Search in sources :

Example 36 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class SendTester method test.

public void test() {
    try {
        Connection connection = Util.createConnection();
        Session session = Util.createSession(connection);
        Producer producer = session.createProducer(address, qos);
        for (int i = 0; i < nMsgs; i++) {
            AMQPMessage msg = messageFactory.create(i);
            Map map = new HashMap();
            map.put(new AMQPString(PROPNAME), new AMQPInt(i));
            msg.setApplicationProperties(new ApplicationProperties(map));
            producer.send(msg, persistent, 5, -1);
        }
        connection.close();
        DeliveryMemory deliveryMemory = producer.getDeliveryMemory();
        System.out.println("Unsettled: " + deliveryMemory.getNumberUnsettled());
        connection = Util.createConnection();
        session = Util.createSession(connection);
        Producer producerRecover = session.createProducer(address, qos, deliveryMemory);
        producerRecover.close();
        session.close();
        connection.close();
        connection = Util.createConnection();
        session = Util.createSession(connection);
        Consumer consumer = session.createConsumer(address, 500, qos, true, null);
        for (; ; ) {
            AMQPMessage msg = consumer.receive(1000);
            if (msg != null) {
                messageFactory.verify(msg);
                if (!msg.isSettled())
                    msg.accept();
                receiveVerifier.add(msg);
            } else
                break;
        }
        consumer.close();
        session.close();
        connection.close();
        receiveVerifier.verify();
    } catch (Exception e) {
        e.printStackTrace();
        fail("test failed: " + e);
    }
}
Also used : HashMap(java.util.HashMap) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPInt(com.swiftmq.amqp.v100.types.AMQPInt) ApplicationProperties(com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) Map(java.util.Map) HashMap(java.util.HashMap)

Example 37 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString 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)

Example 38 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class AMQPSequenceMessageFactory method create.

public AMQPMessage create(int sequenceNo) throws Exception {
    AMQPMessage msg = new AMQPMessage();
    List list = new ArrayList();
    list.add(new AMQPString("key1"));
    list.add(new AMQPLong(Integer.MAX_VALUE + 1));
    list.add(new AMQPString("key3"));
    list.add(new AMQPLong(Integer.MAX_VALUE + 2));
    msg.addAmqpSequence(new AmqpSequence(list));
    return msg;
}
Also used : AMQPLong(com.swiftmq.amqp.v100.types.AMQPLong) ArrayList(java.util.ArrayList) List(java.util.List) ArrayList(java.util.ArrayList) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AmqpSequence(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpSequence)

Example 39 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class AMQPValueMapMessageFactory method createReplyMessage.

public AMQPMessage createReplyMessage(AMQPMessage request) throws Exception {
    AMQPMessage reply = new AMQPMessage();
    Map map = ((AMQPMap) request.getAmqpValue().getValue()).getValue();
    map.put(new AMQPString("REPLY"), new AMQPString("REPLY"));
    reply.setAmqpValue(new AmqpValue(new AMQPMap(map)));
    return reply;
}
Also used : AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AMQPMessage(com.swiftmq.amqp.v100.messaging.AMQPMessage) AMQPMap(com.swiftmq.amqp.v100.types.AMQPMap) Map(java.util.Map) HashMap(java.util.HashMap) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Example 40 with AMQPString

use of com.swiftmq.amqp.v100.types.AMQPString in project swiftmq-ce by iitsoftware.

the class AMQPValueStringMessageFactory method verify.

public void verify(AMQPMessage message) throws Exception {
    AmqpValue value = message.getAmqpValue();
    if (value == null)
        throw new Exception(("verify - no AmqpValue section found!"));
    AMQPString s = (AMQPString) value.getValue();
    if (!s.getValue().startsWith("Message #"))
        throw new Exception("verify - invalid value detected: " + s.getValue());
}
Also used : AMQPString(com.swiftmq.amqp.v100.types.AMQPString) AmqpValue(com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)

Aggregations

AMQPString (com.swiftmq.amqp.v100.types.AMQPString)29 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)24 AmqpValue (com.swiftmq.amqp.v100.generated.messaging.message_format.AmqpValue)17 HashMap (java.util.HashMap)14 Map (java.util.Map)14 IOException (java.io.IOException)13 AMQPContext (com.swiftmq.amqp.AMQPContext)9 AMQPMap (com.swiftmq.amqp.v100.types.AMQPMap)8 JSSESocketFactory (com.swiftmq.net.JSSESocketFactory)8 ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)6 Properties (com.swiftmq.amqp.v100.generated.messaging.message_format.Properties)6 QueueException (com.swiftmq.swiftlet.queue.QueueException)5 AMQPException (com.swiftmq.amqp.v100.client.AMQPException)4 AddressString (com.swiftmq.amqp.v100.generated.messaging.message_format.AddressString)4 TxnIdIF (com.swiftmq.amqp.v100.generated.transactions.coordination.TxnIdIF)4 Milliseconds (com.swiftmq.amqp.v100.generated.transport.definitions.Milliseconds)4 SequenceNo (com.swiftmq.amqp.v100.generated.transport.definitions.SequenceNo)4 AMQPBoolean (com.swiftmq.amqp.v100.types.AMQPBoolean)4 Iterator (java.util.Iterator)4 Connection (com.swiftmq.amqp.v100.client.Connection)3