use of org.apache.rocketmq.serializer.json.RocketMQJsonSerializer in project rocketmq-externals by apache.
the class JsonProducer method main.
public static void main(String[] args) throws Exception {
DefaultMQProducer producer = new DefaultMQProducer("producer-group-json");
producer.setNamesrvAddr("localhost:9876");
producer.start();
// creating serializer for message body serializing
RocketMQSerializer serializer = new RocketMQJsonSerializer<User>();
for (int i = 0; i < 100; i++) {
User user = new User();
user.setName("tom");
user.setAge(i);
// creating message from user data.
Message message = Messages.newMessage("topic-json", user, serializer);
SendResult result = producer.send(message);
System.out.print(result.getSendStatus() + " " + i + "\n");
Thread.sleep(1000);
}
}
Aggregations