一 引入的POM依赖
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>3.6.5</version>
</dependency>
二 声明队列的源码
package com.rabbitmq.client;
public interface Channel extends ShutdownNotifier {
//声明队列
Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete,Map<String, Object> arguments) throws IOException;
}
三 源码中的注释
Declare a queue
Params:
queue – the name of the queue
durable – true if we are declaring a durable queue (the queue will survive a server restart)
exclusive – true if we are declaring an exclusive queue (restricted to this connection)
autoDelete – true if we are declaring an autodelete queue (server will delete it when no longer in use)
arguments – other properties (construction arguments) for the queue
Returns:
a declaration-confirm method to indicate the queue was successfully declared
Throws:
IOException – if an error is encountered
See Also:
AMQP.Queue.Declare, AMQP.Queue.DeclareOk
中文注释:
queue:队列的名称。
durable:队列是否持久化,如果为true,rabbitmq服务重启该队列仍然存在。exclusive:(独占)声明队列同一时间只能保证一个连接,且该队列只有被这一个连接使用。
autoDelete:自动删除的队列,当该队列没有任何的关联时,就会被自动删除。
arguments:扩展参数。
本文介绍了如何在Java中使用RabbitMQ的AMQP客户端库进行队列声明。通过`queueDeclare`方法,可以设置队列的名称、是否持久化、是否独占、是否自动删除以及扩展参数。持久化队列能在服务重启后保留,独占队列限制同一时间仅一个连接使用,自动删除队列在无关联时会被移除,扩展参数则允许自定义更多属性。

533

被折叠的 条评论
为什么被折叠?



