Search in sources :

Example 46 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.

the class Replier method serviceRequests.

public void serviceRequests() {
    try {
        for (int i = 0; i < nMsgs; i++) {
            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);
                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);
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : 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 47 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage 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++) {
            AMQPMessage request = messageFactory.create(i);
            Properties prop = new Properties();
            prop.setReplyTo(tempDest);
            request.setProperties(prop);
            producer.send(request, persistent, 5, -1);
            AMQPMessage reply = consumer.receive();
            if (reply == null)
                throw new Exception("Reply is null");
            if (!reply.isSettled())
                reply.accept();
        }
    } catch (Exception e) {
        fail("test failed: " + e);
    }
}
Also used : AddressIF(com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Example 48 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.

the class Receiver method receive.

public void receive() {
    try {
        int txSize = 0;
        TxnIdIF txnIdIF = txc.createTxnId();
        consumer.acquire(txRcvSize, txnIdIF);
        for (int i = 0; i < nMsgs; i++) {
            AMQPMessage msg = consumer.receive();
            if (msg != null) {
                messageFactory.verify(msg);
                if (!msg.isSettled())
                    msg.accept();
                txSize++;
                if (txSize == txRcvSize) {
                    txc.commit(txnIdIF);
                    txnIdIF = txc.createTxnId();
                    consumer.acquire(txRcvSize, txnIdIF);
                    txSize = 0;
                }
            } else
                throw new Exception("Msg == null at i=" + i);
        }
        if (txSize > 0) {
            txc.commit(txnIdIF);
            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 49 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.

the class Sender method send.

public void send() {
    try {
        int txSize = 0;
        TxnIdIF txnIdIF = txc.createTxnId();
        for (int i = 0; i < nMsgs; i++) {
            AMQPMessage msg = messageFactory.create(i);
            msg.setTxnIdIF(txnIdIF);
            producer.send(msg, persistent, 5, -1);
            txSize++;
            if (txSize == txSendSize) {
                txc.commit(txnIdIF);
                txnIdIF = txc.createTxnId();
                txSize = 0;
            }
        }
        if (txSize > 0) {
            txc.commit(txnIdIF);
            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 50 with AMQPMessage

use of com.swiftmq.amqp.v100.messaging.AMQPMessage in project swiftmq-ce by iitsoftware.

the class AMQPSequenceMessageFactory method createReplyMessage.

public AMQPMessage createReplyMessage(AMQPMessage request) throws Exception {
    AMQPMessage reply = new AMQPMessage();
    List list = request.getAmqpSequence();
    ((AmqpSequence) list.get(0)).getValue().add(new AMQPString("REPLY"));
    for (int i = 0; i < list.size(); i++) reply.addAmqpSequence(((AmqpSequence) list.get(i)));
    return reply;
}
Also used : List(java.util.List) ArrayList(java.util.ArrayList) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage)

Aggregations

AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)56 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)24 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)23 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)20 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)19 Map (java.util.Map)13 AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)12 HashMap (java.util.HashMap)10 AMQPContext (com.swiftmq.amqp.AMQPContext)9 Data (com.swiftmq.amqp.v100.generated.messaging.message_format.Data)8 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)8 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)8 IOException (java.io.IOException)8 Producer (com.swiftmq.amqp.v100.client.Producer)6 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)6 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)5 List (java.util.List)4 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)3 Connection (com.swiftmq.amqp.v100.client.Connection)3 Session (com.swiftmq.amqp.v100.client.Session)3