use of org.apache.rocketmq.common.message.Message in project spring-boot-starter-samples by vindell.
the class RocketmqApplicationTests method contextLoads.
@Test
public void contextLoads() throws MQClientException, RemotingException, MQBrokerException, InterruptedException {
// Destination destination = new ActiveMQQueue("mytest.queue");
Message msg = new // topic
Message(// topic
"TEST", // tag
"TEST", // key用于标识业务的唯一性
"KKK", // body 二进制字节数组
"hi,RocketMQ".getBytes());
for (int i = 0; i < 100; i++) {
SendResult result = rocketmqTemplate.send(msg);
System.out.println(result);
}
}
use of org.apache.rocketmq.common.message.Message in project spring-boot-starter-samples by vindell.
the class BroadcastProducer method main.
public static void main(String[] args) throws Exception {
DefaultMQProducer producer = new DefaultMQProducer("ProducerGroupName");
producer.start();
for (int i = 0; i < 100; i++) {
Message msg = new Message("TopicTest", "TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
SendResult sendResult = producer.send(msg);
System.out.printf("%s%n", sendResult);
}
producer.shutdown();
}
use of org.apache.rocketmq.common.message.Message in project spring-boot-starter-samples by vindell.
the class ListSplitter method next.
@Override
public List<Message> next() {
int nextIndex = currIndex;
int totalSize = 0;
for (; nextIndex < messages.size(); nextIndex++) {
Message message = messages.get(nextIndex);
int tmpSize = message.getTopic().length() + message.getBody().length;
Map<String, String> properties = message.getProperties();
for (Map.Entry<String, String> entry : properties.entrySet()) {
tmpSize += entry.getKey().length() + entry.getValue().length();
}
// for log overhead
tmpSize = tmpSize + 20;
if (tmpSize > SIZE_LIMIT) {
// here just let it go, otherwise it will block the splitting process
if (nextIndex - currIndex == 0) {
// if the next sublist has no element, add this one and then break, otherwise just break
nextIndex++;
}
break;
}
if (tmpSize + totalSize > SIZE_LIMIT) {
break;
} else {
totalSize += tmpSize;
}
}
List<Message> subList = messages.subList(currIndex, nextIndex);
currIndex = nextIndex;
return subList;
}
use of org.apache.rocketmq.common.message.Message 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