Spring Integration Control Bus configuration via annotations

删除回忆录丶 提交于 2019-11-30 05:35:09

问题


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

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

?


回答1:


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




回答2:


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

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


来源:https://stackoverflow.com/questions/27849211/spring-integration-control-bus-configuration-via-annotations

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!