Search in sources :

Example 21 with Properties

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-client by iitsoftware.

the class BeginFrame method decode.

private void decode() throws Exception {
    List l = body.getValue();
    AMQPType t = null;
    int idx = 0;
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            remoteChannel = (AMQPUnsignedShort) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'remoteChannel' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'nextOutgoingId' in 'Begin' frame is NULL");
    try {
        nextOutgoingId = new TransferNumber(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'nextOutgoingId' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'incomingWindow' in 'Begin' frame is NULL");
    try {
        incomingWindow = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'incomingWindow' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    if (t.getCode() == AMQPTypeDecoder.NULL)
        throw new Exception("Mandatory field 'outgoingWindow' in 'Begin' frame is NULL");
    try {
        outgoingWindow = (AMQPUnsignedInt) t;
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'outgoingWindow' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            handleMax = new Handle(((AMQPUnsignedInt) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'handleMax' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            offeredCapabilities = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'offeredCapabilities' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            desiredCapabilities = AMQPTypeDecoder.isArray(t.getCode()) ? (AMQPArray) t : singleToArray(t);
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'desiredCapabilities' in 'Begin' frame: " + e);
    }
    // Factory  : ./.
    if (idx >= l.size())
        return;
    t = (AMQPType) l.get(idx++);
    try {
        if (t.getCode() != AMQPTypeDecoder.NULL)
            properties = new Fields(((AMQPMap) t).getValue());
    } catch (ClassCastException e) {
        throw new Exception("Invalid type of field 'properties' in 'Begin' frame: " + e);
    }
}
Also used : Fields(com.swiftmq.amqp.v100.generated.transport.definitions.Fields) TransferNumber(com.swiftmq.amqp.v100.generated.transport.definitions.TransferNumber) List(java.util.List) ArrayList(java.util.ArrayList) IOException(java.io.IOException) Handle(com.swiftmq.amqp.v100.generated.transport.definitions.Handle)

Example 22 with Properties

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-client by iitsoftware.

the class AMQPRepo method remove.

AMQPRepo remove(String appname) throws Exception {
    AMQPMessage request = new AMQPMessage();
    Map propMap = new HashMap();
    propMap.put(new AMQPString("app"), new AMQPString(appname));
    propMap.put(new AMQPString("operation"), new AMQPString("remove"));
    request.setApplicationProperties(new ApplicationProperties(propMap));
    Properties properties = new Properties();
    properties.setReplyTo(replyQueue);
    request.setProperties(properties);
    producer.send(request);
    AMQPMessage reply = consumer.receive(TIMEOUT);
    if (reply == null)
        throw new Exception("Timeout occurred while waiting for a reply!");
    AMQPMap body = (AMQPMap) reply.getAmqpValue().getValue();
    boolean success = ((AMQPBoolean) (body.getValue().get(new AMQPString("success")))).getValue();
    if (success)
        System.out.println("Removed repository " + appname);
    else {
        String result = ((AMQPString) (body.getValue().get(new AMQPString("result")))).getValue();
        System.out.println(result);
    }
    return this;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) Properties(com.swiftmq.amqp.v100.generated.messaging.message_format.Properties) AMQPBoolean(com.swiftmq.amqp.v100.types.AMQPBoolean) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) HashMap(java.util.HashMap) Map(java.util.Map)

Example 23 with Properties

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties 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 24 with Properties

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties 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 25 with Properties

use of com.swiftmq.amqp.v100.generated.messaging.message_format.Properties in project swiftmq-ce by iitsoftware.

the class Replier method serviceRequests.

public void serviceRequests() {
    try {
        boolean rollback = false;
        int i = 0;
        while (i < nMsgs) {
            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);
            if (rollback)
                txc.rollback(txnIdIF);
            else {
                txc.commit(txnIdIF);
                i++;
            }
            rollback = !rollback;
        }
    } 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)

Aggregations

AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)22 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)19 AddressIF (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressIF)12 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)8 IOException (java.io.IOException)8 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)6 Map (java.util.Map)6 Producer (com.swiftmq.amqp.v100.client.Producer)5 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)5 HashMap (java.util.HashMap)5 List (java.util.List)5 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)4 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)4 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)4 ArrayList (java.util.ArrayList)4 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)3 Fields (com.swiftmq.amqp.v100.generated.transport.definitions.Fields)3 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)3 JMSException (javax.jms.JMSException)3 StreamException (com.rabbitmq.stream.StreamException)2