Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@sendTo does not work with errorHandler #1021

Closed
priyanshus1 opened this issue Jun 12, 2019 · 4 comments
Closed

@sendTo does not work with errorHandler #1021

priyanshus1 opened this issue Jun 12, 2019 · 4 comments
Assignees
Milestone

Comments

@priyanshus1
Copy link

Affects Version(s): 2.1.5

Question

I am using @sendto annotation with RabbitListenerErrorHandler errorHandler().
But I am getting following error:

Caused by: org.springframework.amqp.rabbit.listener.adapter.ReplyFailureException: Failed to send reply with payload 'InvocationResult [returnValue=org.springframework.remoting.support.RemoteInvocationResult@2c663a5c, returnType=null]'
	at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.doHandleResult(AbstractAdaptableMessageListener.java:385) ~[spring-rabbit-2.1.5.RELEASE.jar:2.1.5.RELEASE]
	at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.handleResult(AbstractAdaptableMessageListener.java:339) ~[spring-rabbit-2.1.5.RELEASE.jar:2.1.5.RELEASE]
	at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.returnOrThrow(MessagingMessageListenerAdapter.java:162) ~[spring-rabbit-2.1.5.RELEASE.jar:2.1.5.RELEASE]
	at org.springframework.amqp.rabbit.listener.adapter.MessagingMessageListenerAdapter.onMessage(MessagingMessageListenerAdapter.java:147) ~[spring-rabbit-2.1.5.RELEASE.jar:2.1.5.RELEASE]
	at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1552) ~[spring-rabbit-2.1.5.RELEASE.jar:2.1.5.RELEASE]
	... 10 common frames omitted
Caused by: org.springframework.amqp.AmqpException: Cannot determine ReplyTo message property value: Request message does not contain reply-to property, and no default response Exchange was set.
	at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.getReplyToAddress(AbstractAdaptableMessageListener.java:465) ~[spring-rabbit-2.1.5.RELEASE.jar:2.1.5.RELEASE]
	at org.springframework.amqp.rabbit.listener.adapter.AbstractAdaptableMessageListener.doHandleResult(AbstractAdaptableMessageListener.java:381) ~[spring-rabbit-2.1.5.RELEASE.jar:2.1.5.RELEASE]
	... 14 common frames omitted

Bug report

When debugged in detail I found out that MessagingMessageListenerAdapter.onMessage() function always create the InvocationResult with null sendTo and null Type; while calling the handleResult().

@Override
	public void onMessage(org.springframework.amqp.core.Message amqpMessage, Channel channel) throws Exception { // NOSONAR
		Message<?> message = toMessagingMessage(amqpMessage);
		if (logger.isDebugEnabled()) {
			logger.debug("Processing [" + message + "]");
		}
		InvocationResult result = null;
		try {
			result = invokeHandler(amqpMessage, channel, message);
			if (result.getReturnValue() != null) {
				handleResult(result, amqpMessage, channel, message);
			}
			else {
				logger.trace("No result object given - no result to handle");
			}
		}
		catch (ListenerExecutionFailedException e) {
			if (this.errorHandler != null) {
				try {
					Object errorResult = this.errorHandler.handleError(amqpMessage, message, e);
					if (errorResult != null) {
						handleResult(new InvocationResult(errorResult, null, null), amqpMessage, channel, message);
					}
					else {
						logger.trace("Error handler returned no result");
					}
				}
				catch (Exception ex) {
					returnOrThrow(amqpMessage, channel, message, ex, ex);
				}
			}
			else {
				returnOrThrow(amqpMessage, channel, message, e.getCause(), e);
			}
		}
	}

Well according to documentation mentioned here https://docs.spring.io/spring-amqp/docs/2.1.5.RELEASE/api/ in Interface RabbitListenerErrorHandler
"Handle the error. If an exception is not thrown, the return value is returned to the sender using normal replyTo/@sendto semantics."

I think we can fix the bug by createing InvocationResult with different Expression value or something.

@garyrussell
Copy link
Contributor

Yes, it's a bug; it works if the incoming message has a replyTo header, but the send to expression is lost.

@garyrussell garyrussell self-assigned this Jun 13, 2019
@garyrussell garyrussell added this to the 2.1.7 milestone Jun 13, 2019
@priyanshus1
Copy link
Author

Hi Gary,

Is it not possible to fix it 2.1.6 ? is it already prepared to ship.
I could also fix it if you want ?

@artembilan
Copy link
Member

Yes, Gary has marked it to be fixed in the upcoming 2.1.7 version.

And yes: a contribution is more than welcome!

Please, consider to raise PR against master and we will back-port it into the 2.1.x branch.

Thank you!

@garyrussell
Copy link
Contributor

It turns out this is only a problem on class-level @RabbitListeners.

I went ahead and fixed it because we need to release tomorrow.

garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Jun 13, 2019
spring-projects#1021

Sending the result from a `RabbitListenerErrorHandler` was broken
for class-level `@RabbitListener` because the send to expression
was lost.

**cherry-pick to 2.1.x**
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Jun 13, 2019
spring-projects#1021

Sending the result from a `RabbitListenerErrorHandler` was broken
for class-level `@RabbitListener` because the send to expression
was lost.

**cherry-pick to 2.1.x**
artembilan pushed a commit that referenced this issue Jun 14, 2019
Fixes #1021

Sending the result from a `RabbitListenerErrorHandler` was broken
for class-level `@RabbitListener` because the send to expression
was lost.

**cherry-pick to 2.1.x**

* * Also capture the generic return type after the error is handled

# Conflicts:
#	spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants