First post. I'm new to Spring Integration and have the following scenario: I have a service, "xyzSearchService.getXYZ", that is invoked as a result of an http inbound request. It does some logic then calls the "routingChannel" which in turn calls the google geocode service.
I want the response from google to be returned to xyzSearchService.getXYZ but I am not sure how to configure the replyChannel in the "outboundGateway". Now I have it go to another method in the same service where I can see the results but I want it to be returned to the service/method that called it. Not sure how to configure my final outbound-channel-adapter?
<int-http:inbound-gateway id="inboundXYZSearchRequestGateway"
supported-methods="GET, POST"
request-channel="xyzSearchRequest"
reply-channel="xyzSearchResponse"
mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
view-name="/xyz"
path="/services/xyz/zip/{zipcode}/search"
reply-timeout="50000">
<int-http:header name="zipcode" expression="#pathVariables.zipcode"/>
</int-http:inbound-gateway>
<int:service-activator id="xyzServiceActivator"
input-channel="xyzSearchRequest"
output-channel="xyzSearchResponse"
ref="xyzSearchService"
method="getXYZ"
requires-reply="true"
send-timeout="60000"/>
//the service activator method does some logic and invokes the "routingChannel"
<int:chain input-channel="routingChannel">
<int:router
expression="payload.serviceType"
default-output-channel="channel_default"
resolution-required="false">
</int:router>
</int:chain>
<int-http:outbound-gateway id="outboundGateway"
url="http://maps.googleapis.com/maps/api/geocode/json?address={zipCode}"
http-method="GET"
request-factory="requestFactory"
request-channel="restchannel"
reply-channel="channel2"
expected-response-type="java.lang.String">
<int-http:uri-variable name="zipCode" `enter code `enter code here`here`expression="payload.data['zipcode']"/>
</int-http:outbound-gateway>
<int:channel id="channel2"/>
<int:outbound-channel-adapter channel="channel2" ref="xyzSearchService" method="routeUnit" />
EDIT:
Are you suggesting I create an inbound-gateway, as follows, and invoke that from my service method?
<int-http:inbound-gateway id="inboundNewZipRequestGateway"
supported-methods="GET, POST"
request-channel="zipRoutingChannel"
reply-channel="zipSearchResponse"
mapped-response-headers="Return-Status, Return-Status-Msg, HTTP_RESPONSE_HEADERS"
view-name="/zip"
path="/services/zip/zipcode/{zipcode}/search"
reply-timeout="50000">
<int-http:header name="zipcode" expression="#pathVariables.zipcode"/>
</int-http:inbound-gateway>
EDIT:
i have added the gateway as follows:
<int:gateway id="toHttp" service-interface="com.....domain.MyGW"
default-request-channel="routingChannel"
default-reply-timeout="55550" ></int:gateway>
Was the autowire supposed to look as follows?:
@Autowired
private MyGW toHttp;
or
@Autowired
private MyGW gateway;
I used the former:
Message<?> reply = toHttp.callHttp(inMessage);
I don't think it is picking up the routingChannel however.
The proper solution is to not send to the routing channel directly, but to use a Messaging Gateway and have the
<gateway/>
send to the routing channel.Since you may or may not return a result (depending on the routing), you should set
default-reply-timeout=0
and you'll get null returned from the gateway method in that case.Alternatively, use a
MessagingTemplate
and one of itssendAndReceive()
methods to send to the routing channel - again you will need a reply timeout of zero if you might not get a reply.EDIT:
No, I am suggesting this...
.
And, in
xyzServiceActivator
Or...
or
(with the latter letting the framework taking care of converting to/from messages).