Producer.java
package com.dym.one2many;
//发送消息
import org.apache.rocketmq.client.exception.MQBrokerException;
import org.apache.rocketmq.client.exception.MQClientException;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import org.apache.rocketmq.remoting.exception.RemotingException;
public class Producer {
public static void main(String[] args) throws MQClientException, RemotingException, InterruptedException, MQBrokerException {
//1. 谁来发?
DefaultMQProducer producer = new DefaultMQProducer("group1");
//2. 发给谁?
producer.setNamesrvAddr("localhost:9876");
producer.start();
// 3. 怎么发?
// 4. 发什么?
for(int i=1;i<11;i++){
String msg="hello rocketmq"+i;
Message