You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
27 lines
929 B
27 lines
929 B
2 years ago
|
package UnitTest;
|
||
|
import org.apache.rocketmq.client.producer.DefaultMQProducer;
|
||
|
import org.apache.rocketmq.client.producer.SendResult;
|
||
|
import org.apache.rocketmq.common.message.Message;
|
||
|
|
||
|
import java.util.UUID;
|
||
|
|
||
|
/**
|
||
|
* @Date 2021-04-20 15:40
|
||
|
*/
|
||
|
public class RocketMqProducer {
|
||
|
|
||
|
public static void main(String[] args) throws Exception {
|
||
|
//声明发送者
|
||
|
DefaultMQProducer producer = new DefaultMQProducer("default_producter_group");
|
||
|
producer.setNamesrvAddr("10.10.14.231:9876");
|
||
|
producer.start();
|
||
|
//发送
|
||
|
String body = "你好 RocketMQ";
|
||
|
Message message = new Message("TopicXuanKe", null, body.getBytes());
|
||
|
message.setKeys(UUID.randomUUID().toString());
|
||
|
SendResult sendResult = producer.send(message);
|
||
|
System.out.printf("发送结果:%s%n", sendResult);
|
||
|
//关闭生产者
|
||
|
producer.shutdown();
|
||
|
}
|
||
|
}
|