Pause & Resume Solace Message consumption from a queue

Options
Ravi
Ravi Member Posts: 12

Hi,

we have requirement, when a particular job is running we need to stop listening to a queue to consume new messages after that job is completed we want to start consuming the messages from Queue.

Using Solace Spring Cloud Stream how we can pause and resume consuming of messages from a queue.

if we have some code snippet to implement this in java will be helpful.

Thank you in advance

Tagged:

Comments

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 923 admin
    edited June 2022 #2
    Options

    Hi @Ravi,

    The Spring Cloud Stream Binder for Solace supports pausing/resuming bindings as defined by the Spring Cloud Stream framework. Can you check this out and see if it will work for you? It allows you to do it programmatically or via actuator.

    https://github.com/SolaceProducts/solace-spring-cloud/tree/master/solace-spring-cloud-starters/solace-spring-cloud-stream-starter#consumer-bindings-pauseresume

  • Ravi
    Ravi Member Posts: 12
    Options

    @marc We are using 3.1.0 version for spring-cloud-starter-stream-solace, we can't see pausing/resuming consumer listener in this version.

    Can you please let us know from which version this capability is available?

    Also to pause or resume we need to get the object of Binding object to perform pause or resume consumer listener right? how can we get the Binding object, to perform pause and resume operations?

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 923 admin
    Options

    Hi @Ravi ,

    Looking at the change log here that functionality was added in v3.3.0.

    As for the binding it looks like you can get the BindingsLifecycleController bean from the application context and then get your bindings from there. Checkout the example in the Spring Cloud Stream reference guide under "Binding Visualization and control" -> "Programmatic way".


    Hope that helps!

  • Ravi
    Ravi Member Posts: 12
    edited June 2022 #5
    Options

    Thanks @marc , after using the v3.3.0, I am able to pause and resume consuming of messages as per my need programmatically as below


    BindingsLifecycleController bindingsController = applicationContext.getBean(BindingsLifecycleController.class);

    Binding binding = bindingsController.queryState("binder-in-0");

    log.info(binding.isPaused()); // false

    bindingsController.changeState("binder-in-0", State.PAUSED);

    log.info(binding.isPaused()); // true

    bindingsController.changeState("binder-in-0", State.RESUMED);

    log.info(binding.isPaused()); //false

  • marc
    marc Member, Administrator, Moderator, Employee Posts: 923 admin
    Options

    Excellent, thank you for sharing that it worked + the code 👏 👍