异步写入spring cloud kafka stream

时间:2017-10-18 09:58:37

标签: spring-cloud-stream spring-kafka

我想异步写入spring cloud kafka stream。例如

Class SomeClass{

@StreamLister(Processor.INPUT)
public void receiveEvents(String e){

  class ThreadExecutor implements Runnable {
  private String message;

    public ThreadExecutor(message){
        this.message = message;
    }

    public void run(){
        //after processing the string I will publish it
         message = message + "done";
         writeToStream(message);
     }
   }

   Executors.newCachedThreadPool().execute(new ThreadExecutor(e));
}

@SendTo //not sure how to write it back
public Message<String> writeToStream(String message){
   //this is what I want to know
  }

}

所以在上面的例子中。我想知道如何调用writeToStream方法,以便它将写回kafka。基本上我想在完成任务时写入流,而不像轮询。请帮忙。

1 个答案:

答案 0 :(得分:0)

@Autowired
private MessageChannel output;

...

    output.send(MessageBuilder.withPayload(data).build());

但是,不清楚为什么需要这个;默认情况下,kafka发送已经是异步的。