首页
开源
资讯
活动
开源许可证
软件工程云服务
软件代码质量检测云服务
持续集成与部署云服务
社区个性化内容推荐服务
贡献审阅人推荐服务
群体化学习服务
重睛鸟代码扫描工具
登录
注册
代码拉取完成,页面将自动刷新
Watch
52
Star
505
Fork
302
iteaj
/
iboot
Fork 仓库
加载中
取消
确认
代码
Issues
10
Pull Requests
1
Wiki
5
统计
更新失败,请稍后重试!
Issues
/
详情
移除标识
内容风险标识
本任务被
标识为内容中包含有代码安全 Bug 、隐私泄露等敏感信息,仓库外成员不可访问
创建mqtt订阅报错
待办的
#I7VFMS
赵振涵
创建于
2023-08-23 17:55
rabbitmq开启mqtt插件用作mqtt服务器 在IotAutoConfiguration配置类中增加获取MqttClient方法 ``` @Bean public MqttClient defaultLotOrderMqttClient(DefaultMqttComponent defaultMqttComponent, MqttSubscribeListener mqttSubscribeListener){ DefaultMqttConnectProperties defaultMqttConnectProperties = new DefaultMqttConnectProperties("127.0.0.1", 1883, "defaultLotOrderMqttClient", Arrays.asList(new MqttTopicSubscription("iot.data.topic", MqttQoS.AT_MOST_ONCE)), mqttSubscribeListener); defaultMqttConnectProperties.setUsername("admin"); defaultMqttConnectProperties.setPassword("123456"); return defaultMqttComponent.createNewClientAndConnect(defaultMqttConnectProperties); } ``` MqttDebugSubscribeListener ``` @Component public class MqttDebugSubscribeListener implements MqttSubscribeListener { private MqttTopicSubscription subscription = new MqttTopicSubscription("iot.data.topic", MqttQoS.AT_MOST_ONCE); @Override public void onSubscribe(DefaultMqttSubscribeProtocol protocol) { byte[] message = protocol.requestMessage().getMessage(); String value = new String(message); System.out.println(value); } @Override public MqttTopicSubscription topic(DefaultMqttConnectProperties client) { return subscription; } } ``` 重启项目,SocketClient执行connect方法时开始报错。 具体报错内容如下 ``` 17:47:38.822 [ERROR] [6094] [IWT-3-1] c.i.i.c.h.ClientServiceHandler : 客户端处理(MQTT<默认>) 处理异常 - 错误信息: null - 处理方式:已发送异常事件[ExceptionEvent], 创建监听器[ExceptionEventListener]来监听异常事件 java.lang.NullPointerException: null at com.iteaj.iot.client.component.SocketClientComponent.getFilter(SocketClientComponent.java:249) at com.iteaj.iot.client.handle.ClientServiceHandler.channelActive(ClientServiceHandler.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:230) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:216) at io.netty.channel.AbstractChannelHandlerContext.fireChannelActive(AbstractChannelHandlerContext.java:209) at com.iteaj.iot.client.mqtt.MqttClient.channelActive(MqttClient.java:255) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:230) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:216) at io.netty.channel.AbstractChannelHandlerContext.fireChannelActive(AbstractChannelHandlerContext.java:209) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelActive(DefaultChannelPipeline.java:1398) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:230) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:216) at io.netty.channel.DefaultChannelPipeline.fireChannelActive(DefaultChannelPipeline.java:895) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:305) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:335) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) ```
rabbitmq开启mqtt插件用作mqtt服务器 在IotAutoConfiguration配置类中增加获取MqttClient方法 ``` @Bean public MqttClient defaultLotOrderMqttClient(DefaultMqttComponent defaultMqttComponent, MqttSubscribeListener mqttSubscribeListener){ DefaultMqttConnectProperties defaultMqttConnectProperties = new DefaultMqttConnectProperties("127.0.0.1", 1883, "defaultLotOrderMqttClient", Arrays.asList(new MqttTopicSubscription("iot.data.topic", MqttQoS.AT_MOST_ONCE)), mqttSubscribeListener); defaultMqttConnectProperties.setUsername("admin"); defaultMqttConnectProperties.setPassword("123456"); return defaultMqttComponent.createNewClientAndConnect(defaultMqttConnectProperties); } ``` MqttDebugSubscribeListener ``` @Component public class MqttDebugSubscribeListener implements MqttSubscribeListener { private MqttTopicSubscription subscription = new MqttTopicSubscription("iot.data.topic", MqttQoS.AT_MOST_ONCE); @Override public void onSubscribe(DefaultMqttSubscribeProtocol protocol) { byte[] message = protocol.requestMessage().getMessage(); String value = new String(message); System.out.println(value); } @Override public MqttTopicSubscription topic(DefaultMqttConnectProperties client) { return subscription; } } ``` 重启项目,SocketClient执行connect方法时开始报错。 具体报错内容如下 ``` 17:47:38.822 [ERROR] [6094] [IWT-3-1] c.i.i.c.h.ClientServiceHandler : 客户端处理(MQTT<默认>) 处理异常 - 错误信息: null - 处理方式:已发送异常事件[ExceptionEvent], 创建监听器[ExceptionEventListener]来监听异常事件 java.lang.NullPointerException: null at com.iteaj.iot.client.component.SocketClientComponent.getFilter(SocketClientComponent.java:249) at com.iteaj.iot.client.handle.ClientServiceHandler.channelActive(ClientServiceHandler.java:111) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:230) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:216) at io.netty.channel.AbstractChannelHandlerContext.fireChannelActive(AbstractChannelHandlerContext.java:209) at com.iteaj.iot.client.mqtt.MqttClient.channelActive(MqttClient.java:255) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:230) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:216) at io.netty.channel.AbstractChannelHandlerContext.fireChannelActive(AbstractChannelHandlerContext.java:209) at io.netty.channel.DefaultChannelPipeline$HeadContext.channelActive(DefaultChannelPipeline.java:1398) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:230) at io.netty.channel.AbstractChannelHandlerContext.invokeChannelActive(AbstractChannelHandlerContext.java:216) at io.netty.channel.DefaultChannelPipeline.fireChannelActive(DefaultChannelPipeline.java:895) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:305) at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:335) at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707) at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655) at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581) at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493) at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989) at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) at java.lang.Thread.run(Thread.java:748) ```
评论 (
0
)
赵振涵
创建了
任务
登录
后才可以发表评论
状态
待办的
待办的
进行中
已完成
已关闭
负责人
未设置
标签
未设置
标签管理
里程碑
未关联里程碑
未关联里程碑
Pull Requests
未关联
未关联
关联的 Pull Requests 被合并后可能会关闭此 issue
分支
未关联
分支 (5)
标签 (2)
develop
master
v2.0.0
v1.2.0
1.1.3
v1.1.3
v1.1.0
开始日期   -   截止日期
-
置顶选项
不置顶
置顶等级:高
置顶等级:中
置顶等级:低
优先级
不指定
严重
主要
次要
不重要
参与者(1)