Announcement Announcement Module
No announcement yet.
Segmenting message flow with service-activator/gateway pattern and void methods Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Segmenting message flow with service-activator/gateway pattern and void methods

    Oleg's recent segmentation presentation offered a alternative to an error being propagated all the way back to the start of the message flow.

    I've encountered an issue and I don't know whether it's my misunderstanding or a bug. If a void method is used in the inbound gateway, and a service-activator/gateway is added to segment the message flow, the call on the void method in the inbound gateway hangs forever. Here's a minimal example:

    <int:gateway service-interface="com.example.Producer" default-request-channel="channelA"/>
    <int:service-activator input-channel="channelA" ref="gateway2"/>
    <int:gateway id="gateway2" default-request-channel="channelB"/>
    <bean id="consumer" class="com.example.Consumer"/>
    <int:service-activator input-channel="channelB"  ref="consumer" method="consume"/>
    package com.example;
    public interface Producer {
        public void produce(int value);
    package com.example;
    public class Consumer {
       public void consume(int value) {
    package com.example;
    import org.springframework.context.ApplicationContext;
    public class Main {
        public static void main(String[] args) {
            ApplicationContext context = new ClassPathXmlApplicationContext("config.xml", Main.class);
            Producer gateway = context.getBean(Producer.class);
    When this code is run "Consume" will be printed but not "Done". It hangs.

    This only happens when using a void method. If the produce() and consume() return types are changed to something other than void it does not hang and "Done" is printed.

    If the service-activator/gateway2 pair are removed and bypassed it works fine.

    If I set a default-reply-timeout on gateway2 it will work, so clearly it is gateway2 that is waiting for a result. It seems like I need a way to tell gateway2 not to expect a reply... but how?

    Any suggestions appreciated, setting the default-reply-timeout on gateway2 seems like a bit of a hack!