我在Map中有消息 - key作为队列名称,值作为消息列表。 每当我向队列服务器发布多个消息时,就会抛出异常,因为用户已达到允许的最大登录次数。
将消息发布到1个队列时。下面是执行的代码:
public class MessageManager {
public static void publish(String exchange, HashMap<String, List<String>> queueNameWithMessages) throws IOException {
...
ConnectionFactory factory = new ConnectionFactory();
factory.setHost(Constants.HOST_NAME);
factory.setUsername(Constants.USER_NAME);
factory.setPassword(Constants.PASSWORD);
factory.setPort(Constants.PORT);
Connection connection = factory.newConnection();
Channel ch = connection.createChannel();
Channel ch1 = connection.createChannel();
try {
for(Entry<String, List<String>> entry : queueNameWithMessages) {
String routingKey = entry.getKey();
for(String messageToBeSent : entry.value()) {
ch.basicPublish(exchange, routingKey, true, MessageProperties.PERSISTENT_BASIC, messageToBeSent.getValue().getBytes());
}
ExecutorService threadExecutor = Executors.newFixedThreadPool(5);
String responseKey = props.getProperty(routingKey);
if(!CLAMUtility.workingListnerToRespnseQueue.contains(responseKey)) {
Worker fast = new Worker(0, threadExecutor, ch1,responseKey, routingKey);
CLAMUtility.workingListnerToRespnseQueue.add(responseKey);
}
}
ch.close();
System.out.println("Message published successfully!\n \n");
} catch (Exception e) {
e.printStackTrace();
}
}
}
答案 0 :(得分:0)
我们发现此问题与Rabbit MQ无关。消息使用者系统具有一些与用户交互相关的限制,这些限制未得到妥
谢谢!