use of org.apache.rocketmq.common.message.MessageQueue in project spring-boot-starter-samples by vindell.
the class OrderedProducer method main.
public static void main(String[] args) throws Exception {
// Instantiate with a producer group name.
MQProducer producer = new DefaultMQProducer("example_group_name");
// Launch the instance.
producer.start();
String[] tags = new String[] { "TagA", "TagB", "TagC", "TagD", "TagE" };
for (int i = 0; i < 100; i++) {
int orderId = i % 10;
// Create a message instance, specifying topic, tag and message body.
Message msg = new Message("TopicTestjjj", tags[i % tags.length], "KEY" + i, ("Hello RocketMQ " + i).getBytes(RemotingHelper.DEFAULT_CHARSET));
SendResult sendResult = producer.send(msg, new MessageQueueSelector() {
@Override
public MessageQueue select(List<MessageQueue> mqs, Message msg, Object arg) {
Integer id = (Integer) arg;
int index = id % mqs.size();
return mqs.get(index);
}
}, orderId);
System.out.printf("%s%n", sendResult);
}
// server shutdown
producer.shutdown();
}
Aggregations