Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

?

like image 585
Eugene Stepanenkov Avatar asked Jan 08 '15 20:01

Eugene Stepanenkov


2 Answers

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

@Bean
public IntegrationFlow controlBusFlow() {
     return IntegrationFlows.from("operationChannel").controlBus().get();
}
like image 174
Artem Bilan Avatar answered Nov 13 '22 05:11

Artem Bilan


@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.

like image 26
Gary Russell Avatar answered Nov 13 '22 04:11

Gary Russell