| | |
| | | package com.mes.service;
|
| | |
|
| | | import com.rabbitmq.client.Channel;
|
| | | import com.rabbitmq.client.Connection;
|
| | | import com.rabbitmq.client.ConnectionFactory;
|
| | |
|
| | | import java.util.HashMap;
|
| | | import java.util.Map;
|
| | | import com.mes.common.RabbitMQUtils;
|
| | |
|
| | | public class ModuleA {
|
| | | private static String QUEUE_NAME = "hangzhou2";
|
| | | private static RabbitMQUtils receiver;
|
| | |
|
| | | public ModuleA(String QUEUENAME){
|
| | | QUEUE_NAME=QUEUENAME;
|
| | | public ModuleA(String QUEUENAME) {
|
| | | QUEUE_NAME = QUEUENAME;
|
| | | receiver = new RabbitMQUtils(); // 实例化 RabbitMQUtils 对象
|
| | | }
|
| | |
|
| | | public static void main(String[] argv) throws Exception {
|
| | | // ModuleA moduleA = new ModuleA("hangzhou2"); // 实例化 ModuleA 对象
|
| | | // String message = "Your message to send666";
|
| | | // String messageId = "5"; // 消息ID
|
| | | // receiver.sendMessageWithId(QUEUE_NAME, message, messageId); // 调用 sendMessageWithId 方法发送消息
|
| | | receiver.sendMessageWithId("hangzhou2", "Hello RabbitMQ!", "1");
|
| | | receiver.sendMessageWithId("hangzhou2", "Another message", "2");
|
| | | receiver.sendMessageWithId("hangzhou2", "Yet another message", "1"); // 这条消息会打印重复消息的错误信息
|
| | |
|
| | | public static void main(String[] argv) throws Exception {
|
| | | // 创建连接工厂
|
| | | |
| | | }
|
| | | public void f(){
|
| | | |
| | | }
|
| | | }
|
| | |
|