Search in sources :

Example 81 with AmqpSender

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

the class AmqpExpiredMessageTest method testSendMessageThatIsExpiredUsingTTLWhenAbsoluteIsZero.

@Test(timeout = 60000)
public void testSendMessageThatIsExpiredUsingTTLWhenAbsoluteIsZero() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    // Get the Queue View early to avoid racing the delivery.
    final Queue queueView = getProxyToQueue(getQueueName());
    assertNotNull(queueView);
    AmqpMessage message = new AmqpMessage();
    message.setAbsoluteExpiryTime(0);
    // AET should override any TTL set
    message.setTimeToLive(1000);
    message.setText("Test-Message");
    sender.send(message);
    sender.close();
    assertEquals(1, queueView.getMessageCount());
    Thread.sleep(1000);
    // Now try and get the message
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    receiver.flow(1);
    AmqpMessage received = receiver.receiveNoWait();
    assertNull(received);
    Wait.assertEquals(1, queueView::getMessagesExpired);
    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 82 with AmqpSender

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

the class AmqpFlowControlTest method testNewLinkAttachAreNotAllocatedCreditsWhenAddressIsBlocked.

@Test(timeout = 60000)
public void testNewLinkAttachAreNotAllocatedCreditsWhenAddressIsBlocked() throws Exception {
    fillAddress(getQueueName());
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        // Wait for a potential flow frame.
        Thread.sleep(1000);
        assertEquals(0, sender.getSender().getCredit());
    } 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) Test(org.junit.Test)

Example 83 with AmqpSender

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

the class AmqpFlowControlTest method testTxIsRolledBackOnRejectedPreSettledMessage.

@Test(timeout = 60000)
public void testTxIsRolledBackOnRejectedPreSettledMessage() throws Throwable {
    // Create the link attach before filling the address to ensure the link is allocated credit.
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName());
    sender.setPresettle(true);
    fillAddress(getQueueName());
    final AmqpMessage message = new AmqpMessage();
    byte[] payload = new byte[50 * 1024];
    message.setBytes(payload);
    Exception expectedException = null;
    try {
        session.begin();
        sender.send(message);
        session.commit();
    } catch (Exception e) {
        expectedException = e;
    } finally {
        connection.close();
    }
    assertNotNull(expectedException);
    assertTrue(expectedException.getMessage().contains("resource-limit-exceeded"));
    assertTrue(expectedException.getMessage().contains("Address is full: " + getQueueName()));
}
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) IOException(java.io.IOException) ResourceAllocationException(javax.jms.ResourceAllocationException) Test(org.junit.Test)

Example 84 with AmqpSender

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

the class AmqpFlowControlTest method testCreditsAreRefreshedWhenAddressIsUnblocked.

@Test(timeout = 60000)
public void testCreditsAreRefreshedWhenAddressIsUnblocked() throws Exception {
    fillAddress(getQueueName());
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        // Wait for a potential flow frame.
        Thread.sleep(500);
        assertEquals(0, sender.getSender().getCredit());
        // Empty Address except for 1 message used later.
        AmqpReceiver receiver = session.createReceiver(getQueueName());
        receiver.flow(100);
        AmqpMessage m;
        for (int i = 0; i < messagesSent - 1; i++) {
            m = receiver.receive(5000, TimeUnit.MILLISECONDS);
            m.accept();
        }
        // Wait for address to unblock and flow frame to arrive
        Thread.sleep(500);
        assertTrue(sender.getSender().getCredit() >= 0);
    } 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 85 with AmqpSender

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

the class AmqpManagementTest method testManagementQueryOverAMQP.

@Test(timeout = 60000)
public void testManagementQueryOverAMQP() throws Throwable {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    try {
        String destinationAddress = getQueueName(1);
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender("activemq.management");
        AmqpReceiver receiver = session.createReceiver(destinationAddress);
        receiver.flow(10);
        // Create request message for getQueueNames query
        AmqpMessage request = new AmqpMessage();
        request.setApplicationProperty("_AMQ_ResourceName", ResourceNames.BROKER);
        request.setApplicationProperty("_AMQ_OperationName", "getQueueNames");
        request.setReplyToAddress(destinationAddress);
        request.setText("[]");
        sender.send(request);
        AmqpMessage response = receiver.receive(5, TimeUnit.SECONDS);
        Assert.assertNotNull(response);
        assertNotNull(response);
        Object section = response.getWrappedMessage().getBody();
        assertTrue(section instanceof AmqpValue);
        Object value = ((AmqpValue) section).getValue();
        assertTrue(value instanceof String);
        assertTrue(((String) value).length() > 0);
        assertTrue(((String) value).contains(destinationAddress));
        response.accept();
    } 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) AmqpValue(org.apache.qpid.proton.amqp.messaging.AmqpValue) 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