use of io.netty.handler.codec.mqtt.MqttFixedHeader in project activemq-artemis by apache.
the class MQTTProtocolHandler method handleUnsubscribe.
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);
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project rocketmq-externals by apache.
the class PubSubIntegrationTest method getMqttPublishMessage.
private MqttPublishMessage getMqttPublishMessage() {
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_MOST_ONCE, false, 0);
MqttPublishVariableHeader variableHeader = new MqttPublishVariableHeader(topicName, producerPublishId);
return new MqttPublishMessage(fixedHeader, variableHeader, Unpooled.buffer().writeBytes("hello world".getBytes()));
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project rocketmq-externals by apache.
the class ProduceMessageIntegrationTest method getMqttPublishMessage.
private MqttPublishMessage getMqttPublishMessage() {
MqttFixedHeader fixedHeader = new MqttFixedHeader(MqttMessageType.PUBLISH, false, MqttQoS.AT_MOST_ONCE, false, 0);
MqttPublishVariableHeader variableHeader = new MqttPublishVariableHeader(topicName, packetId);
return new MqttPublishMessage(fixedHeader, variableHeader, Unpooled.buffer().writeBytes("hello world".getBytes()));
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project rocketmq-externals by apache.
the class MqttMessageForwarder method handleMessage.
/**
* handle PUBLISH message from client
*
* @param message
* @return whether the message is handled successfully
*/
@Override
public void handleMessage(Message message) {
MqttPublishMessage publishMessage = (MqttPublishMessage) message.getPayload();
String topic = publishMessage.variableHeader().topicName();
if (!subscriptionStore.hasTopic(topic)) {
subscriptionStore.addTopic(topic);
}
for (Subscription subscription : subscriptionStore.get(publishMessage.variableHeader().topicName())) {
ByteBuf buf = Unpooled.buffer();
byte[] bytes = new byte[publishMessage.payload().readableBytes()];
publishMessage.payload().getBytes(0, bytes);
buf.writeBytes(bytes);
MqttPublishMessage msg = new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, publishMessage.fixedHeader().isDup(), MqttQoS.valueOf(MessageUtil.actualQos(publishMessage.fixedHeader().qosLevel().value())), publishMessage.fixedHeader().isRetain(), publishMessage.fixedHeader().remainingLength()), new MqttPublishVariableHeader(publishMessage.variableHeader().topicName(), publishMessage.variableHeader().packetId()), buf);
subscription.getClient().getCtx().writeAndFlush(msg);
}
}
use of io.netty.handler.codec.mqtt.MqttFixedHeader in project netty by netty.
the class MqttHeartBeatBrokerHandler method channelRead.
@Override
public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception {
MqttMessage mqttMessage = (MqttMessage) msg;
System.out.println("Received MQTT message: " + mqttMessage);
switch(mqttMessage.fixedHeader().messageType()) {
case CONNECT:
MqttFixedHeader connackFixedHeader = new MqttFixedHeader(MqttMessageType.CONNACK, false, MqttQoS.AT_MOST_ONCE, false, 0);
MqttConnAckVariableHeader mqttConnAckVariableHeader = new MqttConnAckVariableHeader(MqttConnectReturnCode.CONNECTION_ACCEPTED, false);
MqttConnAckMessage connack = new MqttConnAckMessage(connackFixedHeader, mqttConnAckVariableHeader);
ctx.writeAndFlush(connack);
break;
case PINGREQ:
MqttFixedHeader pingreqFixedHeader = new MqttFixedHeader(MqttMessageType.PINGRESP, false, MqttQoS.AT_MOST_ONCE, false, 0);
MqttMessage pingResp = new MqttMessage(pingreqFixedHeader);
ctx.writeAndFlush(pingResp);
break;
case DISCONNECT:
ctx.close();
break;
default:
System.out.println("Unexpected message type: " + mqttMessage.fixedHeader().messageType());
ReferenceCountUtil.release(msg);
ctx.close();
}
}
Aggregations