Search in sources :

Example 86 with AmqpSender

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

the class AmqpMaxFrameSizeTest method testMultipleTransfers.

@Test(timeout = 60000)
public void testMultipleTransfers() 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 {
        connection.connect();
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(testQueueName);
        final int payload = FRAME_SIZE * 16;
        for (int i = 0; i < nMsgs; ++i) {
            AmqpMessage message = createAmqpMessage((byte) 'A', payload);
            sender.send(message);
        }
        int count = getMessageCount(server.getPostOffice(), testQueueName);
        assertEquals(nMsgs, count);
        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();
            Data data = (Data) wrapped.getBody();
            System.out.println("received : message: " + data.getValue().getLength());
            assertEquals(payload, data.getValue().getLength());
            message.accept();
        }
    } 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) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) MessageImpl(org.apache.qpid.proton.message.impl.MessageImpl) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

Example 87 with AmqpSender

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

the class AmqpMessagePriorityTest method testMessageWithVeryHighPriority.

@Test(timeout = 60000)
public void testMessageWithVeryHighPriority() 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) 99);
    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(99, 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 88 with AmqpSender

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

the class AmqpDescribedTypePayloadTest method testSendMessageWithDescribedTypeInBodyReceiveOverOpenWire.

@Test(timeout = 60000)
public void testSendMessageWithDescribedTypeInBodyReceiveOverOpenWire() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setDescribedType(new AmqpNoLocalFilter());
    sender.send(message);
    sender.close();
    connection.close();
    Queue queue = getProxyToQueue(getQueueName());
    Wait.assertEquals(1, queue::getMessageCount);
    ActiveMQConnectionFactory factory = new ActiveMQConnectionFactory(getBrokerOpenWireConnectionURI());
    Connection jmsConnection = factory.createConnection();
    try {
        Session jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
        Destination destination = jmsSession.createQueue(getName());
        MessageConsumer jmsConsumer = jmsSession.createConsumer(destination);
        jmsConnection.start();
        Message received = jmsConsumer.receive(5000);
        assertNotNull(received);
        assertTrue(received instanceof BytesMessage);
    } finally {
        jmsConnection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) Destination(javax.jms.Destination) MessageConsumer(javax.jms.MessageConsumer) ObjectMessage(javax.jms.ObjectMessage) BytesMessage(javax.jms.BytesMessage) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Message(javax.jms.Message) Connection(javax.jms.Connection) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) BytesMessage(javax.jms.BytesMessage) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) ActiveMQConnectionFactory(org.apache.activemq.ActiveMQConnectionFactory) AmqpNoLocalFilter(org.apache.activemq.transport.amqp.client.AmqpNoLocalFilter) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) Session(javax.jms.Session) Test(org.junit.Test)

Example 89 with AmqpSender

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

the class AmqpDeliveryAnnotationsTest method testDeliveryAnnotationsStrippedFromIncoming.

@Test(timeout = 60000)
public void testDeliveryAnnotationsStrippedFromIncoming() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setText("Test-Message");
    message.setDeliveryAnnotation(DELIVERY_ANNOTATION_NAME, getQueueName());
    sender.send(message);
    receiver.flow(1);
    Queue queue = getProxyToQueue(getQueueName());
    assertEquals(1, queue.getMessageCount());
    AmqpMessage received = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(received);
    assertNull(received.getDeliveryAnnotation(DELIVERY_ANNOTATION_NAME));
    sender.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) 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 90 with AmqpSender

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

the class AmqpPluginTest method sendMessages.

@Override
public void sendMessages(String destinationName, int count, RoutingType routingType) throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(destinationName);
        for (int i = 0; i < count; ++i) {
            AmqpMessage message = new AmqpMessage();
            message.setMessageId("MessageID:" + i);
            if (routingType != null) {
                message.setMessageAnnotation(AMQPMessageSupport.ROUTING_TYPE.toString(), routingType.getType());
            }
            sender.send(message);
        }
    } 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) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage)

Aggregations

AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)90 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)90 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)89 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)89 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)82 Test (org.junit.Test)74 AmqpReceiver (org.apache.activemq.transport.amqp.client.AmqpReceiver)61 Queue (org.apache.activemq.artemis.core.server.Queue)47 SimpleString (org.apache.activemq.artemis.api.core.SimpleString)8 URI (java.net.URI)6 CountDownLatch (java.util.concurrent.CountDownLatch)6 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)5 Sender (org.apache.qpid.proton.engine.Sender)5 ArrayList (java.util.ArrayList)4 Connection (javax.jms.Connection)4 Message (javax.jms.Message)4 MessageConsumer (javax.jms.MessageConsumer)4 Session (javax.jms.Session)4 Delivery (org.apache.qpid.proton.engine.Delivery)4 BytesMessage (javax.jms.BytesMessage)3