Search in sources :

Example 6 with ErrorCondition

use of org.apache.qpid.proton.amqp.transport.ErrorCondition in project hono by eclipse.

the class ConnectionFactoryImpl method handleConnectionAttemptResult.

private void handleConnectionAttemptResult(final AsyncResult<ProtonConnection> conAttempt, final ProtonClientOptions clientOptions, final Handler<AsyncResult<ProtonConnection>> closeHandler, final Handler<ProtonConnection> disconnectHandler, final Handler<AsyncResult<ProtonConnection>> connectionResultHandler) {
    if (conAttempt.failed()) {
        logger.debug("can't connect to AMQP 1.0 container [{}://{}:{}]: {}", clientOptions.isSsl() ? "amqps" : "amqp", config.getHost(), config.getPort(), conAttempt.cause().getMessage());
        connectionResultHandler.handle(Future.failedFuture(conAttempt.cause()));
    } else {
        // at this point the SASL exchange has completed successfully
        logger.debug("connected to AMQP 1.0 container [{}://{}:{}], opening connection ...", clientOptions.isSsl() ? "amqps" : "amqp", config.getHost(), config.getPort());
        ProtonConnection downstreamConnection = conAttempt.result();
        downstreamConnection.setContainer(String.format("%s-%s", config.getName(), UUID.randomUUID())).setHostname(config.getAmqpHostname()).openHandler(openCon -> {
            if (openCon.succeeded()) {
                logger.debug("connection to container [{}] at [{}://{}:{}] open", downstreamConnection.getRemoteContainer(), clientOptions.isSsl() ? "amqps" : "amqp", config.getHost(), config.getPort());
                downstreamConnection.disconnectHandler(disconnectHandler);
                downstreamConnection.closeHandler(closeHandler);
                connectionResultHandler.handle(Future.succeededFuture(downstreamConnection));
            } else {
                final ErrorCondition error = downstreamConnection.getRemoteCondition();
                if (error == null) {
                    logger.warn("can't open connection to container [{}] at [{}://{}:{}]", downstreamConnection.getRemoteContainer(), clientOptions.isSsl() ? "amqps" : "amqp", config.getHost(), config.getPort(), openCon.cause());
                } else {
                    logger.warn("can't open connection to container [{}] at [{}://{}:{}]: {} -{}", downstreamConnection.getRemoteContainer(), clientOptions.isSsl() ? "amqps" : "amqp", config.getHost(), config.getPort(), error.getCondition(), error.getDescription());
                }
                connectionResultHandler.handle(Future.failedFuture(openCon.cause()));
            }
        }).open();
    }
}
Also used : ProtonConnection(io.vertx.proton.ProtonConnection) Logger(org.slf4j.Logger) LoggerFactory(org.slf4j.LoggerFactory) Vertx(io.vertx.core.Vertx) ProtonClient(io.vertx.proton.ProtonClient) UUID(java.util.UUID) Future(io.vertx.core.Future) Objects(java.util.Objects) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) TrustOptions(io.vertx.core.net.TrustOptions) ProtonClientOptions(io.vertx.proton.ProtonClientOptions) KeyCertOptions(io.vertx.core.net.KeyCertOptions) ProtonSaslExternalImpl(io.vertx.proton.sasl.impl.ProtonSaslExternalImpl) AsyncResult(io.vertx.core.AsyncResult) Handler(io.vertx.core.Handler) ProtonSaslPlainImpl(io.vertx.proton.sasl.impl.ProtonSaslPlainImpl) ClientConfigProperties(org.eclipse.hono.config.ClientConfigProperties) Strings(org.eclipse.hono.util.Strings) ProtonConnection(io.vertx.proton.ProtonConnection) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition)

Example 7 with ErrorCondition

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

the class CoreMessageReceiver method onReceiveComplete.

@Override
public void onReceiveComplete(Delivery delivery) {
    this.underlyingFactory.getRetryPolicy().resetRetryCount(this.getClientId());
    byte[] deliveryTag = delivery.getTag();
    String deliveryTagAsString = StringUtil.convertBytesToString(delivery.getTag());
    TRACE_LOGGER.debug("Received a delivery '{}' from '{}'", deliveryTagAsString, this.receivePath);
    if (deliveryTag == null || deliveryTag.length == 0 || !this.tagsToDeliveriesMap.containsKey(deliveryTagAsString)) {
        TRACE_LOGGER.debug("Received a message from '{}'. Adding to prefecthed messages.", this.receivePath);
        try {
            Message message = Util.readMessageFromDelivery(receiveLink, delivery);
            if (this.settleModePair.getSenderSettleMode() == SenderSettleMode.SETTLED) {
                // No op. Delivery comes settled from the sender
                delivery.disposition(Accepted.getInstance());
                delivery.settle();
            } else {
                this.tagsToDeliveriesMap.put(StringUtil.convertBytesToString(delivery.getTag()), delivery);
                receiveLink.advance();
            }
            // Accuracy of count is not that important. So not making those two operations atomic
            this.currentPrefetechedMessagesCount.incrementAndGet();
            this.prefetchedMessages.add(new MessageWithDeliveryTag(message, delivery.getTag()));
        } catch (Exception e) {
            TRACE_LOGGER.warn("Reading message from delivery '{}' from '{}', session '{}' failed with unexpected exception.", deliveryTagAsString, this.receivePath, this.sessionId, e);
            delivery.disposition(Released.getInstance());
            delivery.settle();
            return;
        }
    } else {
        DeliveryState remoteState = delivery.getRemoteState();
        TRACE_LOGGER.debug("Received a delivery '{}' with state '{}' from '{}'", deliveryTagAsString, remoteState, this.receivePath);
        if (remoteState instanceof Outcome) {
            Outcome remoteOutcome = (Outcome) remoteState;
            UpdateStateWorkItem matchingUpdateStateWorkItem = this.pendingUpdateStateRequests.get(deliveryTagAsString);
            if (matchingUpdateStateWorkItem != null) {
                // This comparison is ugly. Using it for the lack of equals operation on Outcome classes
                if (remoteOutcome.getClass().getName().equals(matchingUpdateStateWorkItem.outcome.getClass().getName())) {
                    TRACE_LOGGER.debug("Completing a pending updateState operation for delivery '{}' from '{}'", deliveryTagAsString, this.receivePath);
                    this.completePendingUpdateStateWorkItem(delivery, deliveryTagAsString, matchingUpdateStateWorkItem, null);
                } else {
                    // if(matchingUpdateStateWorkItem.expectedOutcome instanceof Accepted)
                    // {
                    TRACE_LOGGER.warn("Received delivery '{}' state '{}' doesn't match expected state '{}'", deliveryTagAsString, remoteState, matchingUpdateStateWorkItem.outcome);
                    // Complete requests
                    if (remoteOutcome instanceof Rejected) {
                        Rejected rejected = (Rejected) remoteOutcome;
                        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, matchingUpdateStateWorkItem.getTimeoutTracker().remaining());
                        if (retryInterval == null) {
                            TRACE_LOGGER.error("Completing pending updateState operation for delivery '{}' with exception", deliveryTagAsString, exception);
                            this.completePendingUpdateStateWorkItem(delivery, deliveryTagAsString, matchingUpdateStateWorkItem, exception);
                        } else {
                            matchingUpdateStateWorkItem.setLastKnownException(exception);
                            // Retry after retry interval
                            TRACE_LOGGER.debug("Pending updateState operation for delivery '{}' will be retried after '{}'", deliveryTagAsString, retryInterval);
                            try {
                                this.underlyingFactory.scheduleOnReactorThread((int) retryInterval.toMillis(), new DispatchHandler() {

                                    @Override
                                    public void onEvent() {
                                        delivery.disposition((DeliveryState) matchingUpdateStateWorkItem.getOutcome());
                                    }
                                });
                            } catch (IOException ioException) {
                                this.completePendingUpdateStateWorkItem(delivery, deliveryTagAsString, matchingUpdateStateWorkItem, new ServiceBusException(false, "Operation failed while scheduling a retry on Reactor, see cause for more details.", ioException));
                            }
                        }
                    } else if (remoteOutcome instanceof Released) {
                        Exception exception = new OperationCancelledException(remoteOutcome.toString());
                        TRACE_LOGGER.error("Completing pending updateState operation for delivery '{}' with exception", deliveryTagAsString, exception);
                        this.completePendingUpdateStateWorkItem(delivery, deliveryTagAsString, matchingUpdateStateWorkItem, exception);
                    } else {
                        Exception exception = new ServiceBusException(false, remoteOutcome.toString());
                        TRACE_LOGGER.error("Completing pending updateState operation for delivery '{}' with exception", deliveryTagAsString, exception);
                        this.completePendingUpdateStateWorkItem(delivery, deliveryTagAsString, matchingUpdateStateWorkItem, exception);
                    }
                // }
                }
            } else {
            // Should not happen. Ignore it
            }
        } else {
        // Ignore it. we are only interested in terminal delivery states
        }
    }
}
Also used : Released(org.apache.qpid.proton.amqp.messaging.Released) Message(org.apache.qpid.proton.message.Message) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) DispatchHandler(com.microsoft.azure.servicebus.amqp.DispatchHandler) Duration(java.time.Duration) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) IOException(java.io.IOException) IOException(java.io.IOException) DeliveryState(org.apache.qpid.proton.amqp.transport.DeliveryState) Outcome(org.apache.qpid.proton.amqp.messaging.Outcome)

Example 8 with ErrorCondition

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

the class CoreMessageReceiver method deadLetterMessageAsync.

public CompletableFuture<Void> deadLetterMessageAsync(byte[] deliveryTag, String deadLetterReason, String deadLetterErrorDescription, Map<String, Object> propertiesToModify) {
    Rejected outcome = new Rejected();
    ErrorCondition error = new ErrorCondition(ClientConstants.DEADLETTERNAME, null);
    Map<String, Object> errorInfo = new HashMap<String, Object>();
    if (!StringUtil.isNullOrEmpty(deadLetterReason)) {
        errorInfo.put(ClientConstants.DEADLETTER_REASON_HEADER, deadLetterReason);
    }
    if (!StringUtil.isNullOrEmpty(deadLetterErrorDescription)) {
        errorInfo.put(ClientConstants.DEADLETTER_ERROR_DESCRIPTION_HEADER, deadLetterErrorDescription);
    }
    if (propertiesToModify != null) {
        errorInfo.putAll(propertiesToModify);
    }
    error.setInfo(errorInfo);
    outcome.setError(error);
    return this.updateMessageStateAsync(deliveryTag, outcome);
}
Also used : ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected)

Example 9 with ErrorCondition

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

the class ConnectionHandler method onTransportError.

@Override
public void onTransportError(Event event) {
    ErrorCondition condition = event.getTransport().getCondition();
    if (condition != null) {
        TRACE_LOGGER.warn("Connection.onTransportError: hostname:{}, error:{}", event.getConnection().getHostname(), condition.getDescription());
    } else {
        TRACE_LOGGER.warn("Connection.onTransportError: hostname:{}. error:{}", event.getConnection().getHostname(), "no description returned");
    }
    this.messagingFactory.onConnectionError(condition);
    Connection connection = event.getConnection();
    if (connection != null) {
        connection.free();
    }
}
Also used : ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Connection(org.apache.qpid.proton.engine.Connection)

Example 10 with ErrorCondition

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

the class AMQPSessionCallback method rejectMessage.

private void rejectMessage(Delivery delivery, Symbol errorCondition, String errorMessage) {
    ErrorCondition condition = new ErrorCondition();
    condition.setCondition(errorCondition);
    condition.setDescription(errorMessage);
    Rejected rejected = new Rejected();
    rejected.setError(condition);
    afterIO(new IOCallback() {

        @Override
        public void done() {
            connection.lock();
            try {
                delivery.disposition(rejected);
                delivery.settle();
            } finally {
                connection.unlock();
            }
            connection.flush();
        }

        @Override
        public void onError(int errorCode, String errorMessage) {
        }
    });
}
Also used : ErrorCondition(org.apache.qpid.proton.amqp.transport.ErrorCondition) Rejected(org.apache.qpid.proton.amqp.messaging.Rejected) SimpleString(org.apache.activemq.artemis.api.core.SimpleString) IOCallback(org.apache.activemq.artemis.core.io.IOCallback)

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