Search in sources :

Example 51 with AmqpSender

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

the class AmqpDescribedTypePayloadTest method testDescribedTypeMessageRoundTrips.

@Test(timeout = 60000)
public void testDescribedTypeMessageRoundTrips() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    // Send with AMQP client.
    AmqpSender sender = session.createSender(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setDescribedType(new AmqpNoLocalFilter());
    sender.send(message);
    sender.close();
    Queue queue = getProxyToQueue(getQueueName());
    Wait.assertEquals(1, queue::getMessageCount);
    // Receive and resend with Qpid JMS client
    JmsConnectionFactory factory = new JmsConnectionFactory(getBrokerQpidJMSConnectionURI());
    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 ObjectMessage);
        MessageProducer jmsProducer = jmsSession.createProducer(destination);
        jmsProducer.send(received);
    } finally {
        jmsConnection.close();
    }
    assertEquals(1, queue.getMessageCount());
    // Now lets receive it with AMQP and see that we get back what we expected.
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    receiver.flow(1);
    AmqpMessage returned = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(returned);
    assertNotNull(returned.getDescribedType());
    receiver.close();
    connection.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) JmsConnectionFactory(org.apache.qpid.jms.JmsConnectionFactory) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) Connection(javax.jms.Connection) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpNoLocalFilter(org.apache.activemq.transport.amqp.client.AmqpNoLocalFilter) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ObjectMessage(javax.jms.ObjectMessage) MessageProducer(javax.jms.MessageProducer) 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 52 with AmqpSender

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

the class AmqpDurableReceiverTest method testCreateDurableReceiver.

@Test(timeout = 60000)
public void testCreateDurableReceiver() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.createConnection());
    connection.setContainerId(getContainerID());
    connection.connect();
    AmqpSession session = connection.createSession();
    AmqpReceiver receiver = session.createDurableReceiver(getTopicName(), getSubscriptionName());
    receiver.flow(1);
    assertEquals(getTopicName(), lookupSubscription());
    AmqpSender sender = session.createSender(getTopicName());
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("message:1");
    sender.send(message);
    message = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(message);
    connection.close();
    assertEquals(getTopicName(), lookupSubscription());
}
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 AmqpSender

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

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

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

the class AmqpSendReceiveInterceptorTest method testCreateQueueReceiver.

@Test(timeout = 60000)
public void testCreateQueueReceiver() throws Exception {
    final CountDownLatch latch = new CountDownLatch(1);
    server.getRemotingService().addIncomingInterceptor(new AmqpInterceptor() {

        @Override
        public boolean intercept(AMQPMessage message, RemotingConnection connection) throws ActiveMQException {
            latch.countDown();
            return true;
        }
    });
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getTestName());
    AmqpMessage message = new AmqpMessage();
    message.setMessageId("msg" + 1);
    message.setText("Test-Message");
    sender.send(message);
    assertTrue(latch.await(5, TimeUnit.SECONDS));
    final CountDownLatch latch2 = new CountDownLatch(1);
    server.getRemotingService().addOutgoingInterceptor(new AmqpInterceptor() {

        @Override
        public boolean intercept(AMQPMessage packet, RemotingConnection connection) throws ActiveMQException {
            latch2.countDown();
            return true;
        }
    });
    AmqpReceiver receiver = session.createReceiver(getTestName());
    receiver.flow(2);
    AmqpMessage amqpMessage = receiver.receive(5, TimeUnit.SECONDS);
    assertNotNull(amqpMessage);
    assertEquals(latch2.getCount(), 0);
    sender.close();
    receiver.close();
    connection.close();
}
Also used : AmqpInterceptor(org.apache.activemq.artemis.protocol.amqp.broker.AmqpInterceptor) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ActiveMQException(org.apache.activemq.artemis.api.core.ActiveMQException) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) RemotingConnection(org.apache.activemq.artemis.spi.core.protocol.RemotingConnection) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AMQPMessage(org.apache.activemq.artemis.protocol.amqp.broker.AMQPMessage) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Test(org.junit.Test)

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