消息队列,消息通过发送和Exchange之后最终到达的地方,到达Queue的消息及进入了等待消费的状态。每个消息都会被发送到一个或多个队列。
Name: 队列的名称 Durability: 是否需要持久化,true为持久化 Auto Delete: 当最后一个绑定到Exchange上的队列删除后,自动删除该Exchange
服务器和应用程序之间传送的数据
本质上就是一段数据,由Properties和Payload(Body)组成
Delivery Mode: 送达模式 headers:消息的头信息 content_type: 内容的类型 content_encoding: 内容的编码格式 priority: 消息的优先级 correlation_id: 一般用作消息的唯一Id来做 reply_to: 消息失败后可以返回到对应的哪个队列中 expiration: 消息的过期时间 message_id: 消息的Id # 自定义的数据类型 timestamp: 时间戳 type: 类型 user_id: app_id: cluster_id:
ConnectionFactory connectionFactory = new ConnectionFactory(); connectionFactory.setHost("114.67.224.231"); connectionFactory.setUsername("guest"); connectionFactory.setPassword("guest"); connectionFactory.setVirtualHost("/"); Connection connection = connectionFactory.newConnection(); Channel channel = connection.createChannel(); Map<String, Object> headers = new HashMap<>(); headers.put("ocean0","1"); headers.put("ocean1","2"); AMQP.BasicProperties properties = new AMQP.BasicProperties.Builder() .deliveryMode(2)//设置消息是否持久化 2:持久化 1:非持久化 .contentEncoding("UTF-8") .expiration("15000") //过期时间 单位:毫秒 .headers(headers) //headers中保存的是自定义属性 .build(); //通过channel通道来发送消息 String msg = "hello rabbitmq!"; //注意:此时如果不指定交换机名称,则默认走Default AMQP交换机进行路由 channel.basicPublish("","test001",properties,msg.getBytes()); //关闭连接 channel.close(); connection.close();
Message中的Arguments属性说明:
drop-head
或reject-publish
。