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

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

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

Message.setFlag介绍

暂无

代码示例

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

public static Message decodeMessage(ByteBuffer byteBuffer) throws Exception {
  Message message = new Message();
  // 1 TOTALSIZE
  byteBuffer.getInt();
  // 2 MAGICCODE
  byteBuffer.getInt();
  // 3 BODYCRC
  byteBuffer.getInt();
  // 4 FLAG
  int flag = byteBuffer.getInt();
  message.setFlag(flag);
  // 5 BODY
  int bodyLen = byteBuffer.getInt();
  byte[] body = new byte[bodyLen];
  byteBuffer.get(body);
  message.setBody(body);
  // 6 properties
  short propertiesLen = byteBuffer.getShort();
  byte[] propertiesBytes = new byte[propertiesLen];
  byteBuffer.get(propertiesBytes);
  message.setProperties(string2messageProperties(new String(propertiesBytes, CHARSET_UTF8)));
  return message;
}

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

public static Message cloneMessage(final Message msg) {
  Message newMsg = new Message(msg.getTopic(), msg.getBody());
  newMsg.setFlag(msg.getFlag());
  newMsg.setProperties(msg.getProperties());
  return newMsg;
}

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

toSend.setTags(headerAccessor.getTags());
toSend.setKeys(headerAccessor.getKeys());
toSend.setFlag(headerAccessor.getFlag());
for (Map.Entry<String, String> entry : headerAccessor.getUserProperties()
    .entrySet()) {

代码示例来源: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: apache/rocketmq

message.setWaitStoreMsgOK(false);
message.setBuyerId("buyerid123");
message.setFlag(123);
message.setBody("body".getBytes());
messageList.add(message);

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

public static Message decodeMessage(ByteBuffer byteBuffer) throws Exception {
  Message message = new Message();
  // 1 TOTALSIZE
  byteBuffer.getInt();
  // 2 MAGICCODE
  byteBuffer.getInt();
  // 3 BODYCRC
  byteBuffer.getInt();
  // 4 FLAG
  int flag = byteBuffer.getInt();
  message.setFlag(flag);
  // 5 BODY
  int bodyLen = byteBuffer.getInt();
  byte[] body = new byte[bodyLen];
  byteBuffer.get(body);
  message.setBody(body);
  // 6 properties
  short propertiesLen = byteBuffer.getShort();
  byte[] propertiesBytes = new byte[propertiesLen];
  byteBuffer.get(propertiesBytes);
  message.setProperties(string2messageProperties(new String(propertiesBytes, CHARSET_UTF8)));
  return message;
}

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

rocketMsg.setFlag(flag);

代码示例来源: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: didi/DDMQ

message.setWaitStoreMsgOK(false);
message.setBuyerId("buyerid123");
message.setFlag(123);
message.setBody("body".getBytes());
messageList.add(message);

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

public static Message decodeMessage(ByteBuffer byteBuffer) throws Exception {
  Message message = new Message();
  // 1 TOTALSIZE
  byteBuffer.getInt();
  // 2 MAGICCODE
  byteBuffer.getInt();
  // 3 BODYCRC
  byteBuffer.getInt();
  // 4 FLAG
  int flag = byteBuffer.getInt();
  message.setFlag(flag);
  // 5 BODY
  int bodyLen = byteBuffer.getInt();
  byte[] body = new byte[bodyLen];
  byteBuffer.get(body);
  message.setBody(body);
  // 6 properties
  short propertiesLen = byteBuffer.getShort();
  byte[] propertiesBytes = new byte[propertiesLen];
  byteBuffer.get(propertiesBytes);
  message.setProperties(string2messageProperties(new String(propertiesBytes, CHARSET_UTF8)));
  return message;
}

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

rocketMsg.setFlag(flag);

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

rocketMsg.setFlag(flag);

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

public static Message cloneMessage(final Message msg) {
  Message newMsg = new Message(msg.getTopic(), msg.getBody());
  newMsg.setFlag(msg.getFlag());
  newMsg.setProperties(msg.getProperties());
  return newMsg;
}

代码示例来源: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);
  }
}

相关文章