Search in sources :

Example 1 with MqttPublishMessage

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);
}
Also used : MqttMessage(io.netty.handler.codec.mqtt.MqttMessage) MqttFixedHeader(io.netty.handler.codec.mqtt.MqttFixedHeader) MqttPublishMessage(io.netty.handler.codec.mqtt.MqttPublishMessage) MqttPublishVariableHeader(io.netty.handler.codec.mqtt.MqttPublishVariableHeader)

Example 2 with MqttPublishMessage

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;
}
Also used : MqttConnectMessage(io.netty.handler.codec.mqtt.MqttConnectMessage) MqttPublishMessage(io.netty.handler.codec.mqtt.MqttPublishMessage)

Aggregations

MqttPublishMessage (io.netty.handler.codec.mqtt.MqttPublishMessage)2 MqttConnectMessage (io.netty.handler.codec.mqtt.MqttConnectMessage)1 MqttFixedHeader (io.netty.handler.codec.mqtt.MqttFixedHeader)1 MqttMessage (io.netty.handler.codec.mqtt.MqttMessage)1 MqttPublishVariableHeader (io.netty.handler.codec.mqtt.MqttPublishVariableHeader)1