Search in sources :

Example 1 with MQPushConsumer

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("消息消费失败,定时重试");
        }
    }
}
Also used : DefaultMQPushConsumer(org.apache.rocketmq.client.consumer.DefaultMQPushConsumer) MQPushConsumer(org.apache.rocketmq.client.consumer.MQPushConsumer) MQClientException(org.apache.rocketmq.client.exception.MQClientException) MQBrokerException(org.apache.rocketmq.client.exception.MQBrokerException) RemotingException(org.apache.rocketmq.remoting.exception.RemotingException) EventListener(org.springframework.context.event.EventListener)

Aggregations

DefaultMQPushConsumer (org.apache.rocketmq.client.consumer.DefaultMQPushConsumer)1 MQPushConsumer (org.apache.rocketmq.client.consumer.MQPushConsumer)1 MQBrokerException (org.apache.rocketmq.client.exception.MQBrokerException)1 MQClientException (org.apache.rocketmq.client.exception.MQClientException)1 RemotingException (org.apache.rocketmq.remoting.exception.RemotingException)1 EventListener (org.springframework.context.event.EventListener)1