Spring Integration manually start/stop channel adapter via control bus

后端 未结 3 1929
长情又很酷
长情又很酷 2020-12-06 06:59

Is there anyway to manually start/init a channel adapter?

I have two pairs of inbound/outbound adapters in my context.xml and would like to decide at runtime which o

3条回答
  •  挽巷
    挽巷 (楼主)
    2020-12-06 07:23

    Set autoStartup="false" and either directly start()/stop() them, or use a (send @myAdapter.start()).

    Getting a direct reference (autowire etc), depends on the endpoint type. If it's a polled endpoint, inject a SourcePollingChannelAdapter; message-driven adapters vary, but generally are a MessageProducerSupport or MessagingGatewaySupport.

    EDIT:

    Read about the control-bus here.

    Give the inbound adapter an id attribute.

    Add

    Add

    Create a gateway interface

    public interface Controller {
    
        void control(String command);
    
    }
    

    @Autowire the gateway (or use context.getBean(Controller.class)).

    Then, when you are ready to start the adapter, call, e.g. gateway.control("@mqttOut.start()").

    You don't need auto-startup="false" on the outbound adapters.

    However, for a simple use case like this, you might want to investigate using Spring profiles instead (put the adapters in a profile and enable the profile at runtime.

提交回复
热议问题