use of org.eclipse.hono.service.metric.MetricsTags.QoS in project hono by eclipse.
the class VertxBasedAmqpProtocolAdapter method onMessageReceived.
/**
* Processes an AMQP message received from a device.
* <p>
* This method settles the transfer with the following outcomes:
* <ul>
* <li><em>accepted</em> if the message has been successfully processed.</li>
* <li><em>rejected</em> if the message could not be processed due to a problem caused by the device.</li>
* <li><em>released</em> if the message could not be forwarded to a downstream consumer.</li>
* </ul>
*
* @param ctx The context for the message.
* @return A future indicating the outcome of processing the message.
* The future will succeed if the message has been processed successfully, otherwise it
* will fail with a {@link ServiceInvocationException}.
*/
protected Future<Void> onMessageReceived(final AmqpContext ctx) {
log.trace("processing message [address: {}, qos: {}]", ctx.getAddress(), ctx.getRequestedQos());
final Span msgSpan = ctx.getTracingSpan();
return validateEndpoint(ctx).compose(validatedEndpoint -> validateAddress(validatedEndpoint.getAddress(), validatedEndpoint.getAuthenticatedDevice())).compose(validatedAddress -> uploadMessage(ctx, validatedAddress, msgSpan)).map(d -> {
ProtonHelper.accepted(ctx.delivery(), true);
return d;
}).recover(t -> {
if (t instanceof ClientErrorException) {
MessageHelper.rejected(ctx.delivery(), getErrorCondition(t));
} else {
ProtonHelper.released(ctx.delivery(), true);
}
log.debug("failed to process message from device", t);
TracingHelper.logError(msgSpan, t);
return Future.failedFuture(t);
});
}
Aggregations