use of org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus in project spring-boot-starter-samples by vindell.
the class ScheduledMessageConsumer method main.
public static void main(String[] args) throws Exception {
// Instantiate message consumer
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("ExampleConsumer");
// Subscribe topics
consumer.subscribe("TestTopic", "*");
// Register message listener
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> messages, ConsumeConcurrentlyContext context) {
for (MessageExt message : messages) {
// Print approximate delay time period
System.out.println("Receive message[msgId=" + message.getMsgId() + "] " + (System.currentTimeMillis() - message.getStoreTimestamp()) + "ms later");
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
// Launch consumer
consumer.start();
}
use of org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus 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;
}
use of org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus in project java-example by 1479005017.
the class AliyunReceiver method main.
public static void main(String[] argv) throws Exception {
/**
* Alions
*/
AlionsRPCHook rpcHook = new AlionsRPCHook();
rpcHook.setAccessKeyId(accessKeyId);
rpcHook.setAccessKeySecret(accessKeySecret);
rpcHook.setOnsChannel(onsChannel);
/**
* 初始化
*/
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer(rpcHook);
consumer.setNamesrvAddr(HttpTinyClient.fetchNamesrvAddress(nameServer));
consumer.setConsumerGroup(consumerGroup);
consumer.setVipChannelEnabled(vipChannelEnabled);
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.subscribe("conanli-test", "*");
/**
* 监听消息
*/
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
System.out.printf("%s Receive New Message: %s %n", Thread.currentThread().getName(), msgs);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
/**
* 启动
*/
consumer.start();
}
use of org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus in project java-example by 1479005017.
the class HelloReceiver method main.
public static void main(String[] argv) throws Exception {
/**
* 初始化
*/
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer();
consumer.setNamesrvAddr(namesrvAddr);
consumer.setConsumerGroup(consumerGroup);
consumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
consumer.subscribe("hello", "*");
/**
* 监听消息
*/
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> msgs, ConsumeConcurrentlyContext context) {
System.out.printf("%s Receive New Message: %s %n", Thread.currentThread().getName(), msgs);
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
/**
* 启动
*/
consumer.start();
}
use of org.apache.rocketmq.client.consumer.listener.ConsumeConcurrentlyStatus in project incubator-skywalking by apache.
the class MessageConcurrentlyConsumeInterceptor method afterMethod.
@Override
public Object afterMethod(EnhancedInstance objInst, Method method, Object[] allArguments, Class<?>[] argumentsTypes, Object ret) throws Throwable {
ConsumeConcurrentlyStatus status = (ConsumeConcurrentlyStatus) ret;
if (status == ConsumeConcurrentlyStatus.RECONSUME_LATER) {
AbstractSpan activeSpan = ContextManager.activeSpan();
activeSpan.errorOccurred();
Tags.STATUS_CODE.set(activeSpan, status.name());
}
ContextManager.stopSpan();
return ret;
}
Aggregations