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);
}
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.
the class MQTTProtocolHandler method send.
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);
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.
the class MQTTProtocolHandler method sendConnack.
void sendConnack(MqttConnectReturnCode returnCode) {
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
MqttConnAckVariableHeader varHeader = new MqttConnAckVariableHeader(returnCode, true);
MqttConnAckMessage message = new MqttConnAckMessage(fixedHeader, varHeader);
sendToClient(message);
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.
the class MQTTProtocolHandler method sendPublishProtocolControlMessage.
void sendPublishProtocolControlMessage(int messageId, MqttMessageType messageType) {
MqttQoS qos = (messageType == MqttMessageType.PUBREL) ? MqttQoS.AT_LEAST_ONCE : MqttQoS.AT_MOST_ONCE;
MqttFixedHeader fixedHeader = new // Spec requires 01 in header for rel
MqttFixedHeader(// Spec requires 01 in header for rel
messageType, // Spec requires 01 in header for rel
false, // Spec requires 01 in header for rel
qos, false, 0);
MqttPubAckMessage rel = new MqttPubAckMessage(fixedHeader, MqttMessageIdVariableHeader.from(messageId));
sendToClient(rel);
}
Aggregations