org.apache.rocketmq.common.message.Message.putUserProperty()方法的使用及代码示例

x33g5p2x  于2022-01-25 转载在 其他  
字(9.1k)|赞(0)|评价(0)|浏览(212)

本文整理了Java中org.apache.rocketmq.common.message.Message.putUserProperty()方法的一些代码示例,展示了Message.putUserProperty()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.putUserProperty()方法的具体详情如下:
包路径:org.apache.rocketmq.common.message.Message
类名称:Message
方法名:putUserProperty

Message.putUserProperty介绍

暂无

代码示例

代码示例来源:origin: apache/rocketmq

String prop1 = "prop" + i, prop1V = "hello" + startValue;
String prop2 = "prop" + (i + 1), prop2V = String.valueOf(startValue);
msg.putUserProperty(prop1, prop1V);
msg.putUserProperty(prop2, prop2V);
size += prop1.length() + prop2.length() + prop1V.length() + prop2V.length();
if (size > propertySize) {

代码示例来源:origin: apache/rocketmq-externals

rocketmqMsg.setBuyerId(value);
} else {
  rocketmqMsg.putUserProperty(name, value);

代码示例来源:origin: spring-cloud-incubator/spring-cloud-alibaba

for (Map.Entry<String, String> entry : headerAccessor.getUserProperties()
    .entrySet()) {
  toSend.putUserProperty(entry.getKey(), entry.getValue());

代码示例来源:origin: apache/rocketmq

public static org.apache.rocketmq.common.message.Message msgConvert(BytesMessage omsMessage) {
  org.apache.rocketmq.common.message.Message rmqMessage = new org.apache.rocketmq.common.message.Message();
  rmqMessage.setBody(omsMessage.getBody(byte[].class));
  KeyValue sysHeaders = omsMessage.sysHeaders();
  KeyValue userHeaders = omsMessage.userHeaders();
  //All destinations in RocketMQ use Topic
  rmqMessage.setTopic(sysHeaders.getString(BuiltinKeys.DESTINATION));
  if (sysHeaders.containsKey(BuiltinKeys.START_TIME)) {
    long deliverTime = sysHeaders.getLong(BuiltinKeys.START_TIME, 0);
    if (deliverTime > 0) {
      rmqMessage.putUserProperty(RocketMQConstants.START_DELIVER_TIME, String.valueOf(deliverTime));
    }
  }
  for (String key : userHeaders.keySet()) {
    MessageAccessor.putProperty(rmqMessage, key, userHeaders.getString(key));
  }
  //System headers has a high priority
  for (String key : sysHeaders.keySet()) {
    MessageAccessor.putProperty(rmqMessage, key, sysHeaders.getString(key));
  }
  return rmqMessage;
}

代码示例来源:origin: apache/rocketmq

/**
   * @since version3.4.6
   */
  @Test
  public void testSendChinaUserProp() {
    Message msg = MessageFactory.getRandomMessage(topic);
    String msgKey = "jueyinKey";
    String msgValue = "jueyinzhi";
    msg.putUserProperty(msgKey, msgValue);

    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListener());

    producer.send(msg, null);
    assertThat(producer.getAllMsgBody().size()).isEqualTo(1);

    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    Message sendMsg = (Message) producer.getFirstMsg();
    Message recvMsg = (Message) consumer.getListener().getFirstMsg();
    assertThat(recvMsg.getUserProperty(msgKey)).isEqualTo(sendMsg.getUserProperty(msgKey));
  }
}

代码示例来源:origin: apache/rocketmq

/**
 * @since version3.4.6
 */
@Test
public void testSendEnglishUserProp() {
  Message msg = MessageFactory.getRandomMessage(topic);
  String msgKey = "jueyinKey";
  String msgValue = "jueyinValue";
  msg.putUserProperty(msgKey, msgValue);
  RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListener());
  producer.send(msg, null);
  assertThat(producer.getAllMsgBody().size()).isEqualTo(1);
  consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
  Message sendMsg = (Message) producer.getFirstMsg();
  Message recvMsg = (Message) consumer.getListener().getFirstMsg();
  assertThat(recvMsg.getUserProperty(msgKey)).isEqualTo(sendMsg.getUserProperty(msgKey));
}

代码示例来源:origin: apache/rocketmq

try {
  if (sendResult.getTransactionId() != null) {
    msg.putUserProperty("__transactionId__", sendResult.getTransactionId());

代码示例来源:origin: didi/DDMQ

public static void main(String[] args) throws MQClientException, InterruptedException {
    DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
    producer.start();

    try {
      for (int i = 0; i < 6000000; i++) {
        Message msg = new Message("TopicFilter7",
          "TagA",
          "OrderID001",
          "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));

        msg.putUserProperty("SequenceId", String.valueOf(i));
        SendResult sendResult = producer.send(msg);
        System.out.printf("%s%n", sendResult);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    producer.shutdown();
  }
}

代码示例来源:origin: javahongxi/whatsmars

&& !Objects.equals(entry.getKey(), "WAIT_STORE_MSG_OK")) // exclude "KEYS", "FLAG", "WAIT_STORE_MSG_OK"
.forEach(entry -> {
  rocketMsg.putUserProperty("USERS_" + entry.getKey(), String.valueOf(entry.getValue())); // add other properties with prefix "USERS_"
});

代码示例来源:origin: didi/DDMQ

("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET)
);
msg.putUserProperty("a", String.valueOf(i));

代码示例来源:origin: didi/DDMQ

String prop1 = "prop" + i, prop1V = "hello" + startValue;
String prop2 = "prop" + (i + 1), prop2V = String.valueOf(startValue);
msg.putUserProperty(prop1, prop1V);
msg.putUserProperty(prop2, prop2V);
size += prop1.length() + prop2.length() + prop1V.length() + prop2V.length();
if (size > propertySize) {

代码示例来源:origin: didi/DDMQ

/**
 * @since version3.4.6
 */
@Test(expected = org.apache.rocketmq.client.exception.MQBrokerException.class)
public void testSend20kChinaPropMsg() throws Exception {
  Message msg = MessageFactory.getRandomMessage(topic);
  msg.putUserProperty("key", RandomUtils.getCheseWord(32 * 1024 + 1));
  producer.send(msg);
}

代码示例来源:origin: didi/DDMQ

public static org.apache.rocketmq.common.message.Message msgConvert(BytesMessage omsMessage) {
  org.apache.rocketmq.common.message.Message rmqMessage = new org.apache.rocketmq.common.message.Message();
  rmqMessage.setBody(omsMessage.getBody());
  KeyValue headers = omsMessage.headers();
  KeyValue properties = omsMessage.properties();
  //All destinations in RocketMQ use Topic
  if (headers.containsKey(MessageHeader.TOPIC)) {
    rmqMessage.setTopic(headers.getString(MessageHeader.TOPIC));
    rmqMessage.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "TOPIC");
  } else {
    rmqMessage.setTopic(headers.getString(MessageHeader.QUEUE));
    rmqMessage.putUserProperty(NonStandardKeys.MESSAGE_DESTINATION, "QUEUE");
  }
  for (String key : properties.keySet()) {
    MessageAccessor.putProperty(rmqMessage, key, properties.getString(key));
  }
  //Headers has a high priority
  for (String key : headers.keySet()) {
    MessageAccessor.putProperty(rmqMessage, key, headers.getString(key));
  }
  return rmqMessage;
}

代码示例来源:origin: didi/DDMQ

@Test
  public void testSendMsgWithUserProperty() {
    Message msg = MessageFactory.getRandomMessage(topic);
    msg.putUserProperty("key", RandomUtils.getCheseWord(10 * 1024));
    SendResult sendResult = null;
    try {
      sendResult = producer.send(msg);
    } catch (Exception e) {
    }
    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
  }
}

代码示例来源:origin: didi/DDMQ

/**
   * @since version3.4.6
   */
  @Test
  public void testSend10kChinaPropMsg() {

    Message msg = MessageFactory.getRandomMessage(topic);
    msg.putUserProperty("key", RandomUtils.getCheseWord(10 * 1024));
    SendResult sendResult = null;
    try {
      sendResult = producer.send(msg);
    } catch (Exception e) {
    }
    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
  }
}

代码示例来源:origin: didi/DDMQ

try {
  if (sendResult.getTransactionId() != null) {
    msg.putUserProperty("__transactionId__", sendResult.getTransactionId());

代码示例来源:origin: didi/DDMQ

/**
 * @since version3.4.6
 */
@Test
public void testSendEnglishUserProp() {
  Message msg = MessageFactory.getRandomMessage(topic);
  String msgKey = "jueyinKey";
  String msgValue = "jueyinValue";
  msg.putUserProperty(msgKey, msgValue);
  RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListener());
  producer.send(msg, null);
  assertThat(producer.getAllMsgBody().size()).isEqualTo(1);
  consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);
  Message sendMsg = (Message) producer.getFirstMsg();
  Message recvMsg = (Message) consumer.getListener().getFirstMsg();
  assertThat(recvMsg.getUserProperty(msgKey)).isEqualTo(sendMsg.getUserProperty(msgKey));
}

代码示例来源:origin: didi/DDMQ

/**
   * @since version3.4.6
   */
  @Test
  public void testSendChinaUserProp() {
    Message msg = MessageFactory.getRandomMessage(topic);
    String msgKey = "jueyinKey";
    String msgValue = "jueyinzhi";
    msg.putUserProperty(msgKey, msgValue);

    RMQNormalConsumer consumer = getConsumer(nsAddr, topic, "*", new RMQNormalListener());

    producer.send(msg, null);
    assertThat(producer.getAllMsgBody().size()).isEqualTo(1);

    consumer.getListener().waitForMessageConsume(producer.getAllMsgBody(), consumeTime);

    Message sendMsg = (Message) producer.getFirstMsg();
    Message recvMsg = (Message) consumer.getListener().getFirstMsg();
    assertThat(recvMsg.getUserProperty(msgKey)).isEqualTo(sendMsg.getUserProperty(msgKey));
  }
}

代码示例来源:origin: jiangxinlingdu/rocketmq-all-4.1.0-incubating

/**
 * @since version3.4.6
 */
@Test(expected = org.apache.rocketmq.client.exception.MQBrokerException.class)
public void testSend20kChinaPropMsg() throws Exception {
  Message msg = MessageFactory.getRandomMessage(topic);
  msg.putUserProperty("key", RandomUtils.getCheseWord(32 * 1024 + 1));
  producer.send(msg);
}

代码示例来源:origin: jiangxinlingdu/rocketmq-all-4.1.0-incubating

@Test
  public void testSendMsgWithUserProperty() {
    Message msg = MessageFactory.getRandomMessage(topic);
    msg.putUserProperty("key", RandomUtils.getCheseWord(10 * 1024));
    SendResult sendResult = null;
    try {
      sendResult = producer.send(msg);
    } catch (Exception e) {
    }
    assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
  }
}

相关文章