io.netty.handler.codec.mqtt.MqttUnsubscribePayload Java Examples
The following examples show how to use
io.netty.handler.codec.mqtt.MqttUnsubscribePayload.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UnSubscribeProcessor.java From iot-mqtt with Apache License 2.0 | 6 votes |
@Override public void processRequest(ChannelHandlerContext ctx, MqttMessage mqttMessage) { MqttUnsubscribeMessage unsubscribeMessage = (MqttUnsubscribeMessage) mqttMessage; MqttUnsubscribePayload unsubscribePayload = unsubscribeMessage.payload(); List<String> topics = unsubscribePayload.topics(); String clientId = NettyUtil.getClientId(ctx.channel()); ClientSession clientSession = ConnectManager.getInstance().getClient(clientId); if(Objects.isNull(clientSession)){ log.warn("[UnSubscribe] -> The client is not online.clientId={}",clientId); } topics.forEach( topic -> { subscriptionMatcher.unSubscribe(topic,clientId); subscriptionStore.removeSubscription(clientId,topic); //停止发送系统信息 if(SysToipc.SYS.equals(topic)) { sysMessageService.removeClient(clientSession.getClientId()); } }); MqttUnsubAckMessage unsubAckMessage = MessageUtil.getUnSubAckMessage(MessageUtil.getMessageId(mqttMessage)); ctx.writeAndFlush(unsubAckMessage); }
Example #2
Source File: UnSubscribeProcessor.java From jmqtt with Apache License 2.0 | 6 votes |
@Override public void processRequest(ChannelHandlerContext ctx, MqttMessage mqttMessage) { MqttUnsubscribeMessage unsubscribeMessage = (MqttUnsubscribeMessage) mqttMessage; MqttUnsubscribePayload unsubscribePayload = unsubscribeMessage.payload(); List<String> topics = unsubscribePayload.topics(); String clientId = NettyUtil.getClientId(ctx.channel()); ClientSession clientSession = ConnectManager.getInstance().getClient(clientId); if(Objects.isNull(clientSession)){ log.warn("[UnSubscribe] -> The client is not online.clientId={}",clientId); } topics.forEach( topic -> { subscriptionMatcher.unSubscribe(topic,clientId); subscriptionStore.removeSubscription(clientId,topic); }); MqttUnsubAckMessage unsubAckMessage = MessageUtil.getUnSubAckMessage(MessageUtil.getMessageId(mqttMessage)); ctx.writeAndFlush(unsubAckMessage); }
Example #3
Source File: MqttProtocolUtil.java From ext-opensource-netty with Mozilla Public License 2.0 | 5 votes |
public static MqttUnsubscribeMessage unSubscribeMessage(List<String> topic, int messageId) { MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBSCRIBE, false, MqttQoS.AT_MOST_ONCE, false, 0x02); MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId); MqttUnsubscribePayload mqttUnsubscribeMessage = new MqttUnsubscribePayload(topic); return new MqttUnsubscribeMessage(mqttFixedHeader, variableHeader, mqttUnsubscribeMessage); }