Search in sources :

Example 36 with AmqpSender

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

the class AmqpFlowControlTest method testCreditsAreAllocatedOnceOnLinkCreated.

@Test(timeout = 60000)
public void testCreditsAreAllocatedOnceOnLinkCreated() throws Exception {
    AmqpClient client = createAmqpClient(new URI(singleCreditAcceptorURI));
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        assertEquals("Should only be issued one credit", 1, 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) URI(java.net.URI) Test(org.junit.Test)

Example 37 with AmqpSender

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

the class AmqpFlowControlTest method fillAddress.

/*
    * Fills an address.  Careful when using this method.  Only use when rejected messages are switched on.
    */
private void fillAddress(String address) throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    Exception exception = null;
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(address);
        sendUntilFull(sender);
    } catch (Exception e) {
        exception = e;
    } finally {
        connection.close();
    }
    // Should receive a rejected error
    assertNotNull(exception);
    assertTrue(exception.getMessage().contains("amqp:resource-limit-exceeded"));
}
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) IOException(java.io.IOException) ResourceAllocationException(javax.jms.ResourceAllocationException)

Example 38 with AmqpSender

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

the class AmqpFlowControlTest method testCreditsAreNotAllocatedWhenAddressIsFull.

@Test(timeout = 60000)
public void testCreditsAreNotAllocatedWhenAddressIsFull() throws Exception {
    AmqpClient client = createAmqpClient(new URI(singleCreditAcceptorURI));
    AmqpConnection connection = addConnection(client.connect());
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createSender(getQueueName());
        // Use blocking send to ensure buffered messages do not interfere with credit.
        sender.setSendTimeout(-1);
        sendUntilFull(sender);
        // This should be -1. A single message is buffered in the client, and 0 credit has been allocated.
        assertTrue(sender.getSender().getCredit() == -1);
        long addressSize = server.getPagingManager().getPageStore(new SimpleString(getQueueName())).getAddressSize();
        assertTrue(addressSize >= MAX_SIZE_BYTES && addressSize <= MAX_SIZE_BYTES_REJECT_THRESHOLD);
    } 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) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) URI(java.net.URI) Test(org.junit.Test)

Example 39 with AmqpSender

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

the class AmqpLargeMessageTest method sendMessages.

private void sendMessages(int nMsgs, AmqpConnection connection) throws Exception {
    connection.connect();
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(testQueueName);
    for (int i = 0; i < nMsgs; ++i) {
        AmqpMessage message = createAmqpMessage((byte) 'A', PAYLOAD);
        message.setApplicationProperty("i", (Integer) i);
        message.setDurable(true);
        sender.send(message);
    }
    session.close();
}
Also used : AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage)

Example 40 with AmqpSender

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

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