use of com.alibaba.rocketmq.common.message.MessageExt in project uavstack by uavorg.
the class TestRestService method testRocketmq.
@POST
@Path("testRocketmq")
public void testRocketmq(String jsonString) {
DefaultMQProducer producer = new DefaultMQProducer("hookTest");
producer.setNamesrvAddr("127.0.0.1:9876");
Message msg = new Message("SELF_TEST_TOPIC", "test".getBytes());
try {
producer.start();
for (int i = 0; i < 10; i++) {
producer.send(msg);
}
} catch (MQClientException e) {
e.printStackTrace();
} catch (RemotingException e) {
e.printStackTrace();
} catch (MQBrokerException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
}
DefaultMQPushConsumer pushConsumer = new DefaultMQPushConsumer("hookTest");
pushConsumer.setNamesrvAddr("127.0.0.1:9876");
pushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
pushConsumer.registerMessageListener(new MessageListenerOrderly() {
@Override
public ConsumeOrderlyStatus consumeMessage(List<MessageExt> msgs, ConsumeOrderlyContext context) {
System.out.println("haha");
return ConsumeOrderlyStatus.SUCCESS;
}
});
pushConsumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
System.out.println("haha");
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
try {
pushConsumer.subscribe("SELF_TEST_TOPIC", null);
pushConsumer.start();
} catch (MQClientException e1) {
e1.printStackTrace();
}
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
pushConsumer.shutdown();
producer.shutdown();
}
use of com.alibaba.rocketmq.common.message.MessageExt in project warn-report by saaavsaaa.
the class PullConsumerCluter method getMessage.
public List<MessageExt> getMessage(final String topic, final Long offset, final String subExpression) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
List<MessageExt> result = new ArrayList<MessageExt>();
Set<MessageQueue> mqs = consumer.fetchSubscribeMessageQueues(topic);
for (MessageQueue mq : mqs) {
PullResult pullResult = consumer.pullBlockIfNotFound(mq, subExpression, offset, 1);
if (pullResult.getPullStatus() == PullStatus.FOUND) {
List<MessageExt> extList = pullResult.getMsgFoundList();
result.addAll(extList);
}
}
return result;
}
use of com.alibaba.rocketmq.common.message.MessageExt in project uavstack by uavorg.
the class RocketMQConsumer method handleRocketMqMessage.
private void handleRocketMqMessage(List<MessageExt> msgs, MQMessageListener messageListner) {
for (MessageExt msg : msgs) {
MQMessage ceMessage = new MQMessage();
byte[] msgBody = msg.getBody();
ceMessage.setMessage(msgBody);
try {
messageListner.handle(ceMessage);
} catch (Exception e) {
log.err(this, "MsgId=" + msg.getMsgId() + ",Topic=" + msg.getTopic() + ",MsgBornTimeStamp=" + msg.getBornTimestamp() + "处理异常:" + e.getMessage(), e);
}
}
}
Aggregations