Spring Integration manually starts / stops the channel adapter via the control bus

In any case, can I manually start / initialize the channel adapter?

I have two pairs of inbound / outbound adapters in my .xml context and you want to decide at runtime of which one I want to start from.

EDIT:

Specific scenario:
I have a client that can be configured at runtime to be a mqtt publisher or subscriber.
My context.xml is as follows:

<int-mqtt:message-driven-channel-adapter client-id="foo" auto-startup="true" url="tcp://192.168.97.164:1883" topics="testtopic/#" channel="writeToFile" /> <file:outbound-channel-adapter id="writeToFile" auto-startup="true" directory="./test/out" delete-source-files="false"/> <int:transformer id="Transformer" ref="MessageTransformer" input-channel="readFromFile" output-channel="mqttOut" method="bytesFromFile" /> <bean id="MessageTransformer" class="MessageTransformer"/> <int-mqtt:outbound-channel-adapter id="mqttOut" client-id="foo" url="tcp://192.168.97.164:1883" auto-startup="false" default-qos="1" default-retained="true" default-topic="testtopic/bla" /> <file:inbound-channel-adapter auto-startup="false" id="readFromFile" directory="./test/in" filename-pattern="myFile*"> <int:poller id="poller" fixed-rate="5000" /> </file:inbound-channel-adapter> 


As you can see, I have two settings:
1. Subscriber question: Reading a mqtt message β†’ Writing to a file
2. The case of the publisher: polling a file from a directory β†’ Send via mqtt

At runtime, I decide which setting should be applied.

So, can you kindly tell me how this thing with a control spike fits right here?

+7
java spring spring-integration
source share
3 answers

Set autoStartup="false" and either directly start() / stop() , or use <control-bus/> (send @myAdapter.start() ).

Getting a direct link (autowire, etc.) depends on the type of endpoint. If this is the polled endpoint, enter a SourcePollingChannelAdapter ; message-driven adapters vary, but usually MessageProducerSupport or MessagingGatewaySupport .

EDIT:

Read 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 gateway (or use context.getBean(Controller.class) ).

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

You do not need auto-startup="false" for outgoing adapters.

However, for a simple use case, you may need to explore using Spring profiles instead (put the adapters in the profile and enable the profile at run time.

+14
source share

To do this, you first need to set the autostart property of the adapter channel to false auto-startup="false" , and then use the control panel to start / stop the adapter

See here an example of a control bus - https://github.com/spring-projects/spring-integration-samples/tree/master/basic/control-bus

+3
source share

I searched the same example using spring Java DSL integration, but didn’t find anything, so I created my own. It shows that it is quite easy to configure.

 @Bean public IntegrationFlow controlBus() { return IntegrationFlows.from(controlChannel()) .controlBus() .get(); } @Bean public MessageChannel controlChannel() { return MessageChannels.direct().get(); } 

To stop him:

controlChannel.send(new GenericMessage<>("@myInboundAdapter.stop()"));

https://github.com/CauchyPeano/sftp-poller-control-bus

0
source share

All Articles