Set autoStartup="false"
and either directly start()
/stop()
them, or use a <control-bus/>
(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 <control-bus input-channel="control"/>
Add <int:gateway service-interface="foo.Controller" default-request-channel="control"/>
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.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…