<> preface

When dealing with some business , We may need to stop monitoring manually . Make the message queue still receive messages , But don't process the message first . Wait until the business processing is completed before you start listening , Processing messages in the queue . So we need to use it here
RabbitListenerEndpointRegistry In start and stop method .

<> Stop all queues
@Autowired private RabbitListenerEndpointRegistry
rabbitListenerEndpointRegistry; public void stopAll() { this.
rabbitListenerEndpointRegistry.stop(); }
This method will stop listening to all queues .

Pay attention to this passage on the official website
When a container is configured to listen to auto-delete queue(s), or the
queue has an x-expires option or the Time-To-Live policy is configured on the
Broker, the queue is removed by the broker when the container is stopped (last
consumer is cancelled). Before version 1.3, the container could not be
restarted because the queue was missing; the RabbitAdmin only automatically
redeclares queues etc, when the connection is closed/opens, which does not
happen when the container is stopped/started.

If the queue is configured with auto-delete Stopping listening will delete the queue , That is, once the queue is stopped , The switch will not be able to find the queue , It's very likely that the message will be lost . stay 1.3 Before version ,
auto-delete The queue cannot be restarted after stopping , Because the queue has been lost ,RabbitAdmin Redeclare the queue only when the connection is open or closed .

<> Stop the specified queue

It's used here rabbitListenerEndpointRegistry.getListenerContainers() method . The source code is as follows :
public Collection<MessageListenerContainer> getListenerContainers() { return
Collections.unmodifiableCollection(this.listenerContainers.values()); }
MessageListenerContainer There are following subclasses

The integration relationship is as follows

AbstractMessageListenerContainer Provides a getQueueNames()
method . Through this method, we can get the queues that the listening container listens to .

The method is as follows :
/** * Determine whether the listener listens to the specified queue . * @param queueName Queue name * @param listenerContainer Monitor container
* @return true- monitor ,false- Not monitored . */ private boolean isQueueListener(String queueName
, MessageListenerContainer listenerContainer) { if (listenerContainer instanceof
AbstractMessageListenerContainer) { AbstractMessageListenerContainer
abstractMessageListenerContainer= (AbstractMessageListenerContainer)
listenerContainer; String[] queueNames = abstractMessageListenerContainer.
getQueueNames(); return ArrayUtils.contains(queueNames, queueName); } return
false; }
Stop the specified queue
public boolean stop(String queueName) { Collection<MessageListenerContainer>
listenerContainers= this.rabbitListenerEndpointRegistry.getListenerContainers();
for (MessageListenerContainer listenerContainer : listenerContainers) { if (this
.isQueueListener(queueName, listenerContainer)) { listenerContainer.stop();
return true; } } return false; }
<> Re enable queues
public void start() { this.rabbitListenerEndpointRegistry.start(); }
You can also get the specified listening , Then call start method , with stop similar .rabbitListenerEndpointRegistry.start()
Will start all listening , Ignore if listening started .

©2019-2020 Toolsou All rights reserved,
It's unexpected Python Cherry tree (turtle The gorgeous style of Library )Unity3D of UGUI Basics -- Three modes of canvas os Simple use of module computer network --- Basic concepts of computer network ( agreement , system )html Writing about cherry trees , Writing about cherry trees Some East 14 Pay change 16 salary , Sincerity or routine ?Unity-Demo Examples ✨ realization UI- Backpack equipment drag function 06【 Interpretation according to the frame 】 Data range filtering -- awesome java Four functional interfaces ( a key , simple )