Massage 消息
它是服务器和应用程序间传输的数据,我们在前面的样例代码种可以看到发送消息的样例;Channel.basicPublish 方法,它有几个重载方法
-
void basicPublish
(String exchange , String routingKey, BasicProperties props ,byte[) body) throws IOException ; -
void basicPublish
(String exchange , String routingKey, boolean mandatory, BasicProperties props ,byte[) body) throws IOException ; -
void basicPublish
(String exchange , String routingKey, boolean mandatory, boolean immediate, BasicProperties props ,byte[] body) throws IOException ;
具体参数详细介绍如下:
exchange
:交换器的名称
,指明消息需要发送到哪个交换器中,如果设置为空,则默认发送到RabbitMQ 默认的交换器中routingKey
:路由键
mandatory
:当mandatory 参数设为true
时,交换器无法根据自身的类型和路由键找到一个符合条件的队列,那么RabbitMQ 会调用Basic.Return 命令将消息返回给生产者
。当mandatory参数设置为false 时,出现上述情形,则消息直接被丢弃.immediate
:当imrnediate参数设为true
时,类似UDP, 如果交换器在将消息路由到队列时发现队列上并不存在任何消费者,那么这条消息将不会存入队列中。当与路由键匹配的所有队列都没有消费者时,该消息会通过Basic.Return返回至生产者
props :消息的基本属性集,分别有
- contentType (消息类型)
- contentEncoding (消息编码)
- headers( Map<String ,Object>) (自定义的一些消息数据)
- deliveryMode (消息是否持久化 = 2)
- priority (消息优先级)
- correlationld (可以理解为消息的唯一ID)
- replyTo (消息重回队列)
- expiration (过期时间)
- messageld
- timestamp
- type
- userld
- appld
- clusterld