How to move JMS messages between destinations in WildFly

In this article, we will learn how to move messages from one JMS destination into another running on WildFly application server. We will also be using a filter to move messages selectively.

Firstly, let’s start create the following example JMS Destinations:

jms-queue add --queue-address=queueA --entries=java:/jms/queue/queueA 
jms-queue add --queue-address=queueB --entries=java:/jms/queue/queueB

Next, in order to move messages from queueA into queueB, you can use the following CLI command:


Finally, consider that it is possible to use a filter when moving messages, using a message property as filter:


Please notice that one common use case is moving messages from the Dead Letter Queue to another Queue. In this case, in order to move selectively only messages that were destined to one destination (for example, queueA), you can filter through the property “_AMQ_ORIG_QUEUE“.

Here is, for example, how to restore messages from the DLQ (whose destination was queueA) into the queueB:


You can achieve the same result, by listening to the DLQ, and filtering messages to be moved within the onMessage method:

public void onMessage(Message message) {
   try {
        String queueDestination = "queueB";
            if (message.getStringProperty("_AMQ_ORIG_QUEUE").equals("queueA")) {
               Queue queue = session.createQueue(queueDestination);
               MessageProducer messageProducer = session.createProducer(queue);

    } catch (JMSException e) {