Search in sources :

Example 31 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project activemq-artemis by apache.

the class AMQPSessionCallback method disconnect.

@Override
public void disconnect(ServerConsumer consumer, SimpleString queueName) {
    ErrorCondition ec = new ErrorCondition(AmqpSupport.RESOURCE_DELETED, "Queue was deleted: " + queueName);
    connection.lock();
    try {
        ((ProtonServerSenderContext) consumer.getProtocolContext()).close(ec);
        connection.flush();
    } catch (ActiveMQAMQPException e) {
        logger.error("Error closing link for " + consumer.getQueue().getAddress());
    } finally {
        connection.unlock();
    }
}
Also used : ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) ProtonServerSenderContext(org.apache.activemq.artemis.protocol.amqp.proton.ProtonServerSenderContext)

Example 32 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project activemq-artemis by apache.

the class AMQPSessionContext method addReceiver.

public void addReceiver(Receiver receiver) throws Exception {
    try {
        ProtonServerReceiverContext protonReceiver = new ProtonServerReceiverContext(sessionSPI, connection, this, receiver);
        protonReceiver.initialise();
        receivers.put(receiver, protonReceiver);
        ServerProducer serverProducer = new ServerProducerImpl(receiver.getName(), "AMQP", receiver.getTarget().getAddress());
        sessionSPI.addProducer(serverProducer);
        receiver.setContext(protonReceiver);
        connection.lock();
        try {
            receiver.open();
        } finally {
            connection.unlock();
        }
    } catch (ActiveMQAMQPException e) {
        receivers.remove(receiver);
        receiver.setTarget(null);
        receiver.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage()));
        connection.lock();
        try {
            receiver.close();
        } finally {
            connection.unlock();
        }
    }
}
Also used : ServerProducerImpl(org.apache.activemq.artemis.core.server.impl.ServerProducerImpl) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException) ServerProducer(org.apache.activemq.artemis.core.server.ServerProducer)

Example 33 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project activemq-artemis by apache.

the class AMQPSessionContext method addSender.

public void addSender(Sender sender) throws Exception {
    // TODO: Remove this check when we have support for global link names
    boolean outgoing = (sender.getContext() != null && sender.getContext().equals(true));
    ProtonServerSenderContext protonSender = outgoing ? new ProtonClientSenderContext(connection, sender, this, sessionSPI) : new ProtonServerSenderContext(connection, sender, this, sessionSPI);
    try {
        protonSender.initialise();
        senders.put(sender, protonSender);
        serverSenders.put(protonSender.getBrokerConsumer(), protonSender);
        sender.setContext(protonSender);
        connection.lock();
        try {
            sender.open();
        } finally {
            connection.unlock();
        }
        protonSender.start();
    } catch (ActiveMQAMQPException e) {
        senders.remove(sender);
        sender.setSource(null);
        sender.setCondition(new ErrorCondition(e.getAmqpError(), e.getMessage()));
        connection.lock();
        try {
            sender.close();
        } finally {
            connection.unlock();
        }
    }
}
Also used : ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) ProtonClientSenderContext(org.apache.activemq.artemis.protocol.amqp.client.ProtonClientSenderContext) ActiveMQAMQPException(org.apache.activemq.artemis.protocol.amqp.exceptions.ActiveMQAMQPException)

Example 34 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project activemq-artemis by apache.

the class ProtonTransactionHandler method createRejected.

private Rejected createRejected(Symbol amqpError, String message) {
    Rejected rejected = new Rejected();
    ErrorCondition condition = new ErrorCondition();
    condition.setCondition(amqpError);
    condition.setDescription(message);
    rejected.setError(condition);
    return rejected;
}
Also used : ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected)

Example 35 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project azure-service-bus-java by Azure.

the class CoreMessageSender method onSendComplete.

@Override
public void onSendComplete(final Delivery delivery) {
    final DeliveryState outcome = delivery.getRemoteState();
    final String deliveryTag = new String(delivery.getTag());
    TRACE_LOGGER.debug("Received ack for delivery. path:{}, linkName:{}, deliveryTag:{}, outcome:{}", CoreMessageSender.this.sendPath, this.sendLink.getName(), deliveryTag, outcome);
    final SendWorkItem<Void> pendingSendWorkItem = this.pendingSendsData.remove(deliveryTag);
    if (pendingSendWorkItem != null) {
        if (outcome instanceof Accepted) {
            this.lastKnownLinkError = null;
            this.retryPolicy.resetRetryCount(this.getClientId());
            pendingSendWorkItem.cancelTimeoutTask(false);
            AsyncUtil.completeFuture(pendingSendWorkItem.getWork(), null);
        } else if (outcome instanceof Rejected) {
            Rejected rejected = (Rejected) outcome;
            ErrorCondition error = rejected.getError();
            Exception exception = ExceptionUtil.toException(error);
            if (ExceptionUtil.isGeneralError(error.getCondition())) {
                this.lastKnownLinkError = exception;
                this.lastKnownErrorReportedAt = Instant.now();
            }
            Duration retryInterval = this.retryPolicy.getNextRetryInterval(this.getClientId(), exception, pendingSendWorkItem.getTimeoutTracker().remaining());
            if (retryInterval == null) {
                this.cleanupFailedSend(pendingSendWorkItem, exception);
            } else {
                TRACE_LOGGER.warn("Send failed for delivery '{}'. Will retry after '{}'", deliveryTag, retryInterval);
                pendingSendWorkItem.setLastKnownException(exception);
                Timer.schedule(() -> {
                    CoreMessageSender.this.reSendAsync(deliveryTag, pendingSendWorkItem, false);
                }, retryInterval, TimerType.OneTimeRun);
            }
        } else if (outcome instanceof Released) {
            this.cleanupFailedSend(pendingSendWorkItem, new OperationCancelledException(outcome.toString()));
        } else {
            this.cleanupFailedSend(pendingSendWorkItem, new ServiceBusException(false, outcome.toString()));
        }
    } else {
        TRACE_LOGGER.warn("Delivery mismatch. path:{}, linkName:{}, delivery:{}", this.sendPath, this.sendLink.getName(), deliveryTag);
    }
}
Also used : Released(org.apache.qpid.proton.amqp.messaging.Released) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Duration(java.time.Duration) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) Accepted(org.apache.qpid.proton.amqp.messaging.Accepted) IOException(java.io.IOException)

Aggregations

ErrorCondition (org.apache.qpid.proton.amqp.transport.ErrorCondition)45 Symbol (org.apache.qpid.proton.amqp.Symbol)13 Test (org.junit.Test)11 Handler (io.vertx.core.Handler)10 ProtonConnection (io.vertx.proton.ProtonConnection)10 DeliveryState (org.apache.qpid.proton.amqp.transport.DeliveryState)10 Message (org.apache.qpid.proton.message.Message)10 Vertx (io.vertx.core.Vertx)8 Logger (io.vertx.core.impl.logging.Logger)8 LoggerFactory (io.vertx.core.impl.logging.LoggerFactory)8 ExecutionException (java.util.concurrent.ExecutionException)8 TimeUnit (java.util.concurrent.TimeUnit)8 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)8 Rejected (org.apache.qpid.proton.amqp.messaging.Rejected)8 ProtonClient (io.vertx.proton.ProtonClient)7 Map (java.util.Map)7 CountDownLatch (java.util.concurrent.CountDownLatch)7 MockServer (io.vertx.proton.MockServer)6 AtomicReference (java.util.concurrent.atomic.AtomicReference)6 Proton (org.apache.qpid.proton.Proton)6