use of io.netty.handler.codec.mqtt.MqttPublishMessage 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.MqttPublishMessage in project activemq-artemis by apache.
the class SimpleMQTTInterceptor method intercept.
@Override
public boolean intercept(final MqttMessage mqttMessage, RemotingConnection connection) {
System.out.println("MQTT control packet was intercepted " + mqttMessage.fixedHeader().messageType());
// If you need to handle an specific packet type:
if (mqttMessage instanceof MqttPublishMessage) {
MqttPublishMessage message = (MqttPublishMessage) mqttMessage;
String originalMessage = message.payload().toString(Charset.forName("UTF-8"));
System.out.println("Original message: " + originalMessage);
// The new message content must not be bigger that the original content.
String modifiedMessage = "Modified message ";
message.payload().setBytes(0, modifiedMessage.getBytes());
} else {
if (mqttMessage instanceof MqttConnectMessage) {
MqttConnectMessage connectMessage = (MqttConnectMessage) mqttMessage;
System.out.println("MQTT CONNECT control packet was intercepted " + connectMessage);
}
}
// the target
return true;
}
Aggregations