Search code examples
performancespring-integration

Is it possible to create a synchronous Gateway


I'm currently using a spring integration channel through a gateway and see a very strange (and annoying) behaviour. messages are processed extremely late (more than a minute) after they were send.

Since the channel is handled asynchronously by its own thread pool i guess these threads simply aren't active. since sending of these messages is pretty important i would like to force the handling of the message synchronously in the current thread.

is this possible?

My current config:

<int:annotation-config />
<task:executor id="integrationPool" pool-size="0-100" />
<int:poller default="true" task-executor="integrationPool" fixed-rate="50" />

<int:channel id="loggableevents">
    <int:queue />
</int:channel>
<int:channel id="outgoingevents">
    <int:queue />
    <int:interceptors>
        <int:wire-tap channel="loggableevents" />
    </int:interceptors>
</int:channel>

<int:outbound-channel-adapter channel="outgoingevents" method="handleMessage" ref="momadapter" />
<bean id="momadapter" class="my.project.mom.EventSendingMessageHandler" />

<!-- Logging -->
<int:outbound-channel-adapter channel="loggableevents" ref="loggingadapter" method="handleMessage" />
<bean id="loggingadapter" class="my.project.logging.EventLoggingHandler" />

<int:gateway id="eventgateway" service-interface="my.project.mom.EventGateway" default-request-channel="outgoingevents" />

I use the gateway for convenience, would it be better to access the channel directly?


Solution

  • Just remove the <queue/> element from the outgoingEvents channel and it will all run on the calling thread.

    http://static.springsource.org/spring-integration/docs/2.1.2.RELEASE/reference/html/messaging-channels-section.html