Search in sources :

Example 51 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.

the class AmqpReceiverWithFiltersTest method testReceivedUnsignedFilter.

@Test(timeout = 60000)
public void testReceivedUnsignedFilter() throws Exception {
    final int NUM_MESSAGES = 100;
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = client.connect();
    try {
        // Normal Session which won't create an TXN itself
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        for (int i = 0; i < NUM_MESSAGES + 1; ++i) {
            AmqpMessage message = new AmqpMessage();
            message.setText("Test-Message");
            message.setApplicationProperty("myNewID", new UnsignedInteger(i));
            sender.send(message);
        }
        // Read all messages from the Queue, do not accept them yet.
        AmqpReceiver receiver = session.createReceiver(getQueueName(), "myNewID < " + (NUM_MESSAGES / 2));
        ArrayList<AmqpMessage> messages = new ArrayList<>(NUM_MESSAGES);
        receiver.flow((NUM_MESSAGES + 2) * 2);
        for (int i = 0; i < NUM_MESSAGES / 2; ++i) {
            AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
            Assert.assertNotNull(message);
            System.out.println("Read message: " + message.getApplicationProperty("myNewID"));
            assertNotNull(message);
            messages.add(message);
        }
        Assert.assertNull(receiver.receiveNoWait());
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) ArrayList(java.util.ArrayList) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) UnsignedInteger(org.apache.qpid.proton.amqp.UnsignedInteger) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 52 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.

the class AmqpScheduledMessageTest method testSendWithDeliveryTimeHoldsMessage.

@Test(timeout = 60000)
public void testSendWithDeliveryTimeHoldsMessage() throws Exception {
    AmqpClient client = createAmqpClient();
    assertNotNull(client);
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        AmqpReceiver receiver = session.createReceiver(getQueueName());
        AmqpMessage message = new AmqpMessage();
        long deliveryTime = System.currentTimeMillis() + TimeUnit.MINUTES.toMillis(5);
        message.setMessageAnnotation("x-opt-delivery-time", deliveryTime);
        message.setText("Test-Message");
        sender.send(message);
        // Now try and get the message
        receiver.flow(1);
        // Shouldn't get this since we delayed the message.
        assertNull(receiver.receive(1, TimeUnit.SECONDS));
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 53 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.

the class BrokerDefinedAnycastConsumerTest method testConsumeFromSingleQueueOnAddressDifferentNameMultipleQueues.

@Test(timeout = 60000)
public void testConsumeFromSingleQueueOnAddressDifferentNameMultipleQueues() throws Exception {
    server.addAddressInfo(new AddressInfo(address, RoutingType.ANYCAST));
    server.createQueue(address, RoutingType.ANYCAST, queue1, null, true, false);
    server.createQueue(address, RoutingType.ANYCAST, queue2, null, true, false);
    sendMessages(address.toString(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(address.toString());
    receiver.flow(1);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(1, ((QueueImpl) server.getPostOffice().getBinding(queue1).getBindable()).getConsumerCount());
    assertEquals(0, ((QueueImpl) server.getPostOffice().getBinding(queue2).getBindable()).getConsumerCount());
    receiver.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 54 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.

the class BrokerDefinedAnycastConsumerTest method testConsumeFromSingleQueueOnAddressSameName.

@Test(timeout = 60000)
public void testConsumeFromSingleQueueOnAddressSameName() throws Exception {
    server.addAddressInfo(new AddressInfo(address, RoutingType.ANYCAST));
    server.createQueue(address, RoutingType.ANYCAST, address, null, true, false);
    sendMessages(address.toString(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(address.toString());
    receiver.flow(1);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(1, ((QueueImpl) server.getPostOffice().getBinding(address).getBindable()).getConsumerCount());
    receiver.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 55 with AmqpReceiver

use of org.apache.activemq.transport.amqp.client.AmqpReceiver in project activemq-artemis by apache.

the class BrokerDefinedMulticastConsumerTest method testConsumeFromSingleQueueOnAddressSameName.

@Test(timeout = 60000)
public void testConsumeFromSingleQueueOnAddressSameName() throws Exception {
    server.addAddressInfo(new AddressInfo(address, RoutingType.MULTICAST));
    server.createQueue(address, RoutingType.MULTICAST, address, null, true, false);
    sendMessages(address.toString(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(address.toString() + "::" + address.toString());
    receiver.flow(1);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(1, ((QueueImpl) server.getPostOffice().getBinding(address).getBindable()).getConsumerCount());
    receiver.close();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)118 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)118 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)118 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)118 Test (org.junit.Test)101 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)94 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)61 Queue (org.apache.activemq.artemis.core.server.Queue)59 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)17 Source (org.apache.qpid.proton.amqp.messaging.Source)17 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)12 Receiver (org.apache.qpid.proton.engine.Receiver)6 ArrayList (java.util.ArrayList)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)3 Wait (org.apache.activemq.artemis.tests.util.Wait)3 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)3 ExecutorService (java.util.concurrent.ExecutorService)2 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 ActiveMQException (org.apache.activemq.artemis.api.core.ActiveMQException)2