4
votes

I'm currently specifying a service-activator and related publish-subscribe channel in an integration-context.xml file. Something like this (abridged version):

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

Now I need to specify a custom executor class (for MDC logging), so I started playing around with moving this to an annotation based approach. Something along the lines of this :

@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) {

My question is, if there's any way to specify the ordering in which the @ServiceActivators receive a message from the pub-sub channel, similar to the way I could define it in the integration-context.xml.

Thanks much for your help. And apologies in advance if this was way too simple as setting a property, coz I couldn't seem to locate it.

1
You can do this using @Order annotation. Example: self-learning-java-tutorial.blogspot.com/2021/05/…Hari Krishna

1 Answers

1
votes

Yes, you can simply add @Order alongside with those Messaging annotations.

I guess we have an omission in the Reference Manual do not mention that.

Feel free to raise a JIRA ticket on the matter!