本文整理了Java中com.alibaba.rocketmq.common.message.Message.<init>()
方法的一些代码示例,展示了Message.<init>()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Message.<init>()
方法的具体详情如下:
包路径:com.alibaba.rocketmq.common.message.Message
类名称:Message
方法名:<init>
暂无
代码示例来源:origin: kuangye098/rocketmq
private static Message buildMessage(final int messageSize) throws UnsupportedEncodingException {
Message msg = new Message();
msg.setTopic("BenchmarkTest");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < messageSize; i += 10) {
sb.append("hello baby");
}
msg.setBody(sb.toString().getBytes(RemotingHelper.DEFAULT_CHARSET));
return msg;
}
}
代码示例来源:origin: kuangye098/rocketmq
private static Message buildMessage(final int messageSize) throws UnsupportedEncodingException {
Message msg = new Message();
msg.setTopic("BenchmarkTest");
StringBuilder sb = new StringBuilder();
for (int i = 0; i < messageSize; i += 10) {
sb.append("hello baby");
}
msg.setBody(sb.toString().getBytes(RemotingHelper.DEFAULT_CHARSET));
return msg;
}
}
代码示例来源:origin: kuangye098/rocketmq
private static Message buildMessage(final String topic, final int messageSize) throws UnsupportedEncodingException {
Message msg = new Message();
msg.setTopic(topic);
StringBuilder sb = new StringBuilder();
for (int i = 0; i < messageSize; i += 11) {
sb.append("hello jodie");
}
msg.setBody(sb.toString().getBytes(MixAll.DEFAULT_CHARSET));
return msg;
}
}
代码示例来源:origin: majinkai/skye
public void send(List<Span> spans) {
try {
for (Span span : spans) {
LOG.debug("Ready for send {}", span);
Message message = new Message(Header.MQ_TOPIC, Header.MQ_TAG, Serializer.ser(span));
SendResult sendResult = producer.send(message);
LOG.debug("SendResult={}", sendResult);
}
} catch (Exception e) {
LOG.error("Send message exception", e);
}
}
代码示例来源:origin: coffeewar/enode-master
/**
* 发送数据的接口
*
* @param keySet 本批次包含的keyset
* @param data 本批次的轨迹数据
*/
private void sendTraceDataByMQ(Set<String> keySet, final String data, String currentRegionId) {
String topic = OnsTraceConstants.traceTopic + currentRegionId;
final Message message = new Message(topic, data.getBytes());
message.setKeys(keySet);
try {
traceProducer.send(message, new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
}
@Override
public void onException(Throwable e) {
//todo 对于发送失败的数据,如何保存,保证所有轨迹数据都记录下来
clientlog.info("send trace data ,the traceData is " + data);
}
}, 5000);
} catch (Exception e) {
clientlog.info("send trace data,the traceData is" + data);
}
}
}
代码示例来源:origin: kuangye098/rocketmq
public static void main(String[] args) throws MQClientException, InterruptedException {
DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
producer.start();
for (int i = 0; i < 10000000; i++)
try {
{
Message msg = new Message("TopicTest",// topic
"TagA",// tag
"OrderID188",// key
("Hello MetaQ").getBytes(RemotingHelper.DEFAULT_CHARSET));// body
SendResult sendResult = producer.send(msg);
System.out.println(sendResult);
}
} catch (Exception e) {
e.printStackTrace();
}
producer.shutdown();
}
}
代码示例来源:origin: kuangye098/rocketmq
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",// topic
"TagA",// tag
"OrderID001",// key
("Hello MetaQ").getBytes(RemotingHelper.DEFAULT_CHARSET));// body
msg.putUserProperty("SequenceId", String.valueOf(i));
SendResult sendResult = producer.send(msg);
System.out.println(sendResult);
}
} catch (Exception e) {
e.printStackTrace();
}
producer.shutdown();
}
}
代码示例来源:origin: kuangye098/rocketmq
public static void main(String[] args) throws MQClientException, InterruptedException {
DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
producer.start();
for (int i = 0; i < 1; i++)
try {
{
Message msg = new Message("TopicTest1",// topic
"TagA",// tag
"key113",// key
("Hello MetaQ").getBytes(RemotingHelper.DEFAULT_CHARSET));// body
SendResult sendResult = producer.send(msg);
System.out.println(sendResult);
QueryResult queryMessage =
producer.queryMessage("TopicTest1", "key113", 10, 0, System.currentTimeMillis());
for (MessageExt m : queryMessage.getMessageList()) {
System.out.println(m);
}
}
} catch (Exception e) {
e.printStackTrace();
}
producer.shutdown();
}
}
代码示例来源:origin: songxinjianqwe/EShop-SOA
@Transactional
@Override
public void check() {
List<Long> all = mapper.findMessageIdsByStatusCreatedAfter(Arrays.asList(MessageStatus.UNCONSUMED, MessageStatus.CONSUME_FAILED), MQProducerConfig.CHECK_GAP);
Message checkMessage = new Message();
checkMessage.setTopic(config.getTopic());
checkMessage.setTags(config.getCheckKeys());
checkMessage.setBody(ProtoStuffUtil.serialize(all));
try {
producer.send(checkMessage);
} catch (Exception e) {
log.info("发送check消息失败,暂不做处理,不会影响数据一致性");
e.printStackTrace();
}
}
代码示例来源:origin: songxinjianqwe/EShop-SOA
@Override
public void commit(OrderDO order, String paymentPassword) {
Message message = new Message();
message.setTopic(config.getTopic());
message.setBody(ProtoStuffUtil.serialize(order));
TransactionSendResult result = null;
try {
result = this.producer.sendMessageInTransaction(message, executor, paymentPassword);
log.info("事务消息发送结果:{}", result);
log.info("TransactionState:{} ", result.getLocalTransactionState());
// 因为无法获得executor中抛出的异常,只能模糊地返回订单支付失败信息。
// TODO 想办法从executor中找到原生异常
} catch (Exception e) {
log.info("AccountService抛出异常...");
e.printStackTrace();
}
if (result.getLocalTransactionState() == LocalTransactionState.ROLLBACK_MESSAGE) {
throw new OrderPaymentException(order.getId());
}
}
代码示例来源:origin: songxinjianqwe/EShop-SOA
@Transactional
@Override
public void reSend(List<ProducerTransactionMessageDO> messages) {
for (ProducerTransactionMessageDO messageDO : messages) {
if (messageDO.getSendTimes() == config.getRetryTimes()) {
messageDO.setUpdateTime(LocalDateTime.now());
messageDO.setMessageStatus(MessageStatus.OVER_CONFIRM_RETRY_TIME);
mapper.updateByPrimaryKeySelective(messageDO);
continue;
}
Message message = new Message();
message.setTopic(config.getTopic());
message.setBody(messageDO.getBody());
try {
SendResult result = producer.send(message);
messageDO.setSendTimes(messageDO.getSendTimes() + 1);
messageDO.setUpdateTime(LocalDateTime.now());
mapper.updateByPrimaryKeySelective(messageDO);
log.info("发送重试消息完毕,Message:{},result:{}", message, result);
} catch (Exception e) {
e.printStackTrace();
log.info("发送重试消息时失败! Message:{}", message);
}
}
}
代码示例来源:origin: dubboclub/dubbo-plus
@Override
public void push(List<Span> spanList) {
byte[] bytes = JSON.toJSONBytes(spanList);
Message message = new Message(DstConstants.ROCKET_MQ_TOPIC,bytes);
try {
SendResult sendResult = defaultMQProducer.send(message);
if(sendResult.getSendStatus()!= SendStatus.SEND_OK){
logger.error("send mq message return ["+sendResult.getSendStatus()+"]");
}
} catch (Exception e) {
logger.error("fail to send message.",e);
}
}
}
代码示例来源:origin: coffeewar/enode-master
private Message createEQueueMessage(IApplicationMessage message) {
TopicTagData topicTagData = _messageTopicProvider.getPublishTopic(message);
String appMessageData = _jsonSerializer.serialize(message);
ApplicationDataMessage appDataMessage = new ApplicationDataMessage(appMessageData, message.getClass().getName());
String data = _jsonSerializer.serialize(appDataMessage);
Message mqMessage = new Message(topicTagData.getTopic(), //topic
//_typeNameProvider.getTypeName(message.getClass()), //tags
topicTagData.getTag(), //tag
message.id(), // keys
RocketMQMessageTypeCode.ApplicationMessage.getValue(), // flag
BitConverter.getBytes(data), // body
true);
if (message.getStartDeliverTime() > 0) {
mqMessage.putUserProperty(CommandService.RocketMQSystemPropKey.STARTDELIVERTIME, String.valueOf(message.getStartDeliverTime()));
}
return mqMessage;
}
}
代码示例来源:origin: coffeewar/enode-master
private Message buildCommandMessage(ICommand command, boolean needReply) {
Ensure.notNull(command.getAggregateRootId(), "aggregateRootId");
String commandData = _jsonSerializer.serialize(command);
TopicTagData topicTagData = _commandTopicProvider.getPublishTopic(command);
String replyAddress = needReply && _commandResultProcessor != null ? parseAddress(_commandResultProcessor.getBindingAddress()) : null;
// String replyAddress = null;
String messageData = _jsonSerializer.serialize(new CommandMessage(commandData, replyAddress, command.getClass().getName()));
byte[] body = BitConverter.getBytes(messageData);
String key = buildRocketMQMessageKey(command);
Message message = new Message(topicTagData.getTopic(),
topicTagData.getTag(),
key,
RocketMQMessageTypeCode.CommandMessage.ordinal(), body, true);
if (command.getStartDeliverTime() > 0) {
message.putUserProperty(RocketMQSystemPropKey.STARTDELIVERTIME, String.valueOf(command.getStartDeliverTime()));
}
return message;
}
代码示例来源:origin: coffeewar/enode-master
private Message createRocketMQMessage(DomainEventStreamMessage eventStream) {
Ensure.notNull(eventStream.aggregateRootId(), "aggregateRootId");
EventStreamMessage eventMessage = createEventMessage(eventStream);
TopicTagData topicTagData = _eventTopicProvider.getPublishTopic(null);
String data = _jsonSerializer.serialize(eventMessage);
String key = buildRocketMQMessageKey(eventStream);
byte[] body = BitConverter.getBytes(data);
return new Message(topicTagData.getTopic(),
topicTagData.getTag(),
key,
RocketMQMessageTypeCode.DomainEventStreamMessage.getValue(), body, true);
}
代码示例来源:origin: com.alibaba.rocketmq/rocketmq-client
public boolean sendMessageBack(final MessageExt msg) {
try {
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(this.defaultMQPushConsumer.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: kuangye098/rocketmq
public boolean sendMessageBack(final MessageExt msg) {
try {
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(this.defaultMQPushConsumer.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: com.alibaba.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, this.defaultMQPushConsumer.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(this.defaultMQPushConsumer.getMaxReconsumeTimes()));
newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
this.mQClientFactory.getDefaultMQProducer().send(newMsg);
}
}
代码示例来源:origin: kuangye098/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, this.defaultMQPushConsumer.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(this.defaultMQPushConsumer.getMaxReconsumeTimes()));
newMsg.setDelayTimeLevel(3 + msg.getReconsumeTimes());
this.mQClientFactory.getDefaultMQProducer().send(newMsg);
}
}
代码示例来源:origin: com.alibaba.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);
}
}
内容来源于网络,如有侵权,请联系作者删除!