简体   繁体   中英

Configuring Order of JmsListener Execution

If I have more than one @JmsListener method in a Spring Boot application is there a way to explicitly declare either listener to consume all its messages from its queue before the other?

In other words, if I have

@JmsListener(destination = "queueOne") 
    public void processOrder1(String message) {. . .}

@JmsListener(destination = "queueTwo") 
    public void processOrder2(String message) {. . .}

is there configuration available to have processOrder1() run to completion, shut it down, then have processOrder2() run? Or will processOrder2() always execute after processOrder1() (which is what the debugger suggests)? Or are they somehow running separately independent of each other?

If they cannot be configured in such a way I'd like to know why not.

Not with configuration - each listener gets its own independent asynchronous listener container.

You could configure the container factory with autoStartup set to false and start each container programmatically - get a reference to the container from the container registry using the listener's id attribute and start()/stop() it.

One difficulty is how you would "know" that the first one has completed its work.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM