本文整理汇总了Java中org.apache.rocketmq.common.message.Message.setDelayTimeLevel方法的典型用法代码示例。如果您正苦于以下问题:Java Message.setDelayTimeLevel方法的具体用法?Java Message.setDelayTimeLevel怎么用?Java Message.setDelayTimeLevel使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.rocketmq.common.message.Message
的用法示例。
在下文中一共展示了Message.setDelayTimeLevel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendMessageBack
import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
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);
}
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:26,代码来源:DefaultMQPushConsumerImpl.java
示例2: sendMessageBack
import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
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;
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:22,代码来源:ConsumeMessageOrderlyService.java
示例3: syncSendWithDelay
import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
* 同步发送消息
* @param topic topic
* @param tag tag
* @param msgObj 消息体
* @param delayTimeLevel 默认延迟等级 : 1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h, 传入1代表1s, 2代表5s, 以此类推
* @throws MQException 消息异常
*/
public void syncSendWithDelay(String topic, String tag, Object msgObj, int delayTimeLevel) throws MQException {
if(null == msgObj) {
return;
}
Message delayedMsg = genMessage(topic, tag, msgObj);
try {
if(delayTimeLevel > 0 && delayTimeLevel <= DELAY_ARRAY.length) {
delayedMsg.setDelayTimeLevel(delayTimeLevel);
}
SendResult sendResult = producer.send(delayedMsg);
log.info("sync send rocketmq message with delay, messageId : {}, default delay interval: {}", sendResult.getMsgId(), DELAY_ARRAY[delayTimeLevel-1]);
this.doAfterSyncSend(delayedMsg, sendResult);
} catch (Exception e) {
log.error("消息发送失败,topic : {}, msgObj {}", delayedMsg.getTopic(), msgObj);
throw new MQException("消息发送失败,topic :" + topic + ",e:" + e.getMessage());
}
}
示例4: sendMessageBack
import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
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);
}
}
开发者ID:lirenzuo,项目名称:rocketmq-rocketmq-all-4.1.0-incubating,代码行数:28,代码来源:DefaultMQPullConsumerImpl.java
示例5: getDelayMsg
import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
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;
}
示例6: sendDelayMsg
import org.apache.rocketmq.common.message.Message; //导入方法依赖的package包/类
/**
* send delay msg.
*
* @param msg content
* @param delayLevel 1s 5s 10s 30s 1m 2m 3m 4m 5m 6m 7m 8m 9m 10m 20m 30m 1h 2h
* @return send result
*/
public boolean sendDelayMsg(String topic, String tag, Message msg, int delayLevel) {
msg.setDelayTimeLevel(delayLevel);
SendResult sendResult = null;
try {
sendResult = producer.send(msg);
} catch (Exception e) {
logger.error("send msg error", e);
}
return sendResult != null && sendResult.getSendStatus() == SendStatus.SEND_OK;
}