private static Result<MqttSubAckPayload> decodeSubackPayload( ByteBuf buffer, int bytesRemainingInVariablePart) { final List<Integer> grantedQos = new ArrayList<Integer>(); int numberOfBytesConsumed = 0; while (numberOfBytesConsumed < bytesRemainingInVariablePart) { int qos = buffer.readUnsignedByte(); if (qos != MqttQoS.FAILURE.value()) { qos &= 0x03; } numberOfBytesConsumed++; grantedQos.add(qos); } return new Result<MqttSubAckPayload>(new MqttSubAckPayload(grantedQos), numberOfBytesConsumed); }
private static ByteBuf encodeSubAckMessage( ByteBufAllocator byteBufAllocator, MqttSubAckMessage message) { int variableHeaderBufferSize = 2; int payloadBufferSize = message.payload().grantedQoSLevels().size(); int variablePartSize = variableHeaderBufferSize + payloadBufferSize; int fixedHeaderBufferSize = 1 + getVariableLengthInt(variablePartSize); ByteBuf buf = byteBufAllocator.buffer(fixedHeaderBufferSize + variablePartSize); buf.writeByte(getFixedHeaderByte1(message.fixedHeader())); writeVariableLengthInt(buf, variablePartSize); buf.writeShort(message.variableHeader().messageId()); for (int qos : message.payload().grantedQoSLevels()) { buf.writeByte(qos); } return buf; }
/** * Create the SUBACK response from a list of topicFilters */ private MqttSubAckMessage doAckMessageFromValidateFilters(List<MqttTopicSubscription> topicFilters, int messageId) { List<Integer> grantedQoSLevels = new ArrayList<>(); for (MqttTopicSubscription req : topicFilters) { grantedQoSLevels.add(req.qualityOfService().value()); } MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, AT_MOST_ONCE, false, 0); MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels); return new MqttSubAckMessage(fixedHeader, from(messageId), payload); }
private void verifyFailureQos(MqttSubAckMessage subAckMsg) { List<Integer> grantedQoSes = subAckMsg.payload().grantedQoSLevels(); assertEquals(1, grantedQoSes.size()); assertTrue(grantedQoSes.contains(MqttQoS.FAILURE.value())); }
); }); MqttSubAckMessage subackMessage = MessageUtil.getMqttSubackMessage(subscribeMessage, new MqttSubAckPayload(grantQoss)); client.getCtx().writeAndFlush(subackMessage);
case SUBACK: MqttSubAckMessage suback = (MqttSubAckMessage) msg; final List<Integer> grantedQoSLevels = suback.payload().grantedQoSLevels(); LOG.info("{} SUBACK <{}> packetID <{}>, grantedQoses {}", direction, clientID, messageId(msg), grantedQoSLevels);
private static Result<MqttSubAckPayload> decodeSubAckPayload( ByteBuf buffer, int bytesRemainingInVariablePart) { final List<MqttGrantedQoS> grantedQos = new ArrayList<>(); int numberOfBytesConsumed = 0; while (numberOfBytesConsumed < bytesRemainingInVariablePart) { int qos = buffer.readUnsignedByte() & 0x03; numberOfBytesConsumed++; grantedQos.add(MqttGrantedQoS.valueOf(qos)); } return new Result<>(new MqttSubAckPayload(grantedQos), numberOfBytesConsumed); }
private void subscribe(MqttQoS topic, String newsTopic, MQTTConnection connection) { MqttSubscribeMessage subscribe = MqttMessageBuilders.subscribe() .addSubscription(topic, newsTopic) .messageId(1) .build(); sut.subscribeClientToTopics(subscribe, connection.getClientId(), null, this.connection); MqttSubAckMessage subAck = ((EmbeddedChannel) this.connection.channel).readOutbound(); assertEquals(topic.value(), (int) subAck.payload().grantedQoSLevels().get(0)); }
private static Result<MqttSubAckPayload> decodeSubackPayload( ByteBuf buffer, int bytesRemainingInVariablePart) { final List<Integer> grantedQos = new ArrayList<Integer>(); int numberOfBytesConsumed = 0; while (numberOfBytesConsumed < bytesRemainingInVariablePart) { int qos = buffer.readUnsignedByte(); if (qos != MqttQoS.FAILURE.value()) { qos &= 0x03; } numberOfBytesConsumed++; grantedQos.add(qos); } return new Result<MqttSubAckPayload>(new MqttSubAckPayload(grantedQos), numberOfBytesConsumed); }
private void subscribe(MqttQoS topic, String newsTopic, MQTTConnection connection) { MqttSubscribeMessage subscribe = MqttMessageBuilders.subscribe() .addSubscription(topic, newsTopic) .messageId(1) .build(); sut.subscribeClientToTopics(subscribe, connection.getClientId(), null, this.connection); MqttSubAckMessage subAck = ((EmbeddedChannel) this.connection.channel).readOutbound(); assertEquals(topic.value(), (int) subAck.payload().grantedQoSLevels().get(0)); }
public MqttEndpointImpl subscribeAcknowledge(int subscribeMessageId, List<MqttQoS> grantedQoSLevels) { MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0); MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(subscribeMessageId); MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels.stream().mapToInt(MqttQoS::value).toArray()); io.netty.handler.codec.mqtt.MqttMessage suback = MqttMessageFactory.newMessage(fixedHeader, variableHeader, payload); this.write(suback); return this; }
protected void subscribe(EmbeddedChannel channel, String topic, MqttQoS desiredQos) { MqttSubscribeMessage subscribe = MqttMessageBuilders.subscribe() .addSubscription(desiredQos, topic) .messageId(1) .build(); sut.subscribeClientToTopics(subscribe, FAKE_CLIENT_ID, null, connection); MqttSubAckMessage subAck = channel.readOutbound(); assertEquals(desiredQos.value(), (int) subAck.payload().grantedQoSLevels().get(0)); final String clientId = NettyUtils.clientID(channel); Subscription expectedSubscription = new Subscription(clientId, new Topic(topic), desiredQos); final Set<Subscription> matchedSubscriptions = subscriptions.matchWithoutQosSharpening(new Topic(topic)); assertEquals(1, matchedSubscriptions.size()); final Subscription onlyMatchedSubscription = matchedSubscriptions.iterator().next(); assertEquals(expectedSubscription, onlyMatchedSubscription); }
public MqttEndpointImpl subscribeAcknowledge(int subscribeMessageId, List<MqttQoS> grantedQoSLevels) { MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0); MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(subscribeMessageId); MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels.stream().mapToInt(MqttQoS::value).toArray()); io.netty.handler.codec.mqtt.MqttMessage suback = MqttMessageFactory.newMessage(fixedHeader, variableHeader, payload); this.write(suback); return this; }
protected void subscribe(MQTTConnection connection, String topic, MqttQoS desiredQos) { EmbeddedChannel channel = (EmbeddedChannel) connection.channel; MqttSubscribeMessage subscribe = MqttMessageBuilders.subscribe() .addSubscription(desiredQos, topic) .messageId(1) .build(); sut.subscribeClientToTopics(subscribe, connection.getClientId(), null, connection); MqttSubAckMessage subAck = channel.readOutbound(); assertEquals(desiredQos.value(), (int) subAck.payload().grantedQoSLevels().get(0)); final String clientId = connection.getClientId(); Subscription expectedSubscription = new Subscription(clientId, new Topic(topic), desiredQos); final Set<Subscription> matchedSubscriptions = subscriptions.matchWithoutQosSharpening(new Topic(topic)); assertEquals(1, matchedSubscriptions.size()); final Subscription onlyMatchedSubscription = matchedSubscriptions.iterator().next(); assertEquals(expectedSubscription, onlyMatchedSubscription); }
public MqttEndpointImpl subscribeAcknowledge(int subscribeMessageId, List<MqttQoS> grantedQoSLevels) { this.checkConnected(); MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0); MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(subscribeMessageId); MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels.stream().mapToInt(MqttQoS::value).toArray()); io.netty.handler.codec.mqtt.MqttMessage suback = MqttMessageFactory.newMessage(fixedHeader, variableHeader, payload); this.write(suback); return this; }
protected void subscribe(MQTTConnection connection, String topic, MqttQoS desiredQos) { EmbeddedChannel channel = (EmbeddedChannel) connection.channel; MqttSubscribeMessage subscribe = MqttMessageBuilders.subscribe() .addSubscription(desiredQos, topic) .messageId(1) .build(); sut.subscribeClientToTopics(subscribe, connection.getClientId(), null, connection); MqttSubAckMessage subAck = channel.readOutbound(); assertEquals(desiredQos.value(), (int) subAck.payload().grantedQoSLevels().get(0)); final String clientId = connection.getClientId(); Subscription expectedSubscription = new Subscription(clientId, new Topic(topic), desiredQos); final Set<Subscription> matchedSubscriptions = subscriptions.matchWithoutQosSharpening(new Topic(topic)); assertEquals(1, matchedSubscriptions.size()); final Subscription onlyMatchedSubscription = matchedSubscriptions.iterator().next(); assertEquals(expectedSubscription, onlyMatchedSubscription); }
/** * Create the SUBACK response from a list of topicFilters */ private MqttSubAckMessage doAckMessageFromValidateFilters(List<MqttTopicSubscription> topicFilters, int messageId) { List<Integer> grantedQoSLevels = new ArrayList<>(); for (MqttTopicSubscription req : topicFilters) { grantedQoSLevels.add(req.qualityOfService().value()); } MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, AT_MOST_ONCE, false, 0); MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels); return new MqttSubAckMessage(fixedHeader, from(messageId), payload); }
protected void subscribe(MQTTConnection connection, String topic, MqttQoS desiredQos) { EmbeddedChannel channel = (EmbeddedChannel) connection.channel; MqttSubscribeMessage subscribe = MqttMessageBuilders.subscribe() .addSubscription(desiredQos, topic) .messageId(1) .build(); sut.subscribeClientToTopics(subscribe, connection.getClientId(), null, connection); MqttSubAckMessage subAck = channel.readOutbound(); assertEquals(desiredQos.value(), (int) subAck.payload().grantedQoSLevels().get(0)); final String clientId = connection.getClientId(); Subscription expectedSubscription = new Subscription(clientId, new Topic(topic), desiredQos); final Set<Subscription> matchedSubscriptions = subscriptions.matchWithoutQosSharpening(new Topic(topic)); assertEquals(1, matchedSubscriptions.size()); final Subscription onlyMatchedSubscription = matchedSubscriptions.iterator().next(); assertEquals(expectedSubscription, onlyMatchedSubscription); }
private void subBack(Channel channel, MqttSubscribeMessage mqttSubscribeMessage, int num) { MqttFixedHeader mqttFixedHeader = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0); MqttMessageIdVariableHeader variableHeader = MqttMessageIdVariableHeader.from(mqttSubscribeMessage.variableHeader().messageId()); List<Integer> grantedQoSLevels = new ArrayList<>(num); for (int i = 0; i < num; i++) { grantedQoSLevels.add(mqttSubscribeMessage.payload().topicSubscriptions().get(i).qualityOfService().value()); } MqttSubAckPayload payload = new MqttSubAckPayload(grantedQoSLevels); MqttSubAckMessage mqttSubAckMessage = new MqttSubAckMessage(mqttFixedHeader, variableHeader, payload); channel.writeAndFlush(mqttSubAckMessage); }
protected void subscribe(MQTTConnection connection, String topic, MqttQoS desiredQos) { EmbeddedChannel channel = (EmbeddedChannel) connection.channel; MqttSubscribeMessage subscribe = MqttMessageBuilders.subscribe() .addSubscription(desiredQos, topic) .messageId(1) .build(); sut.subscribeClientToTopics(subscribe, connection.getClientId(), null, connection); MqttSubAckMessage subAck = channel.readOutbound(); assertEquals(desiredQos.value(), (int) subAck.payload().grantedQoSLevels().get(0)); final String clientId = connection.getClientId(); Subscription expectedSubscription = new Subscription(clientId, new Topic(topic), desiredQos); final Set<Subscription> matchedSubscriptions = subscriptions.matchQosSharpening(new Topic(topic)); assertEquals(1, matchedSubscriptions.size()); //assertTrue(matchedSubscriptions.size() >=1); final Subscription onlyMatchedSubscription = matchedSubscriptions.iterator().next(); assertEquals(expectedSubscription, onlyMatchedSubscription); // assertTrue(matchedSubscriptions.contains(expectedSubscription)); }