public MqttMessage doMessage(MqttMessage msg) { logger.debug("MQTT PUBACK"); MqttPublishVariableHeader publishVariableHeader = (MqttPublishVariableHeader) msg.variableHeader(); int packetId = publishVariableHeader.packetId(); ManagerHandler.removeSendedMessage(packetId); return null; }
private MqttPublishMessage createMqttPublishMsg(DeviceSessionCtx ctx, String topic, JsonElement json) { MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_LEAST_ONCE, false, 0); MqttPublishVariableHeader header = new MqttPublishVariableHeader(topic, ctx.nextMsgId()); ByteBuf payload = ALLOCATOR.buffer(); payload.writeBytes(GSON.toJson(json).getBytes(UTF8)); return new MqttPublishMessage(mqttFixedHeader, header, payload); }
protected void send(int messageId, String topicName, int qosLevel, boolean isRetain, ByteBuf payload, int deliveryCount) { boolean redelivery = qosLevel == 0 ? false : (deliveryCount > 0); MqttFixedHeader header = new MqttFixedHeader(MqttMessageType.PUBLISH, redelivery, MqttQoS.valueOf(qosLevel), isRetain, 0); MqttPublishVariableHeader varHeader = new MqttPublishVariableHeader(topicName, messageId); MqttMessage publish = new MqttPublishMessage(header, varHeader, payload); sendToClient(publish); }
public static MqttPublishMessage publish(IMessage message, boolean isDup) { MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, isDup, message.qos(), message.isRetain(), 7 + message.message().length); MqttPublishVariableHeader variableHeader = new MqttPublishVariableHeader(message.topicName(), message.id()); ByteBuf buf = PooledByteBufAllocator.DEFAULT.buffer(message.message().length); return new MqttPublishMessage(fixedHeader, variableHeader, buf.writeBytes(message.message())); }
private MqttPublishMessage createPublishMessage() { MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_LEAST_ONCE, true, 0); MqttPublishVariableHeader mqttPublishVariableHeader = new MqttPublishVariableHeader(MQTT_TOPIC, 1); ByteBuf payload = ALLOCATOR.buffer(); payload.writeBytes(MQTT_MESSAGE.getBytes(CharsetUtil.UTF_8)); return new MqttPublishMessage(mqttFixedHeader, mqttPublishVariableHeader, payload); }
/** * Add retain message for the topic name * Retain id will be generated * * @param topicLevels Topic Levels * @param msg Retain Message * @return Retain Id */ int addRetainMessage(List<String> topicLevels, Message<MqttPublishVariableHeader, MqttPublishPayload> msg);
/** * Get all retain messages the topic name * * @param topicLevels Topic Levels * @return List of Retain Message */ List<Message<MqttPublishVariableHeader, MqttPublishPayload>> getMatchRetainMessages(List<String> topicLevels);