Gateway "replyChannel" confusion
I’m trying to use SI in one of the projects. I did a quick POC which goes as below
- Web Controller calls the Gateway interface method (i.e integration point into the messaging system) with 1 argument and return type HashMap<String, String>
- Gateway pushes the message into the subscribable channel (itemRequest)
- Service Activator is configured as an endpoint which will then kick off the some check (itemServiceImpl). Returns null or itemId. In case of itemId, message is pushed into the outputChannel (cacheEvictRequest)
- Another ServiceActivator is configured to listen @cacheEvictRequest Channel. On receiving the message, item can be flushed. In case of a happy scenario, it will return a HashMap (result=>success)
All works as expected which is good news.
My confusion lies in the replyChannel of the gateway. What is the role/function of replyChannel and how can we use it in this scenario? Just for testing purpose I had added the 'finalChannel' as the replyChannel inside the gateway method. I was expecting the response (HashMap) to be pushed in the finalChannel...but i think i have got it wrong somewhere.
Can someone explain me how replyChannel should be configured?
Code for configuration file
Code:
<int:channel id="itemRequest"/>
<int:channel id="cacheEvictRequest"/>
<int:channel id="finalChannel">
<int:interceptors>
<int:wire-tap channel="logger"/>
</int:interceptors>
</int:channel>
<int:logging-channel-adapter id="logger" level="INFO"/>
<int:gateway id="itemCheckerGateway" service-interface="com.proint.messaging.ItemCheckerGateway" />
<!-- Check item status -->
<int:service-activator input-channel="itemRequest" output-channel="cacheEvictRequest" ref="itemServiceImpl"/>
<!-- Evict cache for this order/item -->
<int:service-activator input-channel="cacheEvictRequest" ref="itemCacheManagerImpl" method="evictCache" />
Gateway
Code:
public interface ItemCheckerGateway {
@Gateway(requestChannel = "itemRequest")
public HashMap<String, Object> checkItem(int itemId);
}
Last ServiceActivator (itemCacheManagerImpl)
Code:
public HashMap<String, Object> evictCache(@Headers Map<String, Object> headerMap, int itemId) {
for(String key : headerMap.keySet()) {
System.out.println("Key [" + key + "] Value [" + headerMap.get(key) + "]");
}
System.out.println("Evict Cache for itemId [" + itemId + "]");
HashMap<String, Object> result = new HashMap<String, Object>();
result.put("result", "success");
result.put("itemId", Integer.valueOf(itemId));
return result;
}
Thanks for your attention.
JP