问题描述
如您所知,发送消息有两种方式 - 同步和异步。
当我们使用同步模式编码时,代码如下
producer.send(new ProducerRecord<Long,Event>(topicName,event)).get();
public java.util.concurrent.Future<RecordMetadata> send(ProducerRecord<K,V> record)
Asynchronously send a record to a topic. Equivalent to send(record,null). See send(ProducerRecord,Callback) for details.
Specified by:
send in interface Producer<K,V>
所以,基本上 send() 方法返回一个 Futher,然后一旦我在这个未来使用 .get(),它就变成了同步行为。
我的问题是,从定义上看,我没有看到异常定义,如何在同步send()下捕获异常?似乎没有定义任何异常。有人可以帮忙澄清一下吗?
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)