我想异步写入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。基本上我想在完成任务时写入流,而不像轮询。请帮忙。
答案 0 :(得分:0)
@Autowired
private MessageChannel output;
...
output.send(MessageBuilder.withPayload(data).build());
但是,不清楚为什么需要这个;默认情况下,kafka发送已经是异步的。