use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.
the class MQTTProtocolHandler method handlePingreq.
void handlePingreq() {
MqttMessage pingResp = new MqttMessage(new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0));
sendToClient(pingResp);
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.
the class MQTTProtocolHandler method handleSubscribe.
void handleSubscribe(MqttSubscribeMessage message) throws Exception {
MQTTSubscriptionManager subscriptionManager = session.getSubscriptionManager();
int[] qos = subscriptionManager.addSubscriptions(message.payload().topicSubscriptions());
MqttFixedHeader header = new MqttFixedHeader(MqttMessageType.SUBACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
MqttSubAckMessage ack = new MqttSubAckMessage(header, message.variableHeader(), new MqttSubAckPayload(qos));
sendToClient(ack);
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.
the class MQTTInterceptorPropertiesTest method checkMessageProperties.
private boolean checkMessageProperties(MqttMessage message, Map<String, Object> expectedProperties) {
System.out.println("Checking properties in interceptor");
try {
assertNotNull(message);
assertNotNull(server.getNodeID());
MqttFixedHeader header = message.fixedHeader();
assertNotNull(header.messageType());
assertEquals(header.qosLevel().value(), AT_MOST_ONCE);
assertEquals(header.isRetain(), expectedProperties.get(RETAINED));
} catch (Throwable t) {
collector.addError(t);
}
return true;
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project netty by netty.
the class MqttHeartBeatClientHandler method channelActive.
@Override
public void channelActive(ChannelHandlerContext ctx) throws Exception {
MqttFixedHeader connectFixedHeader = new MqttFixedHeader(MqttMessageType.CONNECT, false, MqttQoS.AT_MOST_ONCE, false, 0);
MqttConnectVariableHeader connectVariableHeader = new MqttConnectVariableHeader(PROTOCOL_NAME_MQTT_3_1_1, PROTOCOL_VERSION_MQTT_3_1_1, true, true, false, 0, false, false, 20, MqttProperties.NO_PROPERTIES);
MqttConnectPayload connectPayload = new MqttConnectPayload(clientId, MqttProperties.NO_PROPERTIES, null, null, userName, password);
MqttConnectMessage connectMessage = new MqttConnectMessage(connectFixedHeader, connectVariableHeader, connectPayload);
ctx.writeAndFlush(connectMessage);
System.out.println("Sent CONNECT");
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project netty by netty.
the class MqttHeartBeatClientHandler method userEventTriggered.
@Override
public void userEventTriggered(ChannelHandlerContext ctx, Object evt) throws Exception {
if (evt instanceof IdleStateEvent) {
MqttFixedHeader pingreqFixedHeader = new MqttFixedHeader(MqttMessageType.PINGREQ, false, MqttQoS.AT_MOST_ONCE, false, 0);
MqttMessage pingreqMessage = new MqttMessage(pingreqFixedHeader);
ctx.writeAndFlush(pingreqMessage);
System.out.println("Sent PINGREQ");
} else {
super.userEventTriggered(ctx, evt);
}
}
Aggregations