Ad

How To Re-send ActiveMQ Messages That Were Not Acknowledged?

- 1 answer

I am working on a socket IO application that consumes messages from an ActiveMQ queue. I am using stomp library for Node JS

For the most part, it works fine but I need to be able to re-send un-acknowledged messages. The messages for which amq.ack(message) was skipped are not being re-tried and displayed as pending the ActiveMQ web console. Is there a way by which I can re-send them?

const subscribeHeaders = {
    destination,
    ack: 'client-individual'
};

amq.subscribe(subscribeHeaders, (error, message) => {
    if (error) {
        logger.error(`subscribe error ${error.message}`);
        return;
    }

    message.readString('utf-8', (err, body) => {
        if (err) {
            logger.error(`read message error ${err.message}`);
            return;
        }
        const notificationData = JSON.parse(body);

        const { deviceId } = notificationData;

        if (io.sockets.adapter.rooms[deviceId]) {
            io.to(deviceId).emit('notification', notificationData);
            amq.ack(message);
        }
    });
});
Ad

Answer

If you are not acknowledging messages they remain in pending until such time as you either acknowledge them or you close the consumer (or connection) that they are locked to. In you case you might be able to get away with a STOMP unsubscribe of that subscription as a way to release and have those messages be redispatched to another consumer.

Ad
source: stackoverflow.com
Ad