Eugene Stepanenkov
Eugene Stepanenkov

Reputation: 936

Spring Integration Control Bus configuration via annotations

Just a simple question: Is there any way to configure Spring Integration Control Bus via annotations (without any xml)

<control-bus input-channel="operationChannel"/>

?

Upvotes: 5

Views: 2967

Answers (2)

Gary Russell
Gary Russell

Reputation: 174719

@Bean
@ServiceActivator(inputChannel = "controlBusChannel")
public ExpressionControlBusFactoryBean controlBus() throws Exception {
    ExpressionControlBusFactoryBean controlBus = new ExpressionControlBusFactoryBean();
    return controlBus;
}

Note that any outputChannel on the annotation will be ignored; it is defined on the bus itself.

Typically the output channel of a control bus is omitted with the result of normal request/reply operations, such as @someBean.isRunning() (if someBean implements Lifecycle for example) going back to the replyChannel header (e.g. to a MessagingTemplate.sendAndReceive() operation or a Messaging Gateway).

If you need to send the control bus operation results some place else, add an output channel to the factory bean.

Any MessageHandler @Bean (or a factory bean that creates one) can now be annotated with @ServiceActivator. See the documentation.

Upvotes: 6

Artem Bilan
Artem Bilan

Reputation: 121542

The Spring Integration Java DSL provides the stuff on the matter:

@Bean
public IntegrationFlow controlBusFlow() {
     return IntegrationFlows.from("operationChannel").controlBus().get();
}

Upvotes: 9

Related Questions