Search in sources :

Example 66 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class AmqpSendReceiveTest method testSendingAndReceivingToQueueWithDifferentAddressAndQueueName.

@Test(timeout = 60000)
public void testSendingAndReceivingToQueueWithDifferentAddressAndQueueName() throws Exception {
    String queueName = "TestQueueName";
    String address = "TestAddress";
    server.addAddressInfo(new AddressInfo(SimpleString.toSimpleString(address), RoutingType.ANYCAST));
    server.createQueue(new SimpleString(address), RoutingType.ANYCAST, new SimpleString(queueName), null, true, false);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(address);
        AmqpReceiver receiver = session.createReceiver(address);
        receiver.flow(1);
        AmqpMessage message = new AmqpMessage();
        message.setText("TestPayload");
        sender.send(message);
        AmqpMessage receivedMessage = receiver.receive(5000, TimeUnit.MILLISECONDS);
        assertNotNull(receivedMessage);
    } 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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 67 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class BrokerDefinedAnycastConsumerTest method testConsumeWhenOnlyMulticast.

@Test(timeout = 60000)
public void testConsumeWhenOnlyMulticast() throws Exception {
    server.addAddressInfo(new AddressInfo(address, RoutingType.MULTICAST));
    sendMessages(address.toString(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    Source jmsSource = createJmsSource(false);
    jmsSource.setAddress(address.toString());
    try {
        session.createReceiver(jmsSource);
        fail("should throw exception");
    } catch (Exception e) {
    // ignore
    }
    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) Source(org.apache.qpid.proton.amqp.messaging.Source) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 68 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class BrokerDefinedAnycastConsumerTest method testConsumeWhenNoAddressHasBothRoutingTypesButDefaultQueueIsMultiCast.

@Test(timeout = 60000)
public void testConsumeWhenNoAddressHasBothRoutingTypesButDefaultQueueIsMultiCast() throws Exception {
    AddressInfo addressInfo = new AddressInfo(address);
    addressInfo.getRoutingTypes().add(RoutingType.ANYCAST);
    addressInfo.getRoutingTypes().add(RoutingType.MULTICAST);
    server.addAddressInfo(addressInfo);
    server.createQueue(address, RoutingType.MULTICAST, address, null, true, false);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    try {
        session.createReceiver(address.toString());
        fail("expected exception");
    } catch (Exception e) {
    // ignore
    }
    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) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Test(org.junit.Test)

Example 69 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class AmqpMessageRoutingTest method testRoutingExclusivity.

/**
 * If we have an address configured with both ANYCAST and MULTICAST routing types enabled, we must ensure that any
 * messages sent specifically to MULTICAST (e.g. JMS TopicProducer) are only delivered to MULTICAST queues (e.g.
 * i.e. subscription queues) and **NOT** to ANYCAST queues (e.g. JMS Queue).
 *
 * @throws Exception
 */
@Test(timeout = 60000)
public void testRoutingExclusivity() throws Exception {
    // Create Address with both ANYCAST and MULTICAST enabled
    String testAddress = "testRoutingExclusivity-mixed-mode";
    SimpleString ssTestAddress = new SimpleString(testAddress);
    AddressInfo addressInfo = new AddressInfo(ssTestAddress);
    addressInfo.addRoutingType(RoutingType.MULTICAST);
    addressInfo.addRoutingType(RoutingType.ANYCAST);
    server.addAddressInfo(addressInfo);
    server.createQueue(ssTestAddress, RoutingType.ANYCAST, ssTestAddress, null, true, false);
    Connection connection = createConnection(UUIDGenerator.getInstance().generateStringUUID());
    try {
        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Topic topic = session.createTopic(testAddress);
        javax.jms.Queue queue = session.createQueue(testAddress);
        MessageProducer producer = session.createProducer(topic);
        MessageConsumer queueConsumer = session.createConsumer(queue);
        MessageConsumer topicConsumer = session.createConsumer(topic);
        producer.send(session.createTextMessage("testMessage"));
        assertNotNull(topicConsumer.receive(1000));
        assertNull(queueConsumer.receive(1000));
    } finally {
        connection.close();
    }
}
Also used : MessageConsumer(javax.jms.MessageConsumer) Connection(javax.jms.Connection) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) MessageProducer(javax.jms.MessageProducer) Topic(javax.jms.Topic) AddressInfo(org.apache.activemq.artemis.core.server.impl.AddressInfo) Session(javax.jms.Session) Test(org.junit.Test)

Example 70 with AddressInfo

use of org.apache.activemq.artemis.core.server.impl.AddressInfo in project activemq-artemis by apache.

the class BrokerDefinedAnycastConsumerTest method testConsumeFromSingleQueueOnAddressSameNameMultipleQueues.

@Test(timeout = 60000)
public void testConsumeFromSingleQueueOnAddressSameNameMultipleQueues() throws Exception {
    server.addAddressInfo(new AddressInfo(address, RoutingType.ANYCAST));
    server.createQueue(address, RoutingType.ANYCAST, queue1, null, true, false);
    server.createQueue(address, RoutingType.ANYCAST, address, null, true, false);
    sendMessages(address.toString(), 2);
    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());
    assertEquals(0, ((QueueImpl) server.getPostOffice().getBinding(queue1).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

AddressInfo (org.apache.activemq.artemis.core.server.impl.AddressInfo)116 Test (org.junit.Test)89 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)73 ClientSession (org.apache.activemq.artemis.api.core.client.ClientSession)32 ClientSessionFactory (org.apache.activemq.artemis.api.core.client.ClientSessionFactory)24 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)23 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)23 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)22 ServerLocator (org.apache.activemq.artemis.api.core.client.ServerLocator)21 ClientConsumer (org.apache.activemq.artemis.api.core.client.ClientConsumer)19 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)18 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)17 JsonObject (javax.json.JsonObject)16 ClientProducer (org.apache.activemq.artemis.api.core.client.ClientProducer)16 ActiveMQServerControl (org.apache.activemq.artemis.api.core.management.ActiveMQServerControl)16 JsonArray (javax.json.JsonArray)15 Queue (org.apache.activemq.artemis.core.server.Queue)15 ClientMessage (org.apache.activemq.artemis.api.core.client.ClientMessage)13 Configuration (org.apache.activemq.artemis.core.config.Configuration)12 Session (javax.jms.Session)11