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:

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; = host;
        this.username = username;
        this.password = password;

        factory = new ConnectionFactory();

        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", "");

        boolean autoAck = true;
        channel.basicConsume(queue, autoAck, deliverCallback, consumerTag -> {});

    public void closeConnection() throws IOException, TimeoutException {

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

[*] Source:

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