Search in sources :

Example 6 with Sender

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

the class AmqpTransactionCoordinator method doOpen.

@Override
protected void doOpen() {
    Coordinator coordinator = new Coordinator();
    coordinator.setCapabilities(TxnCapability.LOCAL_TXN);
    Source source = new Source();
    String coordinatorName = "qpid-jms:coordinator:" + session.getConnection().getConnectionId();
    Sender sender = session.getEndpoint().sender(coordinatorName);
    sender.setSource(source);
    sender.setTarget(coordinator);
    sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
    sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);
    setEndpoint(sender);
    super.doOpen();
}
Also used : Sender(org.apache.qpid.proton.engine.Sender) Coordinator(org.apache.qpid.proton.amqp.transaction.Coordinator) Source(org.apache.qpid.proton.amqp.messaging.Source)

Example 7 with Sender

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

the class AmqpSender method doOpen.

@Override
protected void doOpen() {
    Symbol[] outcomes = new Symbol[] { Accepted.DESCRIPTOR_SYMBOL, Rejected.DESCRIPTOR_SYMBOL };
    Source source = new Source();
    source.setAddress(senderId);
    source.setOutcomes(outcomes);
    Target target = userSpecifiedTarget;
    if (target == null) {
        target = new Target();
        target.setAddress(address);
    }
    String senderName = senderId + ":" + address;
    Sender sender = session.getEndpoint().sender(senderName);
    sender.setSource(source);
    sender.setTarget(target);
    if (userSpecifiedSenderSettlementMode != null) {
        sender.setSenderSettleMode(userSpecifiedSenderSettlementMode);
        if (SenderSettleMode.SETTLED.equals(userSpecifiedSenderSettlementMode)) {
            presettle = true;
        }
    } else {
        if (presettle) {
            sender.setSenderSettleMode(SenderSettleMode.SETTLED);
        } else {
            sender.setSenderSettleMode(SenderSettleMode.UNSETTLED);
        }
    }
    if (userSpecifiedReceiverSettlementMode != null) {
        sender.setReceiverSettleMode(userSpecifiedReceiverSettlementMode);
    } else {
        sender.setReceiverSettleMode(ReceiverSettleMode.FIRST);
    }
    sender.setDesiredCapabilities(desiredCapabilities);
    sender.setOfferedCapabilities(offeredCapabilities);
    sender.setProperties(properties);
    setEndpoint(sender);
    super.doOpen();
}
Also used : Sender(org.apache.qpid.proton.engine.Sender) Target(org.apache.qpid.proton.amqp.messaging.Target) Symbol(org.apache.qpid.proton.amqp.Symbol) Source(org.apache.qpid.proton.amqp.messaging.Source)

Example 8 with Sender

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

the class AmqpSecurityTest method testSendMessageFailsOnAnonymousRelayWhenNotAuthorizedToSendToAddress.

@Test(timeout = 60000)
public void testSendMessageFailsOnAnonymousRelayWhenNotAuthorizedToSendToAddress() throws Exception {
    CountDownLatch latch = new CountDownLatch(1);
    AmqpClient client = createAmqpClient(guestUser, guestPass);
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
            DeliveryState state = delivery.getRemoteState();
            if (!delivery.remotelySettled()) {
                markAsInvalid("delivery is not remotely settled");
            }
            if (state instanceof Rejected) {
                Rejected rejected = (Rejected) state;
                if (rejected.getError() == null || rejected.getError().getCondition() == null) {
                    markAsInvalid("Delivery should have been Rejected with an error condition");
                } else {
                    ErrorCondition error = rejected.getError();
                    if (!error.getCondition().equals(AmqpError.UNAUTHORIZED_ACCESS)) {
                        markAsInvalid("Should have been tagged with unauthorized access error");
                    }
                }
            } else {
                markAsInvalid("Delivery should have been Rejected");
            }
            latch.countDown();
        }
    });
    AmqpConnection connection = client.connect();
    try {
        AmqpSession session = connection.createSession();
        AmqpSender sender = session.createAnonymousSender();
        AmqpMessage message = new AmqpMessage();
        message.setAddress(getQueueName());
        message.setMessageId("msg" + 1);
        message.setText("Test-Message");
        try {
            sender.send(message);
            fail("Should not be able to send, message should be rejected");
        } catch (Exception ex) {
            ex.printStackTrace();
        } finally {
            sender.close();
        }
        assertTrue(latch.await(5000, TimeUnit.MILLISECONDS));
        connection.getStateInspector().assertValid();
    } finally {
        connection.close();
    }
}
Also used : AmqpConnection(org.apache.activemq.transport.amqp.client.AmqpConnection) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) CountDownLatch(java.util.concurrent.CountDownLatch) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) Sender(org.apache.qpid.proton.engine.Sender) AmqpSession(org.apache.activemq.transport.amqp.client.AmqpSession) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) Delivery(org.apache.qpid.proton.engine.Delivery) Test(org.junit.Test)

Example 9 with Sender

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

the class AmqpSendReceiveTest method testDeliveryDelayOfferedWhenRequested.

@Test(timeout = 60000)
public void testDeliveryDelayOfferedWhenRequested() throws Exception {
    AmqpClient client = createAmqpClient();
    client.setValidator(new AmqpValidator() {

        @Override
        public void inspectOpenedResource(Sender sender) {
            Symbol[] offered = sender.getRemoteOfferedCapabilities();
            if (!contains(offered, AmqpSupport.DELAYED_DELIVERY)) {
                markAsInvalid("Broker did not indicate it support delayed message delivery");
            }
        }
    });
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    AmqpSender sender = session.createSender(getQueueName(), new Symbol[] { AmqpSupport.DELAYED_DELIVERY });
    assertNotNull(sender);
    connection.getStateInspector().assertValid();
    sender.close();
    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) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) Test(org.junit.Test)

Example 10 with Sender

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

the class AmqpTransactionTest method testUnsettledTXMessageGetTransactedDispostion.

@Test(timeout = 30000)
public void testUnsettledTXMessageGetTransactedDispostion() throws Exception {
    AmqpClient client = createAmqpClient();
    AmqpConnection connection = addConnection(client.connect());
    AmqpSession session = connection.createSession();
    assertNotNull(session);
    AmqpSender sender = session.createSender(getQueueName());
    AmqpMessage message = new AmqpMessage();
    message.setText("Test-Message");
    sender.send(message);
    AmqpReceiver receiver = session.createReceiver(getQueueName());
    receiver.setStateInspector(new AmqpValidator() {

        @Override
        public void inspectDeliveryUpdate(Sender sender, Delivery delivery) {
            if (delivery.remotelySettled()) {
                LOG.info("Receiver got delivery update for: {}", delivery);
                if (!(delivery.getRemoteState() instanceof TransactionalState)) {
                    markAsInvalid("Transactionally acquire work no tagged as being in a transaction.");
                } else {
                    TransactionalState txState = (TransactionalState) delivery.getRemoteState();
                    if (!(txState.getOutcome() instanceof Accepted)) {
                        markAsInvalid("Transaction state lacks any outcome");
                    } else if (txState.getTxnId() == null) {
                        markAsInvalid("Transaction state lacks any TX Id");
                    }
                }
                if (!(delivery.getLocalState() instanceof TransactionalState)) {
                    markAsInvalid("Transactionally acquire work no tagged as being in a transaction.");
                } else {
                    TransactionalState txState = (TransactionalState) delivery.getLocalState();
                    if (!(txState.getOutcome() instanceof Accepted)) {
                        markAsInvalid("Transaction state lacks any outcome");
                    } else if (txState.getTxnId() == null) {
                        markAsInvalid("Transaction state lacks any TX Id");
                    }
                }
                TransactionalState localTxState = (TransactionalState) delivery.getLocalState();
                TransactionalState remoteTxState = (TransactionalState) delivery.getRemoteState();
                if (!localTxState.getTxnId().equals(remoteTxState)) {
                    markAsInvalid("Message not enrolled in expected transaction");
                }
            }
        }
    });
    session.begin();
    assertTrue(session.isInTransaction());
    receiver.flow(1);
    AmqpMessage received = receiver.receive(2, TimeUnit.SECONDS);
    assertNotNull(received);
    received.accept(false);
    session.commit();
    sender.getStateInspector().assertValid();
    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) AmqpReceiver(org.apache.activemq.transport.amqp.client.AmqpReceiver) AmqpClient(org.apache.activemq.transport.amqp.client.AmqpClient) Delivery(org.apache.qpid.proton.engine.Delivery) AmqpSender(org.apache.activemq.transport.amqp.client.AmqpSender) AmqpMessage(org.apache.activemq.transport.amqp.client.AmqpMessage) Accepted(org.apache.qpid.proton.amqp.messaging.Accepted) AmqpValidator(org.apache.activemq.transport.amqp.client.AmqpValidator) TransactionalState(org.apache.qpid.proton.amqp.transaction.TransactionalState) Test(org.junit.Test)

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