Search in sources :

Example 16 with Sender

use of org.apache.qpid.proton.engine.Sender in project activemq-artemis by apache.

the class AmqpSecurityTest method testConsumerNotAuthorizedToCreateQueues.

@Test(timeout = 30000)
public void testConsumerNotAuthorizedToCreateQueues() throws Exception {
    AmqpClient client = createAmqpClient(noprivUser, noprivPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Sender sender) {
            ErrorCondition condition = sender.getRemoteCondition();
            if (condition != null && condition.getCondition() != null) {
                if (!condition.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                    markAsInvalid("Should have been tagged with unauthorized access error");
                }
            } else {
                markAsInvalid("Sender should have been opened with an error");
            }
        }
    });
    AmqpConnection connection = client.connect();
    try {
        AmqpSession session = connection.createSession();
        try {
            session.createReceiver(getQueueName(getPrecreatedQueueSize() + 1));
            fail("Should not be able to consume here.");
        } catch (Exception ex) {
            IntegrationTestLogger.LOGGER.info("Caught expected exception");
        }
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 17 with Sender

use of org.apache.qpid.proton.engine.Sender in project activemq-artemis by apache.

the class AmqpSenderTest method testUnsettledSender.

@Test(timeout = 60000)
public void testUnsettledSender() throws Exception {
    final int MSG_COUNT = 1000;
    final CountDownLatch settled = new CountDownLatch(MSG_COUNT);
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    connection.setStateInspector(new AmqpValidator() {

        @Override
        public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
            if (delivery.remotelySettled()) {
                IntegrationTestLogger.LOGGER.trace("Remote settled message for sender: " + sender.getName());
                settled.countDown();
            }
        }
    });
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName(), false);
    for (int i = 1; i <= MSG_COUNT; ++i) {
        AmqpMessage message = new AmqpMessage();
        message.setText("Test-Message: " + i);
        sender.send(message);
        if (i % 1000 == 0) {
            IntegrationTestLogger.LOGGER.info("Sent message: " + i);
        }
    }
    Queue queueView = getProxyToQueue(getQueueName());
    Wait.assertTrue("All messages should arrive", () -> queueView.getMessageCount() == MSG_COUNT);
    sender.close();
    assertTrue("Remote should have settled all deliveries", settled.await(5, TimeUnit.MINUTES));
    connection.close();
}
Also used : AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Delivery(org.apache.qpid.proton.engine.Delivery) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Queue(org.apache.activemq.artemis.core.server.Queue) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 18 with Sender

use of org.apache.qpid.proton.engine.Sender in project activemq-artemis by apache.

the class AMQPConnectionContext method remoteLinkOpened.

protected void remoteLinkOpened(Link link) throws Exception {
    AMQPSessionContext protonSession = getSessionExtension(link.getSession());
    link.setSource(link.getRemoteSource());
    link.setTarget(link.getRemoteTarget());
    if (link instanceof Receiver) {
        Receiver receiver = (Receiver) link;
        if (link.getRemoteTarget() instanceof Coordinator) {
            Coordinator coordinator = (Coordinator) link.getRemoteTarget();
            protonSession.addTransactionHandler(coordinator, receiver);
        } else {
            protonSession.addReceiver(receiver);
        }
    } else {
        Sender sender = (Sender) link;
        protonSession.addSender(sender);
    }
}
Also used : Sender(org.apache.qpid.proton.engine.Sender) Receiver(org.apache.qpid.proton.engine.Receiver) Coordinator(org.apache.qpid.proton.amqp.transaction.Coordinator)

Example 19 with Sender

use of org.apache.qpid.proton.engine.Sender in project azure-service-bus-java by Azure.

the class SendLinkHandler method onLinkRemoteOpen.

@Override
public void onLinkRemoteOpen(Event event) {
    Link link = event.getLink();
    if (link != null && link instanceof Sender) {
        Sender sender = (Sender) link;
        if (link.getRemoteTarget() != null) {
            TRACE_LOGGER.debug("onLinkRemoteOpen: linkName:{}, remoteTarge:{}", sender.getName(), link.getRemoteTarget());
            synchronized (this.firstFlow) {
                this.isFirstFlow = false;
                this.msgSender.onOpenComplete(null);
            }
        } else {
            TRACE_LOGGER.debug("onLinkRemoteOpen: linkName:{}, remoteTarget:{}, remoteSource:{}, action:{}", sender.getName(), null, null, "waitingForError");
        }
    }
}
Also used : Sender(org.apache.qpid.proton.engine.Sender) Link(org.apache.qpid.proton.engine.Link)

Example 20 with Sender

use of org.apache.qpid.proton.engine.Sender in project azure-service-bus-java by Azure.

the class SendLinkHandler method onDelivery.

@Override
public void onDelivery(Event event) {
    Delivery delivery = event.getDelivery();
    while (delivery != null) {
        Sender sender = (Sender) delivery.getLink();
        TRACE_LOGGER.debug("onDelivery: linkName:{}, unsettled:{}, credit:{}, deliveryState:{}, delivery.isBuffered:{}, delivery.tag:{}", sender.getName(), sender.getUnsettled(), sender.getRemoteCredit(), delivery.getRemoteState(), delivery.isBuffered(), delivery.getTag());
        msgSender.onSendComplete(delivery);
        delivery.settle();
        delivery = sender.current();
    }
}
Also used : Sender(org.apache.qpid.proton.engine.Sender) Delivery(org.apache.qpid.proton.engine.Delivery)

Aggregations

Sender (org.apache.qpid.proton.engine.Sender)22 Test (org.junit.Test)10 AmqpClient (org.apache.activemq.transport.amqp.client.AmqpClient)7 AmqpConnection (org.apache.activemq.transport.amqp.client.AmqpConnection)7 AmqpSender (org.apache.activemq.transport.amqp.client.AmqpSender)7 AmqpSession (org.apache.activemq.transport.amqp.client.AmqpSession)7 AmqpValidator (org.apache.activemq.transport.amqp.client.AmqpValidator)7 Delivery (org.apache.qpid.proton.engine.Delivery)7 Source (org.apache.qpid.proton.amqp.messaging.Source)5 Connection (org.apache.qpid.proton.engine.Connection)5 Session (org.apache.qpid.proton.engine.Session)5 AmqpMessage (org.apache.activemq.transport.amqp.client.AmqpMessage)4 Symbol (org.apache.qpid.proton.amqp.Symbol)4 Target (org.apache.qpid.proton.amqp.messaging.Target)4 IAmqpSender (com.microsoft.azure.servicebus.amqp.IAmqpSender)3 ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)3 Receiver (org.apache.qpid.proton.engine.Receiver)3 SendLinkHandler (com.microsoft.azure.servicebus.amqp.SendLinkHandler)2 SessionHandler (com.microsoft.azure.servicebus.amqp.SessionHandler)2 HashMap (java.util.HashMap)2