rocketmq / rocketmq-spring-boot-starter

Help developers quickly integrate RocketMQ in Spring Boot. Support the Spring Message specification to facilitate developers to quickly switch from other MQ to RocketMQ.
https://www.rocketmq.org
Apache License 2.0
77 stars 22 forks source link

producer #2

Open coderElijah opened 6 years ago

coderElijah commented 6 years ago

生产端是直接使用 @Autowired RocketMQproducer rocketmqproducer; rocketmqproducer.send(); 来进行消息推送的么 在使用的时候总是找不到这个bean

he-jialin commented 6 years ago

RocketMQProducerTemplate / https://github.com/rocketmq/rocketmq-samples

he-jialin commented 6 years ago

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(); }

jialechan commented 6 years ago

要自己shutdown?有没有连接池的概念在里面的?可以用到生产环境吗,需要不需要自己搞连接池?