Newbie
Newbie

Reputation: 67

spring integration - multiple gateway

In my project I would be having two inbound gateways with same input params but different response. Each gateway is called declared in a different xml. The problem is when I call gateway1 it goes to xml2 instead of xml1. How should we handle this. Have two gateways in the same interface

public interface MessageGateway {
    @Gateway(requestChannel="requestChannel1")
    @Payload("#args")
    public Response1 invoke(Bean bean) throws Exception;

    @Gateway(requestChannel="requestChannel2")
    @Payload("#args")
    public List<Response2> invoke2(Bean bean) throws Exception;

}

In xml1

<int:gateway id="invoke" default-request-channel="requestChannel1" default-reply-channel="finalResult"
                 service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000"/>
    <int:channel id="errorChannel"/>

In xml2

<int:gateway id="invoke1" default-request-channel="requestChannel2" default-reply-channel="finalResult"
                     service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000"/>
        <int:channel id="errorChannel"/>

I call the gateway from another system. SO I autowire the gateway interface and call the methods.

As per Gary's comment adding the autowiring

@Autowired
private MessageGateway gateway;
//calling
gateway.invoke(bean);

Upvotes: 1

Views: 1563

Answers (2)

cyberpvnk
cyberpvnk

Reputation: 11

A solution is to declare a method sub element. See also the loadBrokerGateway here: http://docs.spring.io/spring-integration/docs/2.0.0.RC1/reference/html/gateway.html.

So XML1

<int:gateway id="invoke" default-request-channel="requestChannel1" default-reply-channel="finalResult" service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000">
    <int:method name="invoke" request-channel="requestChannel1" />
</int:gateway>
<int:channel id="errorChannel"/>

And XML2

<int:gateway id="invoke1" default-request-channel="requestChannel2" default-reply-channel="finalResult" service-interface="<class name>" error-channel="errorChannel" default-reply-timeout="6000">
    <int:method name="invoke" request-channel="requestChannel2" />
</int:gateway>
<int:channel id="errorChannel"/>

Upvotes: 0

Artem Bilan
Artem Bilan

Reputation: 121560

Look. you don't need two <gateway> definitions for the same interface.

If you worry about requestChannel you can use that property on the @Gateway annotation or <method> sub-element of the <gateway>.

In case of two <gateway>s it looks like the second one wins and we have proxy only for that part of configuration.

Upvotes: 1

Related Questions