How can I Stop/start/Pause a @JmsListener (the clean way)

后端 未结 3 1603
忘了有多久
忘了有多久 2020-12-09 12:22

I am using Spring(boot) on my project and I access a JMS Queue (ActiveMQ) using :

@JmsListener(destination = \"mydestinationQueue\")
public void processMessa         


        
相关标签:
3条回答
  • 2020-12-09 12:51
       private void stopJMSListener() {
           if(null == customRegistry){
               customRegistry = context.getBean(JmsListenerEndpointRegistry.class);
           }
            customRegistry.stop();
        }
    
       private void startJMSListener() {
           if(null == customRegistry){
            JmsListenerEndpointRegistry customRegistry = context.getBean(JmsListenerEndpointRegistry.class);
           }
            customRegistry.start();
        }
    
    0 讨论(0)
  • 2020-12-09 12:52

    There's a bean of type JmsListenerEndpointRegistry (name org.springframework.jms.config.internalJmsListenerEndpointRegistry).

    You can access the JMS listener containers from the registry (all or by name) and call stop() on the one(s) you want; the container will stop after any in-process messages complete their processing.

    0 讨论(0)
  • 2020-12-09 13:13

    Here is the solution I've found

    @RestController
    @RequestMapping("/jms")
    public class JmsController {
    
         @Autowired
         ApplicationContext context;
    
    @RequestMapping(value="/halt", method= RequestMethod.GET)
    public @ResponseBody
    String haltJmsListener() {
        JmsListenerEndpointRegistry customRegistry =
                context.getBean("jmsRegistry", JmsListenerEndpointRegistry.class);
        customRegistry.stop();
        return "Jms Listener Stopped";
    }
    
    @RequestMapping(value="/restart", method=RequestMethod.GET)
    public @ResponseBody
    String reStartJmsListener() {
        JmsListenerEndpointRegistry customRegistry =
                context.getBean("jmsRegistry", JmsListenerEndpointRegistry.class);
        customRegistry.start();
        return "Jms Listener restarted";
    }
    
    @RequestMapping(value="/stopApp", method=RequestMethod.GET)
    public @ResponseBody
    String stopApp() {
        String[] args={};
        SpringApplication.run(FacturationApplicationFrontDaemon.class, args).close();
        return "stopped";
    }
    
    }
    
    0 讨论(0)
提交回复
热议问题