Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

producer #2

Open
coderElijah opened this issue May 12, 2018 · 3 comments
Open

producer #2

coderElijah opened this issue May 12, 2018 · 3 comments

Comments

@coderElijah
Copy link

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

@he-jialin
Copy link
Member

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

@he-jialin
Copy link
Member

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
Copy link

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

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants