Search in sources :

Example 1 with MqttQoS

use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttQoS in project swiftmq-ce by iitsoftware.

the class Subscription method processMessage.

@Override
public void processMessage(MessageEntry messageEntry) {
    try {
        QueuePullTransaction tx = consumer.createTransaction();
        tx.moveToTransaction(messageEntry.getMessageIndex(), readTx);
        String jmsTopicName = ((TopicImpl) messageEntry.getMessage().getJMSDestination()).getTopicName();
        MqttQoS mqos = MqttQoS.valueOf(qos.value());
        if (messageEntry.getMessage().propertyExists(Producer.PROP_QOS)) {
            int pqos = messageEntry.getMessage().getIntProperty(Producer.PROP_QOS);
            int sqos = qos.value();
            if (sqos > pqos)
                mqos = MqttQoS.valueOf(pqos);
        }
        session.getMqttConnection().getConnectionQueue().enqueue(new POSendMessage(jmsTopicName, messageEntry.getMessage(), mqos, tx, this));
        incMsgsReceived(1);
    } catch (Exception e) {
        e.printStackTrace();
    }
}
Also used : POSendMessage(com.swiftmq.impl.mqtt.po.POSendMessage) QueuePullTransaction(com.swiftmq.swiftlet.queue.QueuePullTransaction) TopicImpl(com.swiftmq.jms.TopicImpl) MqttQoS(com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttQoS)

Example 2 with MqttQoS

use of com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttQoS in project swiftmq-ce by iitsoftware.

the class MQTTSession method visit.

@Override
public void visit(POSendMessage po) {
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " ...");
    try {
        BytesMessageImpl jmsMessage = (BytesMessageImpl) po.getJmsMessage();
        jmsMessage.reset();
        MqttQoS qos = po.getQos();
        String topicName = topicNameTranslateReverse(po.getTopicName());
        byte[] b = new byte[(int) jmsMessage.getBodyLength()];
        jmsMessage.readBytes(b);
        ByteBuf byteBuf = new ByteBuf(b);
        byteBuf.reset();
        int packetId = -1;
        if (qos != MqttQoS.AT_MOST_ONCE) {
            if (pid == 65535)
                pid = 1;
            packetId = pid++;
            outboundPackets.put(packetId, po);
        }
        mqttConnection.getOutboundQueue().enqueue(new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, false, qos, false, 0), new MqttPublishVariableHeader(topicName, packetId), byteBuf));
        if (qos == MqttQoS.AT_MOST_ONCE) {
            po.getTransaction().commit();
            po.getSubscription().restart();
        } else
            addReplay(packetId, new MqttPublishMessage(new MqttFixedHeader(MqttMessageType.PUBLISH, true, qos, false, 0), new MqttPublishVariableHeader(topicName, packetId), byteBuf));
        incMsgsReceived(1);
    } catch (QueueTransactionClosedException qtc) {
    } catch (Exception e) {
        mqttConnection.initiateClose("send message: exception=" + e);
    }
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", visit, po=" + po + " done");
}
Also used : QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf) EntityAddException(com.swiftmq.mgmt.EntityAddException) QueueTransactionClosedException(com.swiftmq.swiftlet.queue.QueueTransactionClosedException)

Aggregations

POSendMessage (com.swiftmq.impl.mqtt.po.POSendMessage)1 ByteBuf (com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)1 MqttQoS (com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttQoS)1 BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)1 TopicImpl (com.swiftmq.jms.TopicImpl)1 EntityAddException (com.swiftmq.mgmt.EntityAddException)1 QueuePullTransaction (com.swiftmq.swiftlet.queue.QueuePullTransaction)1 QueueTransactionClosedException (com.swiftmq.swiftlet.queue.QueueTransactionClosedException)1