protected void doHandleResult(InvocationResult resultArg, Message request, Channel channel, Object source) { if (this.logger.isDebugEnabled()) { this.logger.debug("Listener method returned result [" + resultArg + "] - generating response message for it"); } try { Message response = buildMessage(channel, resultArg.getReturnValue(), resultArg.getReturnType()); postProcessResponse(request, response); Address replyTo = getReplyToAddress(request, source, resultArg); sendResponse(channel, replyTo, response); } catch (Exception ex) { throw new ReplyFailureException("Failed to send reply with payload '" + resultArg + "'", ex); } }
/** * Extract the message body from the given Rabbit message. * @param message the Rabbit <code>Message</code> * @return the content of the message, to be passed into the listener method as argument */ protected Object extractMessage(Message message) { MessageConverter converter = getMessageConverter(); if (converter != null) { return converter.fromMessage(message); } return message; }
/** * Handle the given result object returned from the listener method, sending a * response message back. * @param resultArg the result object to handle (never <code>null</code>) * @param request the original request message * @param channel the Rabbit channel to operate on (may be <code>null</code>) * @see #buildMessage * @see #postProcessResponse * @see #getReplyToAddress(Message, Object, InvocationResult) * @see #sendResponse */ protected void handleResult(InvocationResult resultArg, Message request, Channel channel) { handleResult(resultArg, request, channel, null); }
if (resultArg.getReturnValue() instanceof ListenableFuture) { ((ListenableFuture<?>) resultArg.getReturnValue()).addCallback( r -> asyncSuccess(resultArg, request, channel, source, r), t -> asyncFailure(request, channel, t)); r -> asyncSuccess(resultArg, request, channel, source, r), t -> asyncFailure(request, channel, t)); doHandleResult(resultArg, request, channel, source);
.andProperties(getMessagePropertiesConverter() .toMessageProperties(i.getArgument(3), envelope, // NOSONAR magic # adapter.getEncoding())) .build()); return null; any(byte[].class)); message.getMessageProperties().setReplyTo(REPLY_QUEUE); adapter.onMessage(message, channel);
postProcessChannel(channel, message); + replyTo.getRoutingKey() + "]"); if (this.retryTemplate == null) { doPublish(channel, replyTo, message); doPublish(channel, replyTo, messageToSend); return null; }, ctx -> {
private void asyncSuccess(InvocationResult resultArg, Message request, Channel channel, Object source, Object r) { doHandleResult(new InvocationResult(r, resultArg.getSendTo(), resultArg.getReturnType()), request, channel, source); try { channel.basicAck(request.getMessageProperties().getDeliveryTag(), false); } catch (IOException e) { this.logger.error("Failed to nack message", e); } }
replyTo = evaluateReplyTo(request, source, result.getReturnValue(), result.getSendTo()); replyTo = evaluateReplyTo(request, source, result.getReturnValue(), this.responseExpression);
if (resultArg.getReturnValue() instanceof ListenableFuture) { ((ListenableFuture<?>) resultArg.getReturnValue()).addCallback( r -> asyncSuccess(resultArg, request, channel, source, r), t -> asyncFailure(request, channel, t)); r -> asyncSuccess(resultArg, request, channel, source, r), t -> asyncFailure(request, channel, t)); doHandleResult(resultArg, request, channel, source);
.andProperties(getMessagePropertiesConverter() .toMessageProperties(i.getArgument(3), envelope, // NOSONAR magic # adapter.getEncoding())) .build()); return null; any(byte[].class)); message.getMessageProperties().setReplyTo(REPLY_QUEUE); adapter.onMessage(message, channel);
postProcessChannel(channel, message); + replyTo.getRoutingKey() + "]"); if (this.retryTemplate == null) { doPublish(channel, replyTo, message); doPublish(channel, replyTo, messageToSend); return null; }, ctx -> {
private void asyncSuccess(InvocationResult resultArg, Message request, Channel channel, Object source, Object r) { doHandleResult(new InvocationResult(r, resultArg.getSendTo(), resultArg.getReturnType()), request, channel, source); try { channel.basicAck(request.getMessageProperties().getDeliveryTag(), false); } catch (IOException e) { this.logger.error("Failed to nack message", e); } }
replyTo = evaluateReplyTo(request, source, result.getReturnValue(), result.getSendTo()); replyTo = evaluateReplyTo(request, source, result.getReturnValue(), this.responseExpression);
protected void doHandleResult(InvocationResult resultArg, Message request, Channel channel, Object source) { if (this.logger.isDebugEnabled()) { this.logger.debug("Listener method returned result [" + resultArg + "] - generating response message for it"); } try { Message response = buildMessage(channel, resultArg.getReturnValue(), resultArg.getReturnType()); postProcessResponse(request, response); Address replyTo = getReplyToAddress(request, source, resultArg); sendResponse(channel, replyTo, response); } catch (Exception ex) { throw new ReplyFailureException("Failed to send reply with payload '" + resultArg + "'", ex); } }
/** * Extract the message body from the given Rabbit message. * @param message the Rabbit <code>Message</code> * @return the content of the message, to be passed into the listener method as argument */ protected Object extractMessage(Message message) { MessageConverter converter = getMessageConverter(); if (converter != null) { return converter.fromMessage(message); } return message; }
/** * Handle the given result object returned from the listener method, sending a * response message back. * @param resultArg the result object to handle (never <code>null</code>) * @param request the original request message * @param channel the Rabbit channel to operate on (may be <code>null</code>) * @see #buildMessage * @see #postProcessResponse * @see #getReplyToAddress(Message, Object, InvocationResult) * @see #sendResponse */ protected void handleResult(InvocationResult resultArg, Message request, Channel channel) { handleResult(resultArg, request, channel, null); }
/** * Build a Rabbit message to be sent as response based on the given result object. * @param channel the Rabbit Channel to operate on. * @param result the content of the message, as returned from the listener method. * @param genericType the generic type to populate type headers. * @return the Rabbit <code>Message</code> (never <code>null</code>). * @see #setMessageConverter */ protected Message buildMessage(Channel channel, Object result, Type genericType) { MessageConverter converter = getMessageConverter(); if (converter != null && !(result instanceof Message)) { return converter.toMessage(result, new MessageProperties(), genericType); } else { if (!(result instanceof Message)) { throw new MessageConversionException("No MessageConverter specified - cannot handle message [" + result + "]"); } return (Message) result; } }
/** * Build a Rabbit message to be sent as response based on the given result object. * @param channel the Rabbit Channel to operate on. * @param result the content of the message, as returned from the listener method. * @param genericType the generic type to populate type headers. * @return the Rabbit <code>Message</code> (never <code>null</code>). * @see #setMessageConverter */ protected Message buildMessage(Channel channel, Object result, Type genericType) { MessageConverter converter = getMessageConverter(); if (converter != null && !(result instanceof Message)) { return converter.toMessage(result, new MessageProperties(), genericType); } else { if (!(result instanceof Message)) { throw new MessageConversionException("No MessageConverter specified - cannot handle message [" + result + "]"); } return (Message) result; } }