4.basicPublish方法的详解

1.简介

basicPublish方法主要是对消息进行一些设置,主要讲basicproperties的相关内容

2.详解

参考官方文档link
4.basicPublish方法的详解_第1张图片
其总共有14个参数:

private String contentType; // 消息的内容类型
private String contentEncoding; // 消息内容的编码
private Map<String, Object> headers; // 消息的头
private Integer deliveryMode; // 消息是否持久化,1为否,2为是
private Integer priority; // 消息的优先级
private String correlationId; // 关联id
private String replyTo; // 消息回复的队列名称
private String expiration; // 消息的有效时间
private String messageId; // 消息的id
private Date timestamp; // 消息的时间戳
private String type; // 类型
private String userId; // 用户id
private String appId; // 应用id
private String clusterId; // 集群id

3.MessageProperties

MessageProperties对一些常用的进行了设置,共有6个

    public static final BasicProperties MINIMAL_BASIC = new BasicProperties((String)null, (String)null, (Map)null, (Integer)null, (Integer)null, (String)null, (String)null, (String)null, (String)null, (Date)null, (String)null, (String)null, (String)null, (String)null);
    public static final BasicProperties MINIMAL_PERSISTENT_BASIC = new BasicProperties((String)null, (String)null, (Map)null, 2, (Integer)null, (String)null, (String)null, (String)null, (String)null, (Date)null, (String)null, (String)null, (String)null, (String)null);
    public static final BasicProperties BASIC = new BasicProperties("application/octet-stream", (String)null, (Map)null, 1, 0, (String)null, (String)null, (String)null, (String)null, (Date)null, (String)null, (String)null, (String)null, (String)null);
    public static final BasicProperties PERSISTENT_BASIC = new BasicProperties("application/octet-stream", (String)null, (Map)null, 2, 0, (String)null, (String)null, (String)null, (String)null, (Date)null, (String)null, (String)null, (String)null, (String)null);
    public static final BasicProperties TEXT_PLAIN = new BasicProperties("text/plain", (String)null, (Map)null, 1, 0, (String)null, (String)null, (String)null, (String)null, (Date)null, (String)null, (String)null, (String)null, (String)null);
    public static final BasicProperties PERSISTENT_TEXT_PLAIN = new BasicProperties("text/plain", (String)null, (Map)null, 2, 0, (String)null, (String)null, (String)null, (String)null, (Date)null, (String)null, (String)null, (String)null, (String)null);
  • MINIMAL_BASIC:默认设置,什么参数都没有设置
  • MINIMAL_PERSISTENT_BASIC:仅仅设置 deliveryMode为2
  • BASIC :内容类型为以流的方式, deliveryMode为1, 优先级为0
  • PERSISTENT_BASIC :内容类型为以流的方式, deliveryMode为2, 优先级为0
  • TEXT_PLAIN :内容类型为以文本的方式, deliveryMode 为1, 优先级为0
  • PERSISTENT_TEXT_PLAIN :内容类型为以文本的方式, deliveryMode 为2, 优先级为0

你可能感兴趣的:(rabbitmq,java,rabbitmq)