Search in sources :

Example 11 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.

the class Requestor method sendRequests.

public void sendRequests() {
    try {
        AddressIF tempDest = consumer.getRemoteAddress();
        for (int i = 0; i < nMsgs; i++) {
            TxnIdIF txnIdIF = txc.createTxnId();
            AMQPMessage request = messageFactory.create(i);
            request.setTxnIdIF(txnIdIF);
            Properties prop = new Properties();
            prop.setReplyTo(tempDest);
            request.setProperties(prop);
            producer.send(request, persistent, 5, -1);
            txc.commit(txnIdIF);
            txnIdIF = txc.createTxnId();
            AMQPMessage reply = consumer.receive();
            if (reply == null)
                throw new Exception("Reply is null");
            if (!reply.isSettled())
                reply.accept();
            txc.commit(txnIdIF);
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 12 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.

the class Receiver method receive.

public void receive() {
    try {
        int txSize = 0;
        boolean rollback = false;
        TxnIdIF txnIdIF = txc.createTxnId();
        int i = 0;
        while (i < nMsgs) {
            AMQPMessage msg = consumer.receive();
            if (msg != null) {
                messageFactory.verify(msg);
                messageList.add(msg);
                msg.setTxnIdIF(txnIdIF);
                if (!msg.isSettled())
                    msg.accept();
                txSize++;
                if (txSize == txRcvSize) {
                    if (rollback) {
                        txc.rollback(txnIdIF);
                        TxnIdIF tx2 = txc.createTxnId();
                        for (int j = 0; j < messageList.size(); j++) {
                            AMQPMessage m2 = (AMQPMessage) messageList.get(j);
                            m2.setTxnIdIF(tx2);
                            if (!m2.isSettled())
                                // forces redelivery
                                m2.reject();
                        }
                        txc.commit(tx2);
                        messageList.clear();
                    } else {
                        txc.commit(txnIdIF);
                        i += txSize;
                    }
                    rollback = !rollback;
                    txnIdIF = txc.createTxnId();
                    txSize = 0;
                }
            } else
                throw new Exception("Msg == null at i=" + i);
        }
        if (txSize > 0) {
            if (rollback)
                txc.rollback(txnIdIF);
            else
                txc.commit(txnIdIF);
            rollback = !rollback;
            txSize = 0;
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 13 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.

the class Sender method send.

public void send() {
    try {
        int txSize = 0;
        TxnIdIF txnIdIF = txc.createTxnId();
        boolean rollback = false;
        int i = 0;
        while (i < nMsgs) {
            AMQPMessage msg = messageFactory.create(i);
            msg.setTxnIdIF(txnIdIF);
            producer.send(msg, persistent, 5, -1);
            txSize++;
            if (txSize == txSendSize) {
                if (rollback)
                    txc.rollback(txnIdIF);
                else {
                    txc.commit(txnIdIF);
                    i += txSize;
                }
                rollback = !rollback;
                txnIdIF = txc.createTxnId();
                txSize = 0;
            }
        }
        if (txSize > 0) {
            if (rollback)
                txc.rollback(txnIdIF);
            else
                txc.commit(txnIdIF);
            rollback = !rollback;
            txSize = 0;
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 14 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.

the class Replier method serviceRequests.

public void serviceRequests() {
    try {
        for (int i = 0; i < nMsgs; i++) {
            TxnIdIF txnIdIF = txc.createTxnId();
            consumer.acquire(1, txnIdIF);
            AMQPMessage request = consumer.receive();
            if (request != null) {
                messageFactory.verify(request);
                if (!request.isSettled())
                    request.accept();
                Properties prop = request.getProperties();
                if (prop == null)
                    throw new Exception("Properties not set in request: " + request);
                AddressIF replyTo = prop.getReplyTo();
                if (replyTo == null)
                    throw new Exception("replyTo not set in request: " + request);
                Producer p = getSession().createProducer(replyTo.getValueString(), qos);
                AMQPMessage reply = messageFactory.createReplyMessage(request);
                reply.setTxnIdIF(txnIdIF);
                Properties prop2 = new Properties();
                prop2.setTo(replyTo);
                prop2.setCorrelationId(prop.getMessageId());
                reply.setProperties(prop2);
                p.send(reply);
                p.close();
            } else
                throw new Exception("Msg == null at i=" + i);
            txc.commit(txnIdIF);
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) Producer(com.swiftmq.amqp.v100.client.Producer) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 15 with TxnIdIF

use of com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF in project swiftmq-ce by iitsoftware.

the class Requestor method sendRequests.

public void sendRequests() {
    try {
        AddressIF tempDest = consumer.getRemoteAddress();
        for (int i = 0; i < nMsgs; i++) {
            TxnIdIF txnIdIF = txc.createTxnId();
            AMQPMessage request = messageFactory.create(i);
            request.setTxnIdIF(txnIdIF);
            Properties prop = new Properties();
            prop.setReplyTo(tempDest);
            request.setProperties(prop);
            producer.send(request, persistent, 5, -1);
            txc.commit(txnIdIF);
            txnIdIF = txc.createTxnId();
            consumer.acquire(1, txnIdIF);
            AMQPMessage reply = consumer.receive();
            if (reply == null)
                throw new Exception("Reply is null");
            if (!reply.isSettled())
                reply.accept();
            txc.commit(txnIdIF);
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) TxnIdIF(com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Aggregations

TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)22 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)21 AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)8 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)8 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)8 DeliveryStateIF (com.swiftmq.amqp.v100.generated.messaging.delivery_state.DeliveryStateIF)5 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)5 Producer (com.swiftmq.amqp.v100.client.Producer)4 TransactionalState (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionalState)4 QueueException (com.swiftmq.swiftlet.queue.QueueException)4 IOException (java.io.IOException)4 AMQPContext (com.swiftmq.amqp.AMQPContext)3 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)3 HashMap (java.util.HashMap)3 InvalidStateException (com.swiftmq.amqp.v100.client.InvalidStateException)2 Rejected (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Rejected)2 QueuePushTransaction (com.swiftmq.swiftlet.queue.QueuePushTransaction)2 Accepted (com.swiftmq.amqp.v100.generated.messaging.delivery_state.Accepted)1 TransactionId (com.swiftmq.amqp.v100.generated.transactions.coordination.TransactionId)1 Packager (com.swiftmq.amqp.v100.transport.Packager)1