Open coderElijah opened 6 years ago
RocketMQProducerTemplate / https://github.com/rocketmq/rocketmq-samples
Send message sample code
public static void main(String[] args) throws Exception { //Instantiate with a producer group name. DefaultMQProducer producer = new DefaultMQProducer("please_rename_unique_group_name"); //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 / ); //Call send message to deliver message to one of brokers. SendResult sendResult = producer.send(msg); System.out.printf("%s%n", sendResult); } //Shut down once the producer instance is not longer in use. producer.shutdown(); }
要自己shutdown?有没有连接池的概念在里面的?可以用到生产环境吗,需要不需要自己搞连接池?
生产端是直接使用 @Autowired RocketMQproducer rocketmqproducer; rocketmqproducer.send(); 来进行消息推送的么 在使用的时候总是找不到这个bean