use of org.apache.rocketmq.common.message.Message in project paascloud-master by paascloud.
the class RocketMqProducer method sendSimpleMessage.
public static SendResult sendSimpleMessage(String body, String topic, String tag, String key, String pid, Integer delayLevel) {
if (delayLevel == null) {
delayLevel = 0;
}
Message message = MqMessage.checkMessage(body, topic, tag, key);
if (delayLevel < 0 || delayLevel > GlobalConstant.Number.EIGHTEEN_INT) {
throw new TpcBizException(ErrorCodeEnum.TPC100500013, topic, key);
}
message.setDelayTimeLevel(delayLevel);
return retrySendMessage(pid, message);
}
use of org.apache.rocketmq.common.message.Message 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);
}
use of org.apache.rocketmq.common.message.Message 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.common.message.Message in project spring-boot-starter-samples by vindell.
the class ProducerController method sendMsg.
/**
* 顺序消息
* @throws Exception
*/
@RequestMapping(value = "/sendMsg", method = RequestMethod.GET)
public void sendMsg() throws Exception {
for (int i = 0; i < 3; i++) {
for (int j = 0; j < 3; j++) {
Message msg = new Message("order", "TagA", "OrderID11113", (i + ":" + j).getBytes());
defaultProducer.send(msg, (List<MessageQueue> mqs, Message msg1, Object arg) -> {
// TODO Auto-generated method stub
int value = arg.hashCode();
if (value < 0) {
value = Math.abs(value);
}
value = value % mqs.size();
return mqs.get(value);
}, i);
}
}
}
use of org.apache.rocketmq.common.message.Message in project spring-boot-starter-samples by vindell.
the class ProducerController method rocketMq.
/**
* 普通消息
* @param tag
* @param body
* @param total
* @return
* @throws Exception
*/
@RequestMapping("/rocketMq/{tag}/{body}/{total}")
@ResponseBody
public String rocketMq(@PathVariable String tag, @PathVariable String body, @PathVariable Integer total) throws Exception {
long t1 = System.currentTimeMillis();
SendResult sendResult = null;
int fail = 0;
for (int i = 1; i < total + 1; i++) {
Message msg = new // topic
Message(// topic
"test", // tag
tag, // key
"OrderID11112", // body
(i + "").getBytes(RemotingHelper.DEFAULT_CHARSET));
// 同步发送
sendResult = defaultProducer.send(msg);
if (sendResult.getSendStatus().name().equals(SendStatus.SEND_OK.name())) {
fail++;
} else {
System.out.println(sendResult.getSendStatus().name());
}
}
long t2 = System.currentTimeMillis();
return "所花时间:" + (t2 - t1) + "成功次数" + fail;
}
Aggregations