DefaultMQProducer defaultMQProducer = new DefaultMQProducer("default");
defaultMQProducer.setNamesrvAddr("localhost:9876");
defaultMQProducer.start();
Message message = new Message("TopicTest", "TestTag", "Hello RocketMQ".getBytes(RemotingHelper.DEFAULT_CHARSET));
SendResult sendResult = defaultMQProducer.send(message);
System.out.println("sendResult = " + sendResult);
defaultMQProducer.shutdown();
//
// Thread.sleep(2000);
//
// DefaultMQPushConsumer defaultMQPushConsumer = new DefaultMQPushConsumer("default");
// defaultMQPushConsumer.subscribe("TopicTest", "*");
// defaultMQPushConsumer.setNamesrvAddr("localhost:9876");
//
// /**
// * CLUSTERING:默认模式,同一个ConsumerGroup(groupName相同)每个consumer只消费所订阅消息的一部分内容,同一个ConsumerGroup里所有的Consumer消息加起来才是所
// * 订阅topic整体,从而达到负载均衡的目的
// * BROADCASTING:同一个ConsumerGroup每个consumer都消费到所订阅topic所有消息,也就是一个消费会被多次分发,被多个consumer消费。
// *
// **/
//// defaultMQPushConsumer.setMessageModel(MessageModel.BROADCASTING);
// defaultMQPushConsumer.setConsumeFromWhere(ConsumeFromWhere.CONSUME_FROM_FIRST_OFFSET);
// defaultMQPushConsumer.registerMessageListener((MessageListenerConcurrently) (mgs, context) -> {
// System.out.println(Thread.currentThread().getName()+" Receive New Messages:"+mgs);
// // ConsumeConcurrentlyStatus.RECONSUME_LATER boker会根据设置的messageDelayLevel发起重试,默认16次
// return ConsumeConcurrentlyStatus.CONSUME_SUCCESS;
// });
// defaultMQPushConsumer.start();
// Thread.sleep(2000);
// defaultMQPushConsumer.shutdown();
标签:Thread,ConsumerGroup,defaultMQProducer,defaultMQPushConsumer,sendResult,new,Rock
From: https://www.cnblogs.com/xiongyungang/p/16979575.html