<> 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,
python Dynamic programming for single source shortest path use VS2019 “Windows Desktop applications ” Module creation Win32 window Conflict statement (conflicting declaration) solve npm ERR! code ELIFECYCLE npm ERR! errno 1 npm ERR! test_vue_0613@1.0.0 dev: Solutions to errors Unity3D Input Key system latex Custom commands in ———\newcommandrk3399_android7.1 debugging USB Summary of Bluetooth module inherit jpa Repository Write custom method query vue vue-element-admin Summary of the project el-select Get selected label value