队列的持久化
This commit is contained in:
14
src/main/java/io/jiulinxiri/rabbitmq/three/README.md
Normal file
14
src/main/java/io/jiulinxiri/rabbitmq/three/README.md
Normal file
@@ -0,0 +1,14 @@
|
||||
## 队列的持久化
|
||||
之前我们创建的队列都是非持久化的,rabbitmq 如果重启的化,该队列就会被删除掉,如果
|
||||
要队列实现持久化 需要在声明队列的时候把 durable 参数设置为持久化
|
||||
```java
|
||||
//让消息风列持久化
|
||||
boolean durable=true;
|
||||
channel.queueDeclare (ACK QUEUE NAME, durable, exclusive: false, autoDelete: false, arguments: null);
|
||||
```
|
||||
但是需要注意的就是如果之前声明的队列不是持久化的,需要把原先队列先删除,或者重新
|
||||
创建一个持久化的队列,不然就会出现错误
|
||||
> ITION FAILED inequivalent arg "durable' for queue "task_queue' in vhost "/': received "true 'but current is 'false'
|
||||
|
||||
以下为控制台中持久化与非持久化队列的 UI 显示区、
|
||||

|
@@ -12,7 +12,10 @@ public class Task02 {
|
||||
|
||||
public static void main(String[] args) throws IOException, TimeoutException {
|
||||
Channel channel = RabbitMqUtils.getChannel();
|
||||
channel.queueDeclare(ACK_QUEUE_NAME,false, false,false,null);
|
||||
// 是否进行队列的持久化
|
||||
boolean durable = true;
|
||||
channel.queueDeclare(ACK_QUEUE_NAME,durable, false,false,null);
|
||||
// channel.queueDeclare(ACK_QUEUE_NAME,false, false,false,null);
|
||||
Scanner scanner = new Scanner(System.in);
|
||||
while (scanner.hasNext()) {
|
||||
String message = scanner.next();
|
||||
|
Reference in New Issue
Block a user