美文网首页
RocketMQ-异步消息

RocketMQ-异步消息

作者: 快点给我想个名 | 来源:发表于2019-06-23 22:28 被阅读0次
    异步消息
    • 生产者
    public class Producer{
    
        public static void main(String[] args) throws Exception {
            //Instantiate with a producer group name.
            DefaultMQProducer producer = new
                    DefaultMQProducer("please_rename_unique_group_name");
            // Specify name server addresses.
            producer.setNamesrvAddr("localhost:9876");
            //Launch the instance.
            producer.start();
            for (int i = 0; i < 100; i++) {
                //Create a message instance, specifying topic, tag and message body.
                Message msg = new Message("TopicTest" /* Topic */,
                        "TagA" /* Tag */,
                        ("Hello RocketMQ " +
                                i).getBytes(RemotingHelper.DEFAULT_CHARSET) /* Message body */
                );
               //异步发送消息
               producer.send(msg, new SendCallback() {
                   @Override
                   public void onSuccess(SendResult sendResult) {
    
                   }
    
                   @Override
                   public void onException(Throwable throwable) {
    
                   }
               });
            }
            //Shut down once the producer instance is not longer in use.
            //producer.shutdown();
        }
    
    }
    

    相关文章

      网友评论

          本文标题:RocketMQ-异步消息

          本文链接:https://www.haomeiwen.com/subject/inwwqctx.html