Search in sources :

Example 1 with AMQPInt

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

the class ReceiveTester 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);
        }
        Consumer consumer = session.createConsumer(address, 500, qos, true, null);
        for (int i = 0; i < nMsgs; i++) {
            AMQPMessage msg = consumer.receive(1000);
            if (msg != null) {
                messageFactory.verify(msg);
                if (!msg.isSettled())
                    msg.accept();
                receiveVerifier.add(msg);
            } else
                throw new Exception("message is null");
        }
        connection.close();
        DeliveryMemory deliveryMemory = consumer.getDeliveryMemory();
        System.out.println("Unsettled: " + deliveryMemory.getNumberUnsettled());
        connection = Util.createConnection();
        session = Util.createSession(connection);
        Consumer consumerRecover = session.createConsumer(address, 500, qos, true, null, deliveryMemory);
        consumerRecover.close();
        session.close();
        connection.close();
        connection = Util.createConnection();
        session = Util.createSession(connection);
        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 2 with AMQPInt

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

Aggregations

ApplicationProperties (com.swiftmq.amqp.v100.generated.messaging.message_format.ApplicationProperties)2 AMQPMessage (com.swiftmq.amqp.v100.messaging.AMQPMessage)2 AMQPInt (com.swiftmq.amqp.v100.types.AMQPInt)2 AMQPString (com.swiftmq.amqp.v100.types.AMQPString)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2