use of org.apache.rocketmq.client.consumer.MQPushConsumer in project spring-boot-starter-samples by vindell.
the class ConsumerListen method testListen.
@EventListener(condition = "#event.topic=='test'")
public void testListen(RocketmqEvent event) {
MQPushConsumer consumer = consumerTemplate.getConsumer();
try {
String id = new String(event.getMessageExt().getBody(), "utf-8");
System.out.println("bl" + id);
} catch (Exception e) {
e.printStackTrace();
if (event.getMessageExt().getReconsumeTimes() <= 1) {
// 重复消费1次
try {
consumer.sendMessageBack(event.getMessageExt(), 1, null);
} catch (RemotingException | MQBrokerException | InterruptedException | MQClientException e1) {
e1.printStackTrace();
// 消息进行定时重试
}
} else {
System.out.println("消息消费失败,定时重试");
}
}
}
Aggregations