在Spring Integration中的发布 - 订阅通道上指定ServiceActivator的顺序(使用javaConfig)

时间:2017-04-13 18:28:15

标签: spring annotations spring-integration

我目前正在integration-context.xml文件中指定服务激活器和相关的发布 - 订阅通道。像这样的东西(删节版):

<int:publish-subscribe-channel id="notificationChannel" task-executor="executor" />

<int:gateway service-interface="com.integration.gateway.RestClientGateway" default-request-channel="notificationChannel" async-executor="executor"/>

<int:service-activator ref="restClient" method="sendRequest" **order="1"** input-channel="notificationChannel"/>
<int:service-activator ref="actionPersistor" method="persistNotification" **order="2"** input-channel="notificationChannel"/>

现在我需要指定一个自定义执行器类(用于MDC日志记录),所以我开始尝试将其移动到基于注释的方法。有点像这样:

@Bean
@Description("PubSub channel for notification")
public MessageChannel notificationChannel() {
    return new PublishSubscribeChannel(mdcTaskExecutor());
}

@Bean
public TaskExecutor mdcTaskExecutor() {
    return MDCThreadPoolTaskExecutor.newWithInheritedMdc(10, 20, 25);
}

@MessagingGateway(name = "restClientGateway", defaultRequestChannel = "notificationChannel", asyncExecutor = "mdcExecutor")
public interface RestClientGateway {

    Future<Message<String>> sendRequest(Message<BlEvent> message);
}

@ServiceActivator(inputChannel = "notificationChannel")
public Message<String> sendRequest(Message<BlEvent> message) {

@ServiceActivator(inputChannel="notificationChannel")
public void persistNotification(Message<BlEvent> message) {

我的问题是,如果有任何方法可以指定@ServiceActivators从pub-sub通道接收消息的顺序,类似于我在integration-context.xml中定义消息的方式。

非常感谢你的帮助。如果这样设置属性太简单了,请提前道歉,因为我似乎无法找到它。

1 个答案:

答案 0 :(得分:0)

是的,您只需添加@Order以及这些消息传递注释。

我想我们在参考手册中有遗漏没有提及。

随意就这件事提出JIRA票!

相关问题