Search in sources :

Example 86 with AmqpConnection

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

the class AmqpReceiverTest method testClientIdIsSetInSubscriptionList.

@Test(timeout = 60000)
public void testClientIdIsSetInSubscriptionList() throws Exception {
    server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString("mytopic"), RoutingType.ANYCAST));
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    connection.setContainerId("testClient");
    connection.connect();
    try {
        AmqpSession session = connection.createSession();
        Source source = new Source();
        source.setDurable(TerminusDurability.UNSETTLED_STATE);
        source.setCapabilities(Symbol.getSymbol("topic"));
        source.setAddress("mytopic");
        session.createReceiver(source, "testSub");
        SimpleString fo = new SimpleString("testClient.testSub:mytopic");
        assertNotNull(server.locateQueue(fo));
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) Source(org.apache.qpid.proton.amqp.messaging.Source) JMSException(javax.jms.JMSException) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 87 with AmqpConnection

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

the class AmqpReceiverWithFiltersTest method testSupportedFiltersAreListedAsSupported.

@Test(timeout = 60000)
public void testSupportedFiltersAreListedAsSupported() throws Exception {
    AmqpClient client = createAmqpClient();
    client.setValidator(new AmqpValidator() {

        @SuppressWarnings("unchecked")
        @Override
        public void inspectOpenedResource(Receiver receiver) {
            if (receiver.getRemoteSource() == null) {
                markAsInvalid("Link opened with null source.");
            }
            Source source = (Source) receiver.getRemoteSource();
            Map<Symbol, Object> filters = source.getFilter();
            if (findFilter(filters, AmqpSupport.JMS_SELECTOR_FILTER_IDS) == null) {
                markAsInvalid("Broker should return selector filter on attach.");
            }
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    session.createReceiver(getQueueName(), "color = red");
    connection.getStateInspector().assertValid();
    connection.close();
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Receiver(org.apache.qpid.proton.engine.Receiver) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) HashMap(java.util.HashMap) Map(java.util.Map) Source(org.apache.qpid.proton.amqp.messaging.Source) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 88 with AmqpConnection

use of org.apache.activemq.transport.amqp.client.AmqpConnection 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 89 with AmqpConnection

use of org.apache.activemq.transport.amqp.client.AmqpConnection 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 90 with AmqpConnection

use of org.apache.activemq.transport.amqp.client.AmqpConnection 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)

Aggregations

AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)183 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)183 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)168 Test (org.junit.Test)158 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)123 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)114 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)91 Queue (org.apache.activemq.artemis.core.server.Queue)70 Source (org.apache.qpid.proton.amqp.messaging.Source)25 AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)22 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)21 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)14 Receiver (org.apache.qpid.proton.engine.Receiver)12 CountDownLatch (java.util.concurrent.CountDownLatch)8 Map (java.util.Map)7 AddressSettings (org.apache.activemq.artemis.core.settings.impl.AddressSettings)7 RemotingConnection (org.apache.activemq.artemis.spi.core.protocol.RemotingConnection)7 Sender (org.apache.qpid.proton.engine.Sender)7 URI (java.net.URI)6 HashMap (java.util.HashMap)6