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"); // 这条消息会打印重复消息的错误信息
|
|
}
|
}
|
|