Channel 类的方法,如 exchangeDeclare(...)
、queueDeclare(...)
等方法,均采用了重载的方式。
channel.exchangeDeclare(…)
/**
* Declare an exchange, via an interface that allows the complete set of
* arguments.
* @see com.rabbitmq.client.AMQP.Exchange.Declare
* @see com.rabbitmq.client.AMQP.Exchange.DeclareOk
* @param exchange the name of the exchange
* @param type the exchange type
* @param durable true if we are declaring a durable exchange (the exchange will survive a server restart)
* @param autoDelete true if the server should delete the exchange when it is no longer in use
* @param internal true if the exchange is internal, i.e. can't be directly
* published to by a client.
* @param arguments other properties (construction arguments) for the exchange
* @return a declaration-confirm method to indicate the exchange was successfully declared
* @throws java.io.IOException if an error is encountered
*/
Exchange.DeclareOk exchangeDeclare(String exchange,
String type,
boolean durable,
boolean autoDelete,
boolean internal,
Map<String, Object> arguments) throws IOException;
次序 | 名称 | 类型 | 示例 | 解释 |
---|---|---|---|---|
1 | exchange | String | “normalExchange” | 交换器的名称 |
2 | type | String | “direct” | 交换器的类型,可选值有:direct , fanout , topic , headers |
3 | durable | boolean | true | 设置是否持久化。true 持久化。持久化表示可以将交换器存盘,rabbitMQ重启,相关信息不会丢失 |
4 | autoDelete | boolean | false | 设置是否自动删除。true 会自动删除。自动删除的前提是至少有一个队列或交换器与这个交换器绑定,之后所有与这个交换器绑定的队列或交换器都解除。 |
5 | internal | boolean | false | 设置是否是内置的。true 是内置的交换器。客户端无法直接发送消息至这个交换器,只能通过交换器到交换器的这种方式。 |
6 | arguments | Map | null | 其它结构化的一些参数。如制定args.put("alternate-exchange", "myAE"); |
channel.queueDeclare(…)
/**
* Declare a queue
* @see com.rabbitmq.client.AMQP.Queue.Declare
* @see com.rabbitmq.client.AMQP.Queue.DeclareOk
* @param queue the name of the queue
* @param durable true if we are declaring a durable queue (the queue will survive a server restart)
* @param exclusive true if we are declaring an exclusive queue (restricted to this connection)
* @param autoDelete true if we are declaring an autodelete queue (server will delete it when no longer in use)
* @param arguments other properties (construction arguments) for the queue
* @return a declaration-confirm method to indicate the queue was successfully declared
* @throws java.io.IOException if an error is encountered
*/
Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete,
Map<String, Object> arguments) throws IOException;
次序 | 名称 | 类型 | 示例 | 解释 |
---|---|---|---|---|
1 | queue | String | “normalQueue” | 队列的名称 |
2 | durable | boolean | true | 设置是否持久化。true 持久化。RabbitMQ 重启后,队列还会存在,不会丢失。 |
3 | exclusive | boolean | false | 设置是否具有排他性。如果一个队列设置为排他队列,该队列仅对首次声明他的连接可见,并在连接断开时自动删除。这里需要注意三点:排他队列是基于连接( Connection)可见的,同一个连接的不同信道 (Channel)是可以同时访问同一连接创建的排他队列;"首次"是指如果一个连接己经声明了排他队列,其他连接是不允许建立同名的排他队列的,这个与普通队列不同:即使该队列是持久化的,一旦连接关闭或者客户端退出,该排他队列都会被自动删除,这种队列适用于一个客户端同时发送和读取消息的应用场景。 |
4 | autoDelete | boolean | false | 设置是否自动删除。true 自动删除。自动删除的意思是至少有一个消费者连接这个队列,之后与这个队列连接的消费者都断开后,就自动删除该队列。 |
5 | arguments | Map | null | 设置队列的其他一些参数,如 x-message-ttl、x-expires、x-max-length、x-max-length-bytes、 x-dead-letter-exchange、x-dead-letter-routing-key、x-max-priority等。 |
Channel.queueBind(…)
/**
* Bind a queue to an exchange.
* @see com.rabbitmq.client.AMQP.Queue.Bind
* @see com.rabbitmq.client.AMQP.Queue.BindOk
* @param queue the name of the queue
* @param exchange the name of the exchange
* @param routingKey the routing key to use for the binding
* @param arguments other properties (binding parameters)
* @return a binding-confirm method if the binding was successfully created
* @throws java.io.IOException if an error is encountered
*/
Queue.BindOk queueBind(String queue, String exchange, String routingKey, Map<String, Object> arguments) throws IOException;
次序 | 名称 | 类型 | 示例 | 解释 |
---|---|---|---|---|
1 | queue | String | “normalQueue” | 队列名称。 |
2 | exchange | String | “normalExchange” | 交换器名称。 |
3 | routingKey | String | “normal” | 路由键。 |
4 | arguments | Map | null | 自定义绑定的参数。 |
Channel.exchangeBind(…)
/**
* Bind an exchange to an exchange.
* @see com.rabbitmq.client.AMQP.Exchange.Bind
* @see com.rabbitmq.client.AMQP.Exchange.BindOk
* @param destination the name of the exchange to which messages flow across the binding
* @param source the name of the exchange from which messages flow across the binding
* @param routingKey the routing key to use for the binding
* @param arguments other properties (binding parameters)
* @return a binding-confirm method if the binding was successfully created
* @throws java.io.IOException if an error is encountered
*/
Exchange.BindOk exchangeBind(String destination, String source, String routingKey, Map<String, Object> arguments) throws IOException;
次序 | 名称 | 类型 | 示例 | 解释 |
---|---|---|---|---|
1 | destination | String | destination | 需要绑定的目标交换器名称。 |
2 | source | String | source | 需要绑定的交换器名称。 |
3 | routingKey | String | exKey | 路由键。 |
4 | arguments | Map | null | 定义化参数。 |