Results 1 to 6 of 6

Thread: Looking for a way to stop a DirectChannel

  1. #1
    Join Date
    Sep 2012
    Posts
    9

    Default Looking for a way to stop a DirectChannel

    I am looking for a way to stop a DirectChannel from getting messages
    I am not using any *inbound*, just sending directly to the channel so not possible to use SmartLifecycle.
    I am using Spring Integration 2.1.0.RELEASE and sending Message<String> messages using:
    Code:
    [..]
    notificationChannel.send(message);[..]
    Is there a way to pause/stop/resume the flow?

    EDIT:
    Or is it possible to stop/pause/resume a service activator

    Thanks in advance
    Last edited by artafinde; Oct 23rd, 2012 at 08:39 AM. Reason: alternative solution

  2. #2
    Join Date
    Oct 2005
    Location
    Boston, MA
    Posts
    2,840

    Default

    The first thing that comes to mind is to add a ChannelInterceptor and provide a configurable flag on that so that the preSend() method returns FALSE when the interceptor's flag is in the OFF position.

    However, there might be a way to handle this elsewhere in the flow (upstream or downstream from the channel itself). Can you explain a bit about your flow and the rationale for being able to deactivate it?

    Thanks,
    Mark

  3. #3
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default

    Hi!
    pause/stop/resume the flow
    is equals to
    stop/pause/resume a service activator
    Any message flow starts from consumer(subscriber) on the channel.
    So, you go right way: you should just stop your endpoint (PollingConsumer or EventDrivenConsumer) from it's SmartLifecycle abilities.
    it will be enough to add an 'id' attribute for your <service-activator> and invoke it, e.g. from <control-bus>:
    HTML Code:
    <transformer input-channel="sendStopCommandChannel" output-channel="controlBusChannel"
    				 expression="'@myServiceActivator.stop()'"/>
    However be careful with that, you may end up with this one:
    Code:
    org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers for channel ...
    when you unsubscribe from chennels who implement AbstractSubscribableChannel.

    Hope that help

    Take care,
    Artem

  4. #4
    Join Date
    Sep 2012
    Posts
    9

    Default

    Cleric thanks for your answer, I used something similar combine what you suggested and the examples:
    https://github.com/SpringSource/spri...sDemoTest.java

    I am getting the controlBusChannel and sending a genericMessage to stop the serviceActivater.

    The service activator is connected to

    Code:
    <si:channel id="notificationChannel"/>
    <si:channel id="enrichingChannel"/>
    so I don't think I will have problem with AbstractSubscribableChannel since both are org.springframework.integration.core.MessageChanne l (right?)

    Thanks again

  5. #5
    Join Date
    Jan 2009
    Location
    Ukraine, Kharkov
    Posts
    644

    Default

    (right?)
    No
    <si:channel id="notificationChannel"/>
    <si:channel id="enrichingChannel"/>
    Both are DirectChannel.
    However you're right, I had to say so:
    Be careful around SubscribableChannel implementations!

    Does it work for you now?

  6. #6
    Join Date
    Sep 2012
    Posts
    9

    Default

    Quote Originally Posted by Cleric View Post
    No

    Both are DirectChannel.
    Oops, good to know
    Quote Originally Posted by Cleric View Post
    However you're right, I had to say so:
    Be careful around SubscribableChannel implementations!

    Does it work for you now?
    Yeah seems to be working on some first tests. I will come back if not, thanks!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •