Search in sources :

Example 21 with BytesMessageImpl

use of com.swiftmq.jms.BytesMessageImpl in project swiftmq-ce by iitsoftware.

the class StreamLibDeployer method run.

public void run() {
    try {
        pullTransaction.commit();
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/run, exception committing tx: " + e + ", exiting");
        return;
    }
    try {
        BytesMessageImpl msg = (BytesMessageImpl) entry.getMessage();
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/run, new message: " + msg);
        processChunk(msg);
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
        ctx.logSwiftlet.logError(ctx.streamsSwiftlet.getName(), toString() + "/run, exception during processing: " + e);
    }
    if (closed)
        return;
    try {
        pullTransaction = receiver.createTransaction(false);
        pullTransaction.registerMessageProcessor(this);
    } catch (Exception e) {
        if (ctx.traceSpace.enabled)
            ctx.traceSpace.trace(ctx.streamsSwiftlet.getName(), toString() + "/run, exception creating new tx: " + e + ", exiting");
        return;
    }
}
Also used : BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) JMSException(javax.jms.JMSException)

Example 22 with BytesMessageImpl

use of com.swiftmq.jms.BytesMessageImpl 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)

Example 23 with BytesMessageImpl

use of com.swiftmq.jms.BytesMessageImpl in project swiftmq-ce by iitsoftware.

the class Producer method send.

public void send(MqttPublishMessage mqttPublishMessage) throws Exception {
    MqttFixedHeader fixedHeader = mqttPublishMessage.fixedHeader();
    ByteBuf payload = mqttPublishMessage.payload();
    BytesMessageImpl bytesMessage = new BytesMessageImpl();
    bytesMessage.setJMSDestination(topic);
    bytesMessage.setJMSTimestamp(System.currentTimeMillis());
    bytesMessage.setJMSMessageID(session.getMqttConnection().nextId());
    bytesMessage.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
    bytesMessage.setStringProperty(MessageImpl.PROP_USER_ID, session.getMqttConnection().getActiveLogin().getUserName());
    bytesMessage.setStringProperty(MessageImpl.PROP_CLIENT_ID, session.getClientId());
    if (fixedHeader.isDup())
        bytesMessage.setBooleanProperty(MessageImpl.PROP_DOUBT_DUPLICATE, true);
    bytesMessage.setIntProperty(PROP_QOS, fixedHeader.qosLevel().value());
    payload.reset();
    byte[] b = new byte[payload.size()];
    payload.readBytes(b);
    bytesMessage.writeBytes(b);
    transaction = sender.createTransaction();
    transaction.putMessage(bytesMessage);
    if (ctx.traceSpace.enabled)
        ctx.traceSpace.trace(ctx.mqttSwiftlet.getName(), toString() + ", sent: " + bytesMessage);
}
Also used : MqttFixedHeader(com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader) BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) ByteBuf(com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)

Example 24 with BytesMessageImpl

use of com.swiftmq.jms.BytesMessageImpl in project swiftmq-ce by iitsoftware.

the class ClusterMetricPublisher method createMessage.

private BytesMessageImpl createMessage(Versionable versionable) throws Exception {
    BytesMessageImpl msg = new BytesMessageImpl();
    versionable.transferToMessage(msg);
    msg.setJMSDeliveryMode(javax.jms.DeliveryMode.NON_PERSISTENT);
    msg.setJMSDestination(new TopicImpl(QueueManagerImpl.CLUSTER_TOPIC));
    msg.setJMSPriority(MessageImpl.MAX_PRIORITY);
    if (interval > 0)
        msg.setJMSExpiration(System.currentTimeMillis() + interval * 2);
    msg.setStringProperty(PROP_SOURCE_ROUTER, SwiftletManager.getInstance().getRouterName());
    msg.setReadOnly(false);
    return msg;
}
Also used : BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) TopicImpl(com.swiftmq.jms.TopicImpl)

Example 25 with BytesMessageImpl

use of com.swiftmq.jms.BytesMessageImpl in project swiftmq-ce by iitsoftware.

the class AMQPNativeOutboundTransformer method transform.

public void transform(Delivery delivery) throws AMQPException, JMSException {
    BytesMessageImpl msg = null;
    try {
        msg = (BytesMessageImpl) delivery.getMessage();
    } catch (ClassCastException e) {
        throw new JMSException("Unable to transform. JMS message is not a BytesMessage");
    }
    if (!msg.propertyExists(messageFormat))
        throw new JMSException("Message format property not set");
    if (!msg.propertyExists(amqpNative) || !msg.getBooleanProperty(amqpNative))
        throw new JMSException("Message is not an AMQP native transformation");
    byte[] body = msg._getBody();
    if (body == null) {
        msg.reset();
        body = new byte[(int) msg.getBodyLength()];
        msg.readBytes(body);
    }
    delivery.setData(body);
    delivery.setMessageFormat(msg.getLongProperty(messageFormat));
}
Also used : BytesMessageImpl(com.swiftmq.jms.BytesMessageImpl) JMSException(javax.jms.JMSException)

Aggregations

BytesMessageImpl (com.swiftmq.jms.BytesMessageImpl)26 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)5 QueueImpl (com.swiftmq.jms.QueueImpl)4 List (java.util.List)4 JMSException (javax.jms.JMSException)4 Endpoint (com.swiftmq.admin.mgmt.Endpoint)2 ContentHeaderProperties (com.swiftmq.amqp.v091.types.ContentHeaderProperties)2 ByteBuf (com.swiftmq.impl.mqtt.v311.netty.buffer.ByteBuf)2 TextMessageImpl (com.swiftmq.jms.TextMessageImpl)2 XidImpl (com.swiftmq.jms.XidImpl)2 StoreEntry (com.swiftmq.swiftlet.store.StoreEntry)2 Dumpable (com.swiftmq.tools.dump.Dumpable)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 BytesMessage (javax.jms.BytesMessage)2 Field (com.swiftmq.amqp.v091.types.Field)1 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)1 Delivery (com.swiftmq.impl.amqp.amqp.v00_09_01.Delivery)1 MqttFixedHeader (com.swiftmq.impl.mqtt.v311.netty.handler.codec.mqtt.MqttFixedHeader)1 QueueIndexEntry (com.swiftmq.impl.store.standard.index.QueueIndexEntry)1