io.netty.handler.codec.mqtt.MqttUnsubAckMessage Java Examples
The following examples show how to use
io.netty.handler.codec.mqtt.MqttUnsubAckMessage.
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: ClientProtocolProcess.java From ext-opensource-netty with Mozilla Public License 2.0 | 5 votes |
/** * B - S * @param channel * @param mqttMessage */ public void processUnSubBack(Channel channel, MqttMessage mqttMessage) { int messageId; if (mqttMessage instanceof MqttUnsubAckMessage) { MqttUnsubAckMessage mqttUnsubAckMessage = (MqttUnsubAckMessage) mqttMessage; messageId = mqttUnsubAckMessage.variableHeader().messageId(); } else { MqttMessageIdVariableHeader o = (MqttMessageIdVariableHeader) mqttMessage.variableHeader(); messageId = o.messageId(); NettyLog.error("not UnsubAckMessage:{}", messageId); } this.consumerProcess.processUnSubBack(messageId); }
Example #4
Source File: MqttMessageFactory.java From lannister with Apache License 2.0 | 5 votes |
public static MqttUnsubAckMessage unsuback(int messageId) { MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false, 2); MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(messageId); return new MqttUnsubAckMessage(fixedHeader, variableHeader); }
Example #5
Source File: MqttProtocolUtil.java From ext-opensource-netty with Mozilla Public License 2.0 | 4 votes |
public static MqttUnsubAckMessage unsubAckMessage(int messageId) { return (MqttUnsubAckMessage) MqttMessageFactory.newMessage( new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0), MqttMessageIdVariableHeader.from(messageId), null); }
Example #6
Source File: MessageUtil.java From iot-mqtt with Apache License 2.0 | 4 votes |
public static MqttUnsubAckMessage getUnSubAckMessage(int messageId){ MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.UNSUBACK,false,MqttQoS.AT_MOST_ONCE,false,0); MqttMessageIdVariableHeader idVariableHeader = MqttMessageIdVariableHeader.from(messageId); return new MqttUnsubAckMessage(fixedHeader,idVariableHeader); }
Example #7
Source File: MQTTProtocolHandler.java From activemq-artemis with Apache License 2.0 | 4 votes |
void handleUnsubscribe(MqttUnsubscribeMessage message) throws Exception { session.getSubscriptionManager().removeSubscriptions(message.payload().topics()); MqttFixedHeader header = new MqttFixedHeader(MqttMessageType.UNSUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0); MqttUnsubAckMessage m = new MqttUnsubAckMessage(header, message.variableHeader()); sendToClient(m); }