1

在我的 RabbitMQ 应用程序中,生产者发送消息,但消费者只接收其中的一部分(不是最大的)。当我rabbitmqctl list_queues在终端执行时,它显示:

~$ sudo rabbitmqctl list_queues
Listing queues ...    
MdnaMessagesQueue   0
...done.

这意味着消息会丢失到队列中,或者它们很快就会从队列中取出。所以我不明白为什么会这样。我没有其他可以从该队列获取消息的应用程序。这是我的生产者代码:

public class Sender {
    private static final String QUEUE_NAME = "MdnaMessagesQueue";

    public void send(byte[] message) throws IOException {

        AMQP.BasicProperties.Builder bob = new AMQP.BasicProperties.Builder();
        AMQP.BasicProperties minBasic = bob.build();
        AMQP.BasicProperties minPersistentBasic = bob.deliveryMode(2).build();

        ExecutorService service = Executors.newFixedThreadPool(10);
        ConnectionFactory factory = new ConnectionFactory();
        factory.setHost("localhost");
        Connection connection = factory.newConnection(service);
        Channel channel = connection.createChannel();
        channel.queueDeclare(QUEUE_NAME, true, false, false, null);
        channel.basicPublish("", QUEUE_NAME, MessageProperties.PERSISTENT_TEXT_PLAIN, message);
        channel.close();
        connection.close();
    }
}
4

0 回答 0