Spring Integration Gateway response channel when return method is invalid

I have questions / explanations regarding the SI gateway function:

If my gateway interface is defined below:

public interface MyGateway{ public void myGatewayMethod(Message<?> inMessage); } 

And my gateway configuration is defined below:

 <int:gateway id="mySvcGateway" service-interface="com.myCompany.myPkg.MyGateway" error-channel="globalExceptionHandlerChannel"> <int:method name="myGatewayMethod" request-channel="myGatewayReqChannel" /> </int:gateway> 

My questions / clarifications to the following:

1) Since the gateway service interface method returns void, is the bean gateway proxy still looking for the answer to the "default response channel" or the user "response channel"?

2) In other words, is it worth mentioning reply-channel="nullChannel" (or default-reply-channel="nullChannel" )?

OR

since the method return is invalid, the gateway will automatically understand if there is a listening channel for the response?

3) Can I add the reply-timeout attribute to this configuration OR does it not make sense since no response is expected?

In a similar context, if I add another method to the service interface method, as shown below:

 public interface MyGateway{ public void myGatewayMethod(Message<?> inMessage); public Object myGatewayMethod2(Message<?> inMessage); } 

and add this method to my gateway configuration as shown below:

 <int:gateway id="mySvcGateway" service-interface="com.myCompany.myPkg.MyGateway" error-channel="globalExceptionHandlerChannel"> <int:method name="myGatewayMethod" request-channel="myGatewayReqChannel" /> <int:method name="myGatewayMethod2" request-channel="myGatewayReqChannel2" /> </int:gateway> 

4) In this case, I believe that I need to define a reply-channel , right?

5) default-reply-channel may not work for this case, since for one method the gateway is waiting for a response, and not for another, right?

6) If yes, then for the method that returns void, do I need to explicitly specify reply-channel="nullChannel" ?

Thanks to confirmation.

+5
source share
1 answer

Lalita!

Thanks for such a big question, and I'm surprised that they are all around the void gateway method.

A quick, reasonable answer for all of them:

Since we are not saying anything on this subject in the Reference Guide, there is no problem for such a configuration, and it should work as expected, faith in Spring Integration.

I'm joking a bit, but every joke has a piece of truth.

Now take a look at the source code of the GatewayProxyFactoryBean :

  private Object invokeGatewayMethod(MethodInvocation invocation, boolean runningOnCallerThread) throws Exception { .......... boolean shouldReply = returnType != void.class; .................. Object[] args = invocation.getArguments(); if (shouldReply) { response = shouldReturnMessage ? gateway.sendAndReceiveMessage(args) : gateway.sendAndReceive(args); } else { gateway.send(args); response = null; } } return (response != null) ? this.convert(response, returnType) : null; } 

Where MessagingGatewaySupport.send() delegates

 this.messagingTemplate.convertAndSend(requestChannel, object, this.historyWritingPostProcessor); 

which is also void , and just calls MessageChannel.send() at the end.

As you can guess, this method does not care about replyChannel and replyTimeout .

It is logically assumed that these parameters will simply be ignored for the void method, and any default-* for other methods will not affect those that have a void return type.

I hope I get it.

+3
source

Source: https://habr.com/ru/post/1233970/


All Articles