use of org.apache.rocketmq.client.producer.SendResult in project spring-boot-starter-samples by vindell.
the class Producer method send.
// 每3s执行1次
@Scheduled(fixedDelay = 3000)
public void send() throws Exception {
/*// send queue.
MessageQueue mq = new MessageQueue("TEST", "brokerName", 1);
Message msg = new Message("TEST", // topic
"TEST", // tag
"KKK", // key用于标识业务的唯一性
"hi,RocketMQ".getBytes()// body 二进制字节数组
);
SendResult result = rocketmqTemplate.send(msg, mq);
System.out.println(result);*/
// send topic.
Message msg2 = new // topic
Message(// topic
"Topic-DC-Output", // tag
"TagA-Output", // key用于标识业务的唯一性; key 消息关键词,多个Key用KEY_SEPARATOR隔开(查询消息使用)
"KKK", // body 二进制字节数组
(new Date() + ": hi,RocketMQ(topic) ").getBytes());
SendResult result2 = rocketmqTemplate.send(msg2);
// System.out.println(result2);
}
use of org.apache.rocketmq.client.producer.SendResult 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.client.producer.SendResult 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.client.producer.SendResult 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();
}
use of org.apache.rocketmq.client.producer.SendResult in project spring-boot-starter-samples by vindell.
the class LogProducer method send.
public void send(String text) throws Exception {
Message msg = new // topic
Message(// topic
"Topic-DC-Output", // tag
"TagB-Output", // key用于标识业务的唯一性; key 消息关键词,多个Key用KEY_SEPARATOR隔开(查询消息使用)
"KKK", // body 二进制字节数组
text.getBytes());
SendResult result = rocketmqTemplate.send(msg);
System.out.println(result);
}
Aggregations