use of org.apache.rocketmq.serializer.json.RocketMQJsonDeserializer in project rocketmq-externals by apache.
the class JsonConsumer method main.
public static void main(String[] args) throws Exception {
DefaultMQPushConsumer consumer = new DefaultMQPushConsumer("consumer-group-json");
consumer.setNamesrvAddr("localhost:9876");
consumer.subscribe("topic-json", "*");
// creating deserializer for message body deserializing
RocketMQDeserializer deserializer = new RocketMQJsonDeserializer<>(User.class);
consumer.registerMessageListener(new MessageListenerConcurrently() {
@Override
public ConsumeConcurrentlyStatus consumeMessage(List<MessageExt> list, ConsumeConcurrentlyContext consumeConcurrentlyContext) {
for (MessageExt messageExt : list) {
// getting data from message.
User user = Messages.getMessageBody(messageExt, deserializer);
System.out.print(user.getName() + ":" + user.getAge() + "\n");
}
return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
}
});
consumer.start();
}
Aggregations