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

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

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

Message.setDelayTimeLevel介绍

暂无

代码示例

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

rocketmqMsg.setTags(value);
} else if (MessageConst.PROPERTY_DELAY_TIME_LEVEL.equals(name)) {
  rocketmqMsg.setDelayTimeLevel(Integer.parseInt(value));
} else if (MessageConst.PROPERTY_WAIT_STORE_MSG_OK.equals(name)) {
  rocketmqMsg.setWaitStoreMsgOK(Boolean.parseBoolean(value));

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

message);
headerAccessor.setLeaveMutable(true);
toSend.setDelayTimeLevel(headerAccessor.getDelayTimeLevel());
toSend.setTags(headerAccessor.getTags());
toSend.setKeys(headerAccessor.getKeys());

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

public boolean sendMessageBack(final MessageExt msg) {
  try {
    // max reconsume times exceeded then send to dead letter queue.
    Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()), msg.getBody());
    String originMsgId = MessageAccessor.getOriginMessageId(msg);
    MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    newMsg.setFlag(msg.getFlag());
    MessageAccessor.setProperties(newMsg, msg.getProperties());
    MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
    MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes()));
    MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(getMaxReconsumeTimes()));
    newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    this.defaultMQPushConsumer.getDefaultMQPushConsumerImpl().getmQClientFactory().getDefaultMQProducer().send(newMsg);
    return true;
  } catch (Exception e) {
    log.error("sendMessageBack exception, group: " + this.consumerGroup + " msg: " + msg.toString(), e);
  }
  return false;
}

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

public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName)
  throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
  try {
    String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
      : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
    this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg,
      this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000, getMaxReconsumeTimes());
  } catch (Exception e) {
    log.error("sendMessageBack Exception, " + this.defaultMQPushConsumer.getConsumerGroup(), e);
    Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()), msg.getBody());
    String originMsgId = MessageAccessor.getOriginMessageId(msg);
    MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    newMsg.setFlag(msg.getFlag());
    MessageAccessor.setProperties(newMsg, msg.getProperties());
    MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
    MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes() + 1));
    MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(getMaxReconsumeTimes()));
    newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    this.mQClientFactory.getDefaultMQProducer().send(newMsg);
  }
}

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

public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName, String consumerGroup)
  throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
  try {
    String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
      : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
    if (UtilAll.isBlank(consumerGroup)) {
      consumerGroup = this.defaultMQPullConsumer.getConsumerGroup();
    }
    this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg, consumerGroup, delayLevel, 3000,
      this.defaultMQPullConsumer.getMaxReconsumeTimes());
  } catch (Exception e) {
    log.error("sendMessageBack Exception, " + this.defaultMQPullConsumer.getConsumerGroup(), e);
    Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPullConsumer.getConsumerGroup()), msg.getBody());
    String originMsgId = MessageAccessor.getOriginMessageId(msg);
    MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    newMsg.setFlag(msg.getFlag());
    MessageAccessor.setProperties(newMsg, msg.getProperties());
    MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
    MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes() + 1));
    MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(this.defaultMQPullConsumer.getMaxReconsumeTimes()));
    newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    this.mQClientFactory.getDefaultMQProducer().send(newMsg);
  }
}

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

public static List<Object> getDelayMsg(String topic, int delayLevel, int msgSize) {
  List<Object> msgs = new ArrayList<Object>();
  for (int i = 0; i < msgSize; i++) {
    Message msg = new Message(topic, RandomUtil.getStringByUUID().getBytes());
    msg.setDelayTimeLevel(delayLevel);
    msgs.add(msg);
  }
  return msgs;
}

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

/**
 * Send delayed message.
 *
 * @param destination formats: `topicName:tags`
 * @param message     {@link org.springframework.messaging.Message}
 * @param timeout     send timeout with millis
 * @param delayLevel  level for the delay message {@link MessageDelayLevel}
 * @return {@link SendResult}
 */
public SendResult sendDelayed(String destination, Message<?> message, long timeout, MessageDelayLevel delayLevel) {
  if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
    log.error("sendDelayed failed. destination:{}, message is null ", destination);
    throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
  }
  try {
    long now = System.currentTimeMillis();
    org.apache.rocketmq.common.message.Message rocketMsg = convertToRocketMsg(destination, message);
    if (delayLevel.level > 0) {
      rocketMsg.setDelayTimeLevel(delayLevel.level);
    }
    SendResult sendResult = producer.send(rocketMsg, timeout);
    long costTime = System.currentTimeMillis() - now;
    log.debug("send message cost: {} ms, msgId:{}", costTime, sendResult.getMsgId());
    return sendResult;
  } catch (Exception e) {
    log.error("sendDelayed failed. destination:{}, message:{} ", destination, message);
    throw new MessagingException(e.getMessage(), e);
  }
}

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

public boolean sendMessageBack(final MessageExt msg) {
  try {
    if (MixAll.MQTT_MODE) {
      log.error("send MessageBack in MQTT MODE is illegal, msg={}", msg);
      return false;
    }
    // max reconsume times exceeded then send to dead letter queue.
    Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()), msg.getBody());
    String originMsgId = MessageAccessor.getOriginMessageId(msg);
    MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    newMsg.setFlag(msg.getFlag());
    MessageAccessor.setProperties(newMsg, msg.getProperties());
    MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
    MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes()));
    MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(getMaxReconsumeTimes()));
    newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    this.defaultMQPushConsumer.getDefaultMQPushConsumerImpl().getmQClientFactory().getDefaultMQProducer().send(newMsg);
    return true;
  } catch (Exception e) {
    log.error("sendMessageBack exception, group: " + this.consumerGroup + " msg: " + msg.toString(), e);
  }
  return false;
}

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

public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName)
  throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
  if (MixAll.MQTT_MODE) {
    log.error("send MessageBack in MQTT MODE is illegal, msg={}, brokerName={}", msg, brokerName);
    return;
  }
  try {
    String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
      : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
    this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg,
      this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000, getMaxReconsumeTimes());
  } catch (Exception e) {
    log.error("sendMessageBack Exception, " + this.defaultMQPushConsumer.getConsumerGroup(), e);
    Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()), msg.getBody());
    String originMsgId = MessageAccessor.getOriginMessageId(msg);
    MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    newMsg.setFlag(msg.getFlag());
    MessageAccessor.setProperties(newMsg, msg.getProperties());
    MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
    MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes() + 1));
    MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(getMaxReconsumeTimes()));
    newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    this.mQClientFactory.getDefaultMQProducer().send(newMsg);
  }
}

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

public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName, String consumerGroup)
  throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
  try {
    String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
      : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
    if (UtilAll.isBlank(consumerGroup)) {
      consumerGroup = this.defaultMQPullConsumer.getConsumerGroup();
    }
    this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg, consumerGroup, delayLevel, 3000,
      this.defaultMQPullConsumer.getMaxReconsumeTimes());
  } catch (Exception e) {
    log.error("sendMessageBack Exception, " + this.defaultMQPullConsumer.getConsumerGroup(), e);
    Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPullConsumer.getConsumerGroup()), msg.getBody());
    String originMsgId = MessageAccessor.getOriginMessageId(msg);
    MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    newMsg.setFlag(msg.getFlag());
    MessageAccessor.setProperties(newMsg, msg.getProperties());
    MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
    MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes() + 1));
    MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(this.defaultMQPullConsumer.getMaxReconsumeTimes()));
    newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    this.mQClientFactory.getDefaultMQProducer().send(newMsg);
  }
}

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

public static List<Object> getDelayMsg(String topic, int delayLevel, int msgSize) {
  List<Object> msgs = new ArrayList<Object>();
  for (int i = 0; i < msgSize; i++) {
    Message msg = new Message(topic, RandomUtil.getStringByUUID().getBytes());
    msg.setDelayTimeLevel(delayLevel);
    msgs.add(msg);
  }
  return msgs;
}

代码示例来源:origin: org.apache.rocketmq/rocketmq-spring-boot

/**
 * Same to {@link #syncSend(String, Message)} with send timeout specified in addition.
 *
 * @param destination formats: `topicName:tags`
 * @param message     {@link org.springframework.messaging.Message}
 * @param timeout     send timeout with millis
 * @param delayLevel  level for the delay message
 * @return {@link SendResult}
 */
public SendResult syncSend(String destination, Message<?> message, long timeout, int delayLevel) {
  if (Objects.isNull(message) || Objects.isNull(message.getPayload())) {
    log.error("syncSend failed. destination:{}, message is null ", destination);
    throw new IllegalArgumentException("`message` and `message.payload` cannot be null");
  }
  try {
    long now = System.currentTimeMillis();
    org.apache.rocketmq.common.message.Message rocketMsg = RocketMQUtil.convertToRocketMessage(objectMapper,
      charset, destination, message);
    if (delayLevel > 0) {
      rocketMsg.setDelayTimeLevel(delayLevel);
    }
    SendResult sendResult = producer.send(rocketMsg, timeout);
    long costTime = System.currentTimeMillis() - now;
    log.debug("send message cost: {} ms, msgId:{}", costTime, sendResult.getMsgId());
    return sendResult;
  } catch (Exception e) {
    log.error("syncSend failed. destination:{}, message:{} ", destination, message);
    throw new MessagingException(e.getMessage(), e);
  }
}

代码示例来源:origin: maihaoche/rocketmq-spring-boot-starter

message.setDelayTimeLevel(delayTimeLevel);

代码示例来源:origin: sohutv/sohu-tv-mq

/**
 * 构建消息
 * @param messageObject 消息
 * @param tags tags
 * @param keys key
 * @param delayLevel 延时级别
 * @return
 */
public Message buildMessage(Object messageObject, String tags, String keys, MessageDelayLevel delayLevel) {
  byte[] bytes = getMessageSerializer().serialize(messageObject);
  Message message = new Message(topic, tags, keys, bytes);
  if (delayLevel != null) {
    message.setDelayTimeLevel(delayLevel.getLevel());
  }
  return message;
}

代码示例来源:origin: org.springframework.cloud/spring-cloud-stream-binder-rocketmq

message);
headerAccessor.setLeaveMutable(true);
toSend.setDelayTimeLevel(headerAccessor.getDelayTimeLevel());
toSend.setTags(headerAccessor.getTags());
toSend.setKeys(headerAccessor.getKeys());

代码示例来源:origin: ww20081120/framework

msg.setDelayTimeLevel(RocketmqFactory.calculationLevel(delayTime));

代码示例来源:origin: org.apache.rocketmq/rocketmq-client

public boolean sendMessageBack(final MessageExt msg) {
  try {
    // max reconsume times exceeded then send to dead letter queue.
    Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()), msg.getBody());
    String originMsgId = MessageAccessor.getOriginMessageId(msg);
    MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    newMsg.setFlag(msg.getFlag());
    MessageAccessor.setProperties(newMsg, msg.getProperties());
    MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
    MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes()));
    MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(getMaxReconsumeTimes()));
    newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    this.defaultMQPushConsumer.getDefaultMQPushConsumerImpl().getmQClientFactory().getDefaultMQProducer().send(newMsg);
    return true;
  } catch (Exception e) {
    log.error("sendMessageBack exception, group: " + this.consumerGroup + " msg: " + msg.toString(), e);
  }
  return false;
}

代码示例来源:origin: org.apache.rocketmq/rocketmq-client

public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName)
  throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
  try {
    String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
      : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
    this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg,
      this.defaultMQPushConsumer.getConsumerGroup(), delayLevel, 5000, getMaxReconsumeTimes());
  } catch (Exception e) {
    log.error("sendMessageBack Exception, " + this.defaultMQPushConsumer.getConsumerGroup(), e);
    Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPushConsumer.getConsumerGroup()), msg.getBody());
    String originMsgId = MessageAccessor.getOriginMessageId(msg);
    MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    newMsg.setFlag(msg.getFlag());
    MessageAccessor.setProperties(newMsg, msg.getProperties());
    MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
    MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes() + 1));
    MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(getMaxReconsumeTimes()));
    newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    this.mQClientFactory.getDefaultMQProducer().send(newMsg);
  }
}

代码示例来源:origin: org.apache.rocketmq/rocketmq-client

public void sendMessageBack(MessageExt msg, int delayLevel, final String brokerName, String consumerGroup)
  throws RemotingException, MQBrokerException, InterruptedException, MQClientException {
  try {
    String brokerAddr = (null != brokerName) ? this.mQClientFactory.findBrokerAddressInPublish(brokerName)
      : RemotingHelper.parseSocketAddressAddr(msg.getStoreHost());
    if (UtilAll.isBlank(consumerGroup)) {
      consumerGroup = this.defaultMQPullConsumer.getConsumerGroup();
    }
    this.mQClientFactory.getMQClientAPIImpl().consumerSendMessageBack(brokerAddr, msg, consumerGroup, delayLevel, 3000,
      this.defaultMQPullConsumer.getMaxReconsumeTimes());
  } catch (Exception e) {
    log.error("sendMessageBack Exception, " + this.defaultMQPullConsumer.getConsumerGroup(), e);
    Message newMsg = new Message(MixAll.getRetryTopic(this.defaultMQPullConsumer.getConsumerGroup()), msg.getBody());
    String originMsgId = MessageAccessor.getOriginMessageId(msg);
    MessageAccessor.setOriginMessageId(newMsg, UtilAll.isBlank(originMsgId) ? msg.getMsgId() : originMsgId);
    newMsg.setFlag(msg.getFlag());
    MessageAccessor.setProperties(newMsg, msg.getProperties());
    MessageAccessor.putProperty(newMsg, MessageConst.PROPERTY_RETRY_TOPIC, msg.getTopic());
    MessageAccessor.setReconsumeTime(newMsg, String.valueOf(msg.getReconsumeTimes() + 1));
    MessageAccessor.setMaxReconsumeTimes(newMsg, String.valueOf(this.defaultMQPullConsumer.getMaxReconsumeTimes()));
    newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
    this.mQClientFactory.getDefaultMQProducer().send(newMsg);
  }
}

相关文章