use of org.apache.rocketmq.client.producer.SendResult in project pinpoint by naver.
the class RocketMQOriginalProducer method send.
@GetMapping("/original/send")
public String send() throws UnsupportedEncodingException, RemotingException, MQClientException, InterruptedException, MQBrokerException {
Message msg = new Message("TopicTest", "TagA", "OrderID188", "Hello world".getBytes(RemotingHelper.DEFAULT_CHARSET));
SendResult send = producer.send(msg);
System.out.println(send.getMsgId());
return "success";
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq-externals by apache.
the class TopicServiceImplTest method sendTopicMessageRequest.
@Test
public void sendTopicMessageRequest() throws Exception {
SendTopicMessageRequest sendTopicMessageRequest = new SendTopicMessageRequest();
sendTopicMessageRequest.setTopic(TEST_CONSOLE_TOPIC);
sendTopicMessageRequest.setMessageBody("sendTopicMessageRequestMessageBody");
sendTopicMessageRequest.setKey("sendTopicMessageRequestKey");
sendTopicMessageRequest.setTag("sendTopicMessageRequestTag");
SendResult sendResult = topicService.sendTopicMessageRequest(sendTopicMessageRequest);
Assert.assertNotNull(sendResult);
Assert.assertTrue(StringUtils.isNoneBlank(sendResult.getMsgId()));
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq-externals by apache.
the class RocketMQSourceTest method testEvent.
@Test
public void testEvent() throws EventDeliveryException, MQBrokerException, MQClientException, InterruptedException, UnsupportedEncodingException {
// publish test message
DefaultMQProducer producer = new DefaultMQProducer(producerGroup);
producer.setNamesrvAddr(nameServer);
String sendMsg = "\"Hello Flume\"" + "," + DateFormatUtils.format(new Date(), "yyyy-MM-DD hh:mm:ss");
try {
producer.start();
Message msg = new Message(TOPIC_DEFAULT, tag, sendMsg.getBytes("UTF-8"));
SendResult sendResult = producer.send(msg);
log.info("publish message : {}, sendResult:{}", sendMsg, sendResult);
} catch (Exception e) {
throw new MQClientException("Failed to publish messages", e);
} finally {
producer.shutdown();
}
// start source
Context context = new Context();
context.put(NAME_SERVER_CONFIG, nameServer);
context.put(TAG_CONFIG, tag);
Channel channel = new MemoryChannel();
Configurables.configure(channel, context);
List<Channel> channels = new ArrayList<>();
channels.add(channel);
ChannelSelector channelSelector = new ReplicatingChannelSelector();
channelSelector.setChannels(channels);
ChannelProcessor channelProcessor = new ChannelProcessor(channelSelector);
RocketMQSource source = new RocketMQSource();
source.setChannelProcessor(channelProcessor);
Configurables.configure(source, context);
source.start();
PollableSource.Status status = source.process();
if (status == PollableSource.Status.BACKOFF) {
fail("Error");
}
/*
wait for processQueueTable init
*/
Thread.sleep(1000);
source.stop();
/*
mock flume sink
*/
Transaction transaction = channel.getTransaction();
transaction.begin();
Event event = channel.take();
if (event == null) {
transaction.commit();
fail("Error");
}
byte[] body = event.getBody();
String receiveMsg = new String(body, "UTF-8");
log.info("receive message : {}", receiveMsg);
assertEquals(sendMsg, receiveMsg);
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq-externals by apache.
the class RocketMQProducer method send.
/**
* @param event redis event.
* @return true if send success.
* @throws MQClientException MQClientException
* @throws RemotingException RemotingException
* @throws InterruptedException InterruptedException
* @throws MQBrokerException MQBrokerException
*/
public boolean send(Event event) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
Message msg = new Message(this.topic, toJSONBytes(event, IgnoreNonFieldGetter));
SendResult rs = this.producer.send(msg);
return rs.getSendStatus() == SendStatus.SEND_OK;
}
use of org.apache.rocketmq.client.producer.SendResult in project rocketmq-externals by apache.
the class TestController method list.
@RequestMapping(value = "/runTask.do", method = RequestMethod.GET)
@ResponseBody
public Object list() throws MQClientException, RemotingException, InterruptedException {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(testTopic + "Group");
consumer.setNamesrvAddr(rMQConfigure.getNamesrvAddr());
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.subscribe(testTopic, "*");
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
logger.info("receiveMessage msgSize={}", msgs.size());
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
final DefaultMQProducer producer = new DefaultMQProducer(testTopic + "Group");
producer.setInstanceName(String.valueOf(System.currentTimeMillis()));
producer.setNamesrvAddr(rMQConfigure.getNamesrvAddr());
producer.start();
new Thread(new Runnable() {
@Override
public void run() {
int i = 0;
while (true) {
try {
Message msg = new Message(testTopic, "TagA" + i, "KEYS" + i, ("Hello RocketMQ " + i).getBytes());
Thread.sleep(1000L);
SendResult sendResult = producer.send(msg);
logger.info("sendMessage={}", JsonUtil.obj2String(sendResult));
} catch (Exception e) {
e.printStackTrace();
try {
Thread.sleep(1000);
} catch (Exception ignore) {
}
}
}
}
}).start();
return true;
}
Aggregations