wu
2024-04-09 b35cea7a306c107eb38e024ea39f6351014ce799
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
package com.mes.service;
 
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;
        // 实例化 RabbitMQUtils 对象
        receiver = new 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 方法发送消息
        RabbitMQUtils.sendMessageWithId("hangzhou2", "Hello RabbitMQ!", "1");
        RabbitMQUtils.sendMessageWithId("hangzhou2", "Another message", "2");
        RabbitMQUtils.sendMessageWithId("hangzhou2", "Another message", "3");
        RabbitMQUtils.sendMessageWithId("hangzhou2", "Another message", "4");
        RabbitMQUtils.sendMessageWithId("hangzhou2", "Another message", "5");
      //  receiver.sendMessageWithId("hangzhou2", "Yet another message", "1"); // 这条消息会打印重复消息的错误信息
 
    }
}