6
votes

I've questions/clarifications-to-make regarding SI gateway feature:

If my gateway interface is defined as below:

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

And my gateway configuration defined as 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-make are :

1) Since the gateway service interface method is returning void, does the Gateway proxy bean still look for a response on the "default-reply-channel" or the user defined "reply-channel" ?

2) In other words, do I still need to mention reply-channel="nullChannel" (or default-reply-channel="nullChannel") ?

OR

since the method return is void, gateway automatically will understand no to listen to the reply channel ?

3) Can I still add reply-timeout attribute to this configuration OR it will not make sense since there is no reply expected ?

In similar context, if I add another method in the service interface method as below:

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

and add this method in my gateway config as 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 would believe I need to define reply-channel, correct ?

5) The default-reply-channel may not work for this case as for one method gateway expects a response and not for other, correct ?

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

Thanks to confirm.

1
Can someone pls help me out on above clarifications ? Artem/Garry - Looking for your kind attn ! Many thanks !lbvirgo
OK, Lalit. I'm starring your question and take a look today :-)Artem Bilan

1 Answers

5
votes

Lalit!

Thank for such a big bunch of question and I'm surprised that all of them are around the gateway's void method.

The quick reasonable answer to all of them is:

Since we don't say in the Reference Manual anything on the matter, there is no worries for such a configuration and it should work as expected by the
faith in Spring Integration.

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

Now let's take a look to the source code of 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 to the

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

which is void, too, and just calls in the end MessageChannel.send().

As you may guess this method doesn't care about replyChannel and replyTimeout at all.

Logically it assumes that those options will be just ignored for the void method and any default-* for other methods doesn't impact those with void return type.

Hope I am clear.