@Override public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { String correlationId = properties.getCorrelationId(); if (correlationId != null) { PendingRequest request = pendingRequests.remove(correlationId); if (request != null) { try { request.complete(responseTranscoder.decodeFromBytes(body)); } catch (Exception e) { logger.error("Unhandled error completing RPC request", e); } } else { logger.warn("Cannot correlate request with id: " + correlationId + ", it is possible the request timedout."); } } else { logger.warn("Ignoring message with no correlation id"); } } });
protected void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { Timer.Context ctx = this.consumeTimer.time(); try { try { // decode the event T event = this.transcoder.decodeFromBytes(body); // handle the event this.handler.handleDevliery(properties.getHeaders(), event); // ack the event this.channel.basicAck(envelope.getDeliveryTag(), false); } catch (Exception e) { // send a nack for this delivery logger.error("Error handling message delivery, rejecting" + (this.requeueOnError ? " for requeue" : ""), e); this.channel.basicNack(envelope.getDeliveryTag(), false, this.requeueOnError); } } finally { ctx.stop(); } }
protected void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { String correlationId = properties.getCorrelationId(); String replyTo = properties.getReplyTo(); if (correlationId != null && replyTo != null) { // decode the event T event = this.transcoder.decodeFromBytes(body); // handle the event R response = this.handler.handleDevliery(event); // ack the event this.channel.basicAck(envelope.getDeliveryTag(), false); // send the response if (response != null) { this.channel.basicPublish( "", replyTo, new BasicProperties("application/json", null, null, 1, null, correlationId, null, null, null, null, null, null, null, null), this.responseTranscoder.encodeAsBytes(response) ); } } else { logger.warn("Ignoring request without correlationId or replyTo"); } }