一、queueDeclare(…)
queueDeclare()用于实现通道与队列的绑定。它包含5个参数。
String queue: 被绑定的消息队列名,当该消息队列不存在时,将新建该消息队列
Boolean durable: 是否持久化消息队列, 该参数持久化的仅为队列,而不包含队列中的消息
Boolean exclusive: 该通道是否独占该队列
Boolean autoDelete: 消费完成时是否删除队列, 该删除操作在消费者彻底断开连接之后进行。
Map<String, Object> arguments:其他配置参数
/**
* QueueDeclare实现方法
* @param queue
* @param durable
* @param exclusive
* @param autoDelete
* @param arguments
* @return
* @throws IOException
*/
public com.rabbitmq.client.AMQP.Queue.DeclareOk queueDeclare(String queue, boolean durable, boolean exclusive, boolean autoDelete, Map<String, Object> arguments) throws IOException {
com.rabbitmq.client.AMQP.Queue.DeclareOk ok = this.delegate.queueDeclare(queue, durable, exclusive, autoDelete, arguments);
this.recordQueue(ok, queue, durable, exclusive, autoDelete, arguments);
return ok;
}
二、basicPublish(…)
basicPublish() 方法是基础的发布消息方法,它有四个参数
String exchange : 交换机名, 当不使用交换机时,传入“”空串。
String routingKey :(路由地址) 发布消息的队列, 无论channel绑定那个队列,最终发布消息的队列都有该字串指定
AMQP.BasicProperties props :消息的配置属性,例如 MessageProperties.PERSISTENT_TEXT_PLAIN 表示消息持久化。
byte[] body :消息数据本体, 必须是byte数组
/**
* basicPublish实现
* @param exchange
* @param routingKey
* @param props
* @param body
* @throws IOException
*/
public void basicPublish(String exchange, String routingKey, AMQP.BasicProperties props, byte[] body) throws IOException {
this.basicPublish(exchange, routingKey, false, props, body);
}