是否可以创建同步网关

时间:2012-06-06 13:46:28

标签: performance spring-integration

我目前正在通过网关使用弹簧集成通道,并看到一种非常奇怪(且令人讨厌)的行为。邮件在发送后极晚(超过一分钟)处理。

由于通道由其自己的线程池异步处理,我猜这些线程根本就不是活动的。因为发送这些消息非常重要,我想强制在当前线程中同步处理消息。

这可能吗?

我当前的配置:

<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" />

为方便起见,我使用网关,直接访问频道会更好吗?

2 个答案:

答案 0 :(得分:4)

只需删除&lt; queue /&gt;来自outgoingEvents频道的元素,它将全部在调用线程上运行。

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

答案 1 :(得分:0)

如果您得到此答案并且正在使用基于接口的网关。必须使用消息通道。在这种情况下的解决方案是,使用直接通道。以下代码示例演示如何使用java DSL执行此操作。

@Bean(name = "spa.import.zipcodes")
public MessageChannel queueRecordsChannel() {
    return MessageChannels.direct().get();
}

检查此页面以获取有关DirectChannel的更多信息: http://docs.spring.io/spring-integration/reference/html/messaging-channels-section.html