Search in sources :

Example 56 with AmqpConnection

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

the class AmqpInboundConnectionTest method testBrokerConnectionProperties.

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

        @Override
        public void inspectOpenedResource(Connection connection) {
            Map<Symbol, Object> properties = connection.getRemoteProperties();
            if (!properties.containsKey(PRODUCT)) {
                markAsInvalid("Broker did not send a queue product name value");
                return;
            }
            if (!properties.containsKey(VERSION)) {
                markAsInvalid("Broker did not send a queue version value");
                return;
            }
            if (!PRODUCT_NAME.equals(properties.get(PRODUCT))) {
                markAsInvalid("Broker did not send a the expected product name");
                return;
            }
            String brokerVersion = VersionLoader.getVersion().getFullVersion();
            if (!brokerVersion.equals(properties.get(VERSION))) {
                markAsInvalid("Broker did not send a the expected product version");
                return;
            }
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    try {
        assertNotNull(connection);
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Connection(org.apache.qpid.proton.engine.Connection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Map(java.util.Map) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 57 with AmqpConnection

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

the class AmqpLargeMessageTest method testSendAMQPReceiveAMQP.

@Test(timeout = 60000)
public void testSendAMQPReceiveAMQP() throws Exception {
    server.getAddressSettingsRepository().addMatch("#", new AddressSettings().setDefaultAddressRoutingType(RoutingType.ANYCAST));
    String testQueueName = "ConnectionFrameSize";
    int nMsgs = 200;
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        sendMessages(nMsgs, connection);
        int count = getMessageCount(server.getPostOffice(), testQueueName);
        assertEquals(nMsgs, count);
        AmqpSession session = connection.createSession();
        AmqpReceiver receiver = session.createReceiver(testQueueName);
        receiver.flow(nMsgs);
        for (int i = 0; i < nMsgs; ++i) {
            AmqpMessage message = receiver.receive(5, TimeUnit.SECONDS);
            assertNotNull("failed at " + i, message);
            MessageImpl wrapped = (MessageImpl) message.getWrappedMessage();
            if (wrapped.getBody() instanceof Data) {
                // converters can change this to AmqValue
                Data data = (Data) wrapped.getBody();
                System.out.println("received : message: " + data.getValue().getLength());
                assertEquals(PAYLOAD, data.getValue().getLength());
            }
            message.accept();
        }
        session.close();
    } finally {
        connection.close();
    }
}
Also used : AddressSettings(org.apache.activemq.artemis.core.settings.impl.AddressSettings) 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) Data(org.apache.qpid.proton.amqp.messaging.Data) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 58 with AmqpConnection

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

the class AmqpMessageDivertsTest method runQueueReceiverReadMessageWithDivert.

public void runQueueReceiverReadMessageWithDivert(String routingType) throws Exception {
    final String forwardingAddress = getQueueName() + "Divert";
    final SimpleString simpleForwardingAddress = SimpleString.toSimpleString(forwardingAddress);
    server.createQueue(simpleForwardingAddress, RoutingType.ANYCAST, simpleForwardingAddress, null, true, false);
    server.getActiveMQServerControl().createDivert("name", "routingName", getQueueName(), forwardingAddress, true, null, null, routingType);
    sendMessages(getQueueName(), 1);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(forwardingAddress);
    Queue queueView = getProxyToQueue(forwardingAddress);
    assertEquals(1, queueView.getMessageCount());
    receiver.flow(1);
    assertNotNull(receiver.receive(5, TimeUnit.SECONDS));
    receiver.close();
    assertEquals(1, queueView.getMessageCount());
    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) Queue(org.apache.activemq.artemis.core.server.Queue)

Example 59 with AmqpConnection

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

the class AmqpMessagePriorityTest method testMessagePriorityPreservedAfterServerRestart.

@Test(timeout = 60000)
public void testMessagePriorityPreservedAfterServerRestart() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setDurable(true);
    message.setMessageId("MessageID:1");
    message.setPriority((short) 7);
    sender.send(message);
    sender.close();
    connection.close();
    server.stop();
    server.start();
    client = createAmqpClient();
    connection = addConnection(client.connect());
    session = connection.createSession();
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(1, queueView.getMessageCount());
    receiver.flow(1);
    AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(receive);
    assertEquals((short) 7, receive.getPriority());
    receiver.close();
    assertEquals(1, queueView.getMessageCount());
    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) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 60 with AmqpConnection

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

the class AmqpMessagePriorityTest method testMessageNonDefaultPriority.

@Test(timeout = 60000)
public void testMessageNonDefaultPriority() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("MessageID:1");
    message.setPriority((short) 0);
    sender.send(message);
    sender.close();
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    Queue queueView = getProxyToQueue(getQueueName());
    assertEquals(1, queueView.getMessageCount());
    receiver.flow(1);
    AmqpMessage receive = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(receive);
    assertEquals((short) 0, receive.getPriority());
    receiver.close();
    assertEquals(1, queueView.getMessageCount());
    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) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) 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