Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/facebook/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
RabbitMQ:将消息发布到多个队列时出现连接问题_Rabbitmq_Rabbitmq Exchange - Fatal编程技术网

RabbitMQ:将消息发布到多个队列时出现连接问题

RabbitMQ:将消息发布到多个队列时出现连接问题,rabbitmq,rabbitmq-exchange,Rabbitmq,Rabbitmq Exchange,我将Map-key中的消息作为队列名称,将值作为消息列表。 每当我将多条消息发布到队列服务器时,服务器都会抛出一个异常,因为用户已达到允许的最大登录次数 将消息发布到1个队列时。下面是执行的代码: public class MessageManager { public static void publish(String exchange, HashMap<String, List<String>> queueNameWithMessages) throws IOEx

我将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();
    } 
}
公共类消息管理器{
公共静态无效发布(字符串交换、HashMap queueNameWithMessages)引发IOException{
...
ConnectionFactory工厂=新的ConnectionFactory();
factory.setHost(Constants.HOST\u NAME);
factory.setUsername(常量.USER\u名称);
factory.setPassword(常量.PASSWORD);
工厂设置端口(常量端口);
Connection Connection=factory.newConnection();
Channel ch=connection.createChannel();
Channel ch1=connection.createChannel();
试一试{
for(条目:queueNameWithMessages){
String routingKey=entry.getKey();
for(字符串messageToBeSent:entry.value()){
ch.basicPublish(exchange、routingKey、true、MessageProperties.PERSISTENT_BASIC、messageToBeSent.getValue().getBytes());
}
ExecutorService threadExecutor=Executors.newFixedThreadPool(5);
字符串responseKey=props.getProperty(routingKey);
如果(!CLAMUtility.WorkingListNerToResponseQueue.contains(responseKey))包含{
Worker fast=新的Worker(0,threadExecutor,ch1,responseKey,routingKey);
CLAMUtility.workingListnerToRespnseQueue.add(responseKey);
}
}
ch.close();
System.out.println(“消息已成功发布!\n\n”);
}捕获(例外e){
e、 printStackTrace();
} 
}

}

我们发现该问题与Rabbit MQ无关。消息使用者系统存在一些未正确处理的与用户交互相关的限制


谢谢

是否将同一消息发布到多个队列?如果是这样,这就是交换的目的。作为一般的最佳实践,您应该始终发布到Exchange,而不是直接发布到队列。我将所有不同的消息发送到每个队列,这就是我应用的循环
条目:queueNameWithMessages
。感谢您对发布交换的快速参考。我希望以这种方式发布“当用户达到允许的最大登录次数时,服务器抛出异常”是什么意思。我不记得RabbitMQ有这种错误消息