in

RabbitMQ Java channel "Closed due to exception from Consumer method handleDelivery for channel AMQChannel" in JavaFX


[*]

I’m trying to set up an amqp RabbitMQ consumer that is connected to a message queue from work. The code works just fine by itself, but as soon as I add it to my JavaFX application and open the channel, it closes with the message Closed due to exception from Consumer method handleDelivery for channel AMQChannel. I’ve tried using the manual acknowledgement as some suggest, but without success. This is the code that I use to connect to the queue:

@NoArgsConstructor
@Getter
@Setter
public final class QueueListener {
    private static QueueListener INSTANCE;

    public static QueueListener getInstance() {
        if(INSTANCE == null) {
            INSTANCE = new QueueListener();
        }

        return INSTANCE;
    }

    public static void setInstance(QueueListener q){
        INSTANCE = q;
    }

    private MainController controller;

    private ConnectionFactory factory;
    private Connection conn;
    private Channel channel;

    private String queue;
    private String host;
    private String username;
    private String password;

    public void connect(String queue, String host, String username, String password) throws IOException, TimeoutException {
        this.queue = queue;
        this.host = host;
        this.username = username;
        this.password = password;

        factory = new ConnectionFactory();
        factory.setUsername(username);
        factory.setPassword(password);
        factory.setHost(host);

        Map<String, Object> qmode = new HashMap<>();
        qmode.put("x-queue-mode", "lazy");
        qmode.put("x-single-active-consumer", true);

        conn = factory.newConnection();
        channel = conn.createChannel();

        channel.addShutdownListener(cause -> System.out.println(cause.getReason()));

        boolean durable = true;
        channel.queueDeclare(queue, durable, false, false, qmode);
        System.out.println(" [*] Waiting for messages. To exit press CTRL+C");

        DeliverCallback deliverCallback = (consumerTag, delivery) -> {
            String message = new String(delivery.getBody(), StandardCharsets.US_ASCII);

            message = message.replaceAll("u000D", "");

            System.out.println(message);
            MyLogger.logger.info(message);
            controller.parseData(message);
        };
        boolean autoAck = true;
        channel.basicConsume(queue, autoAck, deliverCallback, consumerTag -> {});
    }

    public void closeConnection() throws IOException, TimeoutException {
        channel.close();
        conn.close();
    }

    public void setController(MainController controller){
        this.controller = controller;
    }
}

[*]
[*] Source: https://stackoverflow.com/questions/70633094/rabbitmq-java-channel-closed-due-to-exception-from-consumer-method-handledelive

a generic framework for implementing next-generation distributed applications and systems

a classic doom and wolfenstein3D like game made in Python, using the famous PYGAME module