use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class BatchSendIT method testBatchSend_CheckProperties.
@Test
public void testBatchSend_CheckProperties() throws Exception {
List<Message> messageList = new ArrayList<>();
Message message = new Message();
message.setTopic(topic);
message.setKeys("keys123");
message.setTags("tags123");
message.setWaitStoreMsgOK(false);
message.setBuyerId("buyerid123");
message.setFlag(123);
message.setBody("body".getBytes());
messageList.add(message);
DefaultMQProducer producer = ProducerFactory.getRMQProducer(nsAddr);
SendResult sendResult = producer.send(messageList);
Assert.assertEquals(SendStatus.SEND_OK, sendResult.getSendStatus());
String[] offsetIds = sendResult.getOffsetMsgId().split(",");
String[] msgIds = sendResult.getMsgId().split(",");
Assert.assertEquals(messageList.size(), offsetIds.length);
Assert.assertEquals(messageList.size(), msgIds.length);
Thread.sleep(2000);
Message messageByOffset = producer.viewMessage(offsetIds[0]);
Message messageByMsgId = producer.viewMessage(topic, msgIds[0]);
System.out.println(messageByOffset);
System.out.println(messageByMsgId);
Assert.assertEquals(message.getTopic(), messageByMsgId.getTopic());
Assert.assertEquals(message.getTopic(), messageByOffset.getTopic());
Assert.assertEquals(message.getKeys(), messageByOffset.getKeys());
Assert.assertEquals(message.getKeys(), messageByMsgId.getKeys());
Assert.assertEquals(message.getTags(), messageByOffset.getTags());
Assert.assertEquals(message.getTags(), messageByMsgId.getTags());
Assert.assertEquals(message.isWaitStoreMsgOK(), messageByOffset.isWaitStoreMsgOK());
Assert.assertEquals(message.isWaitStoreMsgOK(), messageByMsgId.isWaitStoreMsgOK());
Assert.assertEquals(message.getBuyerId(), messageByOffset.getBuyerId());
Assert.assertEquals(message.getBuyerId(), messageByMsgId.getBuyerId());
Assert.assertEquals(message.getFlag(), messageByOffset.getFlag());
Assert.assertEquals(message.getFlag(), messageByMsgId.getFlag());
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq by apache.
the class MessageExceptionIT method testProducerSmoke.
@Test
public void testProducerSmoke() {
Message msg = new Message(topic, RandomUtils.getStringByUUID().getBytes());
SendResult sendResult = null;
try {
sendResult = producer.send(msg);
} catch (Exception e) {
}
assertThat(sendResult).isNotEqualTo(null);
assertThat(sendResult.getSendStatus()).isEqualTo(SendStatus.SEND_OK);
}
use of org.apache.rocketmq.client.producer.SendResult in project canal by alibaba.
the class CanalRocketMQProducer method sendMessage.
@SuppressWarnings("deprecation")
private void sendMessage(List<Message> messages, int partition) {
if (messages.isEmpty()) {
return;
}
// 获取一下messageQueue
DefaultMQProducerImpl innerProducer = this.defaultMQProducer.getDefaultMQProducerImpl();
TopicPublishInfo topicInfo = innerProducer.getTopicPublishInfoTable().get(messages.get(0).getTopic());
if (topicInfo == null) {
for (Message message : messages) {
sendMessage(message, partition);
}
} else {
// 批量发送
List<MessageQueue> queues = topicInfo.getMessageQueueList();
int size = queues.size();
if (size <= 0) {
// 可能是第一次创建
for (Message message : messages) {
sendMessage(message, partition);
}
} else {
MessageQueue queue;
if (partition >= size) {
queue = queues.get(partition % size);
} else {
queue = queues.get(partition);
}
try {
// 阿里云RocketMQ暂不支持批量发送消息,当canal.mq.flatMessage = true时,会发送失败
SendResult sendResult = this.defaultMQProducer.send(messages, queue);
if (logger.isDebugEnabled()) {
logger.debug("Send Message Result: {}", sendResult);
}
} catch (Throwable e) {
throw new RuntimeException(e);
}
}
}
}
use of org.apache.rocketmq.client.producer.SendResult in project pinpoint by naver.
the class RocketMQOriginalProducer method sendAsync.
@GetMapping("/original/sendAsync")
public String sendAsync() throws UnsupportedEncodingException, RemotingException, MQClientException, InterruptedException {
Message msg = new Message("TopicTest", "TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
producer.send(msg, new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
System.out.printf(sendResult.getMsgId());
}
@Override
public void onException(Throwable e) {
System.out.printf("Exception", e);
e.printStackTrace();
}
});
return "success";
}
use of org.apache.rocketmq.client.producer.SendResult in project pinpoint by naver.
the class RocketMQSpringBootProducer method templatesendAsync.
@GetMapping("/template/sendAsync")
public String templatesendAsync() {
String topic = "TopicTest";
rocketMQTemplate.asyncSend(topic, MessageBuilder.withPayload("Hello, World!2222".getBytes(UTF8)).build(), new SendCallback() {
@Override
public void onSuccess(SendResult sendResult) {
System.out.printf("async onSucess SendResult=%s %n", sendResult);
}
@Override
public void onException(Throwable e) {
System.out.printf("async onException Throwable=%s %n", e);
}
});
return "success";
}
Aggregations