本文整理汇总了Java中com.alibaba.rocketmq.common.message.Message.setDelayTimeLevel方法的典型用法代码示例。如果您正苦于以下问题:Java Message.setDelayTimeLevel方法的具体用法?Java Message.setDelayTimeLevel怎么用?Java Message.setDelayTimeLevel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类com.alibaba.rocketmq.common.message.Message
的用法示例。
在下文中一共展示了Message.setDelayTimeLevel方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testScheduledMessageProducer
import com.alibaba.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Test
public void testScheduledMessageProducer() throws Exception {
// Instantiate a producer to send scheduled messages
DefaultMQProducer producer = new DefaultMQProducer("ExampleProducerGroup");
// Launch producer
producer.start();
int totalMessagesToSend = 100;
for (int i = 0; i < totalMessagesToSend; i++) {
Message message = new Message("TestTopic", ("Hello scheduled message " + i).getBytes());
// This message will be delivered to consumer 10 seconds later.
message.setDelayTimeLevel(3);
// Send the message
producer.send(message);
}
// Shutdown producer after use.
producer.shutdown();
}
示例2: send
import com.alibaba.rocketmq.common.message.Message; //导入方法依赖的package包/类
public SendResult send(String topic, String tags, String keys, byte[] body, int delayTimeLevel) throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
Message msg = new Message(topic, tags, keys, body);
msg.setDelayTimeLevel(delayTimeLevel);
log.info("rocketMQ sending msg=" + msg.toString());
SendResult sendResult = producer.send(msg);
log.info("rocketMQ sending result, key=" + keys + ",result=" + sendResult.toString());
return sendResult;
}
示例3: test_sendMessage
import com.alibaba.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Test
public void test_sendMessage() throws Exception {
BrokerController brokerController = new BrokerController(//
new BrokerConfig(), //
new NettyServerConfig(), //
new NettyClientConfig(), //
new MessageStoreConfig());
boolean initResult = brokerController.initialize();
System.out.println("initialize " + initResult);
brokerController.start();
MQClientAPIImpl client = new MQClientAPIImpl(new NettyClientConfig(), null, null, null);
client.start();
for (int i = 0; i < 100000; i++) {
String topic = "UnitTestTopic_" + i % 3;
Message msg = new Message(topic, "TAG1 TAG2", "100200300", ("Hello, Nice world\t" + i).getBytes());
msg.setDelayTimeLevel(i % 3 + 1);
try {
SendMessageRequestHeader requestHeader = new SendMessageRequestHeader();
requestHeader.setProducerGroup("abc");
requestHeader.setTopic(msg.getTopic());
requestHeader.setDefaultTopic(MixAll.DEFAULT_TOPIC);
requestHeader.setDefaultTopicQueueNums(4);
requestHeader.setQueueId(i % 4);
requestHeader.setSysFlag(0);
requestHeader.setBornTimestamp(System.currentTimeMillis());
requestHeader.setFlag(msg.getFlag());
requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties()));
SendResult result =
client.sendMessage("127.0.0.1:10911", "brokerName", msg, requestHeader, 1000 * 5, CommunicationMode.SYNC, null);
System.out.println(i + "\t" + result);
}
catch (Exception e) {
e.printStackTrace();
}
}
client.shutdown();
brokerController.shutdown();
}
示例4: test_sendMessage
import com.alibaba.rocketmq.common.message.Message; //导入方法依赖的package包/类
@Test
public void test_sendMessage() throws Exception {
BrokerController brokerController = new BrokerController(//
new BrokerConfig(), //
new NettyServerConfig(), //
new NettyClientConfig(), //
new MessageStoreConfig());
boolean initResult = brokerController.initialize();
System.out.println("initialize " + initResult);
brokerController.start();
MQClientAPIImpl client = new MQClientAPIImpl(new NettyClientConfig(), null);
client.start();
for (int i = 0; i < 100000; i++) {
String topic = "UnitTestTopic_" + i % 3;
Message msg =
new Message(topic, "TAG1 TAG2", "100200300", ("Hello, Nice world\t" + i).getBytes());
msg.setDelayTimeLevel(i % 3 + 1);
try {
SendMessageRequestHeader requestHeader = new SendMessageRequestHeader();
requestHeader.setProducerGroup("abc");
requestHeader.setTopic(msg.getTopic());
requestHeader.setDefaultTopic(MixAll.DEFAULT_TOPIC);
requestHeader.setDefaultTopicQueueNums(4);
requestHeader.setQueueId(i % 4);
requestHeader.setSysFlag(0);
requestHeader.setBornTimestamp(System.currentTimeMillis());
requestHeader.setFlag(msg.getFlag());
requestHeader.setProperties(MessageDecoder.messageProperties2String(msg.getProperties()));
SendResult result =
client.sendMessage("127.0.0.1:10911", "brokerName", msg, requestHeader, 1000 * 5,
CommunicationMode.SYNC, null);
System.out.println(i + "\t" + result);
}
catch (Exception e) {
e.printStackTrace();
}
}
client.shutdown();
brokerController.shutdown();
}