我想在Spring Integration中使用异步Paho客户端:
@Bean
public DefaultMqttPahoClientFactory clientFactory() {
return new DefaultMqttPahoClientFactory();
}
<int-mqtt:message-driven-channel-adapter id="mqttInbound"
client-id="${mqtt.default.client.id}.src"
url="${mqtt.url}"
topics="sometopic"
client-factory="clientFactory"
channel="output"/>
我必须自己写一个吗?我只能找到同步客户端工厂的示例。
答案 0 :(得分:1)
我非常确定Spring Integration提供的DefaultMqttPahoClientFactory()正在使用&#34; synchronous&#34; Paho中的操作模式,因此您可能需要另一个ClientFactory实现。
答案 1 :(得分:1)
正确;目前,仅支持同步客户端。
随意打开improvement JIRA issue here,当然还有contributions are always welcome - guidelines here。
也就是说,我不清楚在示例中使用入站适配器中的异步客户端的好处;它是消息驱动的,到达的消息是在客户端的线程上异步传递的。显然,出站适配器可以从异步操作中获得一些好处。
outbound adapter非常简单,编写一个使用异步客户端的版本应该不会太难 - 它可能需要将传递令牌发送到某个频道 - 但我们应该从{{{ 1}} object,所以我们不会将IMqttDeliveryToken
泄漏到上层。