Skip to content

Gateway: evaluate setting a NullChannel replyChannel in case of void return type method #3280

@mauromol

Description

@mauromol

Expected Behavior

The full discussion is at: https://stackoverflow.com/questions/61756786/spring-integration-gateway-with-void-method-return-type-why-doesnt-it-set-a-nu

Substantially, when I set up a gateway method with void return type, I expect that any reply message that is produced by the downstream chain is simply ignored, and that I can rather opt-in for an exception if an unexpected (?) reply message is produced.

Current Behavior

If I understand it well, right now a gateway method with void return type only works (with no exception) if the downstream chain ends with an outbound adapter or if I explicitly set a NullChannel replyChannel somewhere in the chain (perhaps with an annotation on the gateway method). Otherwise an exception is produced:

org.springframework.messaging.core.DestinationResolutionException: no output-channel or replyChannel header available

In my case I have a gateway interface with many methods and a downstream HTTP outbound gateway that invokes actions on a remote service through REST. The REST API provides some actions with a response, some others with no meaningful response (apart from a status code which is used to correctly wire errors).
On my gateway interface I would expect that a method with a void return type is enough to tell Spring Integration that I don't care about any (unmeaningful) response produced by the HTTP outbound gateway, but this is not the case and an exception is produced. I have to annotate my interface method by specifying a MessageHeaders.REPLY_CHANNEL header with nullChannel name or @nullChannel expression, or rather set this header somewhere else in my downstream chain. But this sounds redundant to me.

By debugging I see that org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(MethodInvocation, boolean) does a "sendAndReceive" when the gateway method is expected to return something, otherwise a simple "send". The former call causes an appropriate replyChannel header to be set on the produced message (sorry, I'm not sure on how this is done, probably by org.springframework.integration.gateway.MessagingGatewaySupport.registerReplyMessageCorrelator()?), while the latter doesn't cause any replyChannel header to be set and hence the exception occurs if a reply message arrives from the downstream chain.

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions