As an IT pro who manages IBM MQ, you know how crucial it is to be able to reliably and efficiently copy messages between queues. Whether you need to migrate messages to a new queue, troubleshoot issues by extracting messages, or keep development and production environments in sync – having robust tools for copying messages is a must-have skill for any MQ admin.
In this comprehensive guide, I‘ll walk you through the ins and outs of copying messages between MQ queues using the built-in dmpmqmsg utility. From basic queue-to-queue copying all the way to advanced techniques, you‘ll learn the tips and tricks to master dmpmqmsg.
By the end, you‘ll be an MQ message copying guru! Let‘s get started, friend.
An Overview of IBM‘s dmpmqmsg Tool
IBM provides the dmpmqmsg command-line utility for copying messages between queues. Here‘s a quick rundown of what it is and how it works:
dmpmqmsgcomes included with every MQ installation, usually under/opt/mqm/bin- It must be run by an MQ admin user like
mqmormqadmin - It copies messages from a source queue to a target queue
- It preserves all message properties like persistence, priority, expiration, etc.
The basic syntax is:
dmpmqmsg -m QueueManager -i SourceQueue -o TargetQueue
This copies all messages from SourceQueue to TargetQueue under queue manager QueueManager. Pretty simple right?
But dmpmqmsg has a lot more capabilities under the hood. Keep reading as I uncover more of its power.
First up, let‘s look at copying between local queues…
Copying Messages Between Local Queues
The most common scenario is copying messages between two local queues belonging to the same queue manager.
For example, let‘s say you want to copy messages from the LOCAL.INBOX queue to the LOCAL.SENT queue on a queue manager named QM1.
Here‘s how that looks with dmpmqmsg:
dmpmqmsg -m QM1 -i LOCAL.INBOX -o LOCAL.SENT
To verify it worked, you can check the queue depths before and after:
dis ql(LOCAL.INBOX)
AMQ8409: Display Queue details.
QUEUE(LOCAL.INBOX)
CURDEPTH(10)
dis ql(LOCAL.SENT)
AMQ8409: Display Queue details.
QUEUE(LOCAL.SENT)
CURDEPTH(0)
dmpmqmsg -m QM1 -i LOCAL.INBOX -o LOCAL.SENT
dis ql(LOCAL.INBOX)
AMQ8409: Display Queue details.
QUEUE(LOCAL.INBOX)
CURDEPTH(0)
dis ql(LOCAL.SENT)
AMQ8409: Display Queue details.
QUEUE(LOCAL.SENT)
CURDEPTH(10)
As you can see, the 10 messages moved from LOCAL.INBOX to LOCAL.SENT while preserving all their properties. Pretty nifty!
Now let‘s look at copying between remote queues…
Transferring Messages Between Remote Queues
One of dmpmqmsg‘s best features is copying messages between queues on different queue managers.
This enables powerful workflows like:
- Migrating messages from a test to production environment
- Extracting messages from remote servers for debugging
- Centralized copying from many agents to a single processing queue
For remote copying, you simply use the fully qualified queue name syntax like:
dmpmqmsg -m QM1 -i QM2.REMOTE.INBOX -o QM1.LOCAL.SENT
Here we‘re copying messages from the REMOTE.INBOX queue on QM2 into the LOCAL.SENT queue on QM1.
As you might expect, there must be a communication channel defined between the two queue managers for this to work.
The major MQ interconnect options like SVRCONN channels, cluster channels, and TLS/VPN tunnels all support dmpmqmsg message copying between remote queues.
Selectively Copying Messages
Now this is where dmpmqmsg really shines…
So far we‘ve been copying all messages from one queue to another. But you can also selectively copy messages based on ID, correlation ID, or other criteria.
For example, to copy only message ID 15 from a queue:
dmpmqmsg -m QM1 -i 15 -o TARGET.QUEUE
Or to copy a range of messages from ID 100 to 200:
dmpmqmsg -m QM1 -i ‘100:200‘ -o TARGET.QUEUE
You can also filter on correlation ID, Put date, or other message properties using a syntax like:
dmpmqmsg -m QM1 -i ‘CorrelID=XYZ‘ -o TARGET.QUEUE
This flexibility makes dmpmqmsg invaluable for extracting specific messages for debugging or auditing purposes.
You can even chain together multiple selection criteria, like copying messages between two dates with a certain correlation ID. The combinations are endless!
Preserving Message Properties
A key benefit of using dmpmqmsg is that it preserves the full set of MQ message properties when copying, including:
- Persistence – Messages stay persistent or non-persistent
- Priority – The message priority from 0-9 is maintained
- Expiration – Any message expiration set is honored
- Format – The message format, like RFH2 headers, is unchanged
The only property not preserved is the original Put date/time. The message receives a new Put date when copied to the destination queue.
This consistency means you can copy messages around with confidence without inadvertently losing critical metadata properties.
Handling Cluster Queue Quirks
dmpmqmsg can copy messages to and from cluster queues, but there are some specific behaviors you need to know:
- For one-way cluster sender queues, you can only copy messages from the queue, not to the queue
- For cluster receiver queues, you can only copy messages to the queue, not from the queue
- For full cluster repositories, you can copy messages both to and from the queue
This relates to how IBM MQ handles message flow internally on cluster queues. The key is checking whether your cluster queue is a sender, receiver, or repository before attempting to copy with dmpmqmsg.
Coping with Large Message Volumes
When dealing with queues that have large volumes of messages, you may run into limitations with dmpmqmsg.
By default, it dumps messages to a temporary file with a max size of 1GB. Once that limit is reached, you‘ll get errors like:
MQDMP0001: An internal error occurred...
MQDMP0002: Internal error details...
MQLIMITEXCEEDED: Message file limit exceeded
There are a few ways to work around this:
- Use message ID selection to copy in smaller batches
- Increase the
MSGFILESZparameter inqm.ini - Write messages to file first, then reload into target queue with
amqsput
With a little performance tuning, you can use dmpmqmsg to efficiently copy millions of messages between queues.
Automating Message Copying with Scripts
Since it‘s a simple command-line program, dmpmqmsg lends itself well to automation via scripts.
Let‘s look at a Bash script that copies any messages less than 2 days old from an INBOX queue to an ARCHIVE queue:
#!/bin/bash
SOURCE_QUEUE=INBOX
TARGET_QUEUE=ARCHIVE
CUTOFF=$(date -d ‘2 days ago‘ +%Y%m%d)
dmpmqmsg -m QM1 -i "‘PutDate<$CUTOFF‘" -o $TARGET_QUEUE
We use the PutDate filter to selectively grab older messages. This script could easily be setup as a cron job to keep archiving older messages automatically.
There are tons of possibilities for scripting dmpmqmsg to match your specific workflow needs.
Key Takeaways and Best Practices
Alright, we‘ve covered a ton of ground on effectively using dmpmqmsg for message copying in IBM MQ. Let‘s recap some key learnings:
✅ Use dmpmqmsg for local or remote queue-to-queue copying
✅ Selectively filter messages based on ID, correlation ID, or other headers
✅ Remember it preserves properties like persistence, priority, expiration
✅ Handle large volumes by tuning MSGFILESZ and copying in batches
✅ Automate repeat copying tasks with simple shell scripts
✅ Check cluster queue type before attempting one-way copies
Mastering dmpmqmsg is a critical skill for any MQ administrator. Whether you need to migrate queues, populate test environments, extract messages for diagnostics, or keep archives in sync, having robust message copying capabilities makes life much easier.
I hope this guide gave you a full understanding of how to unleash the power of dmpmqmsg for your own IBM MQ needs. Never hesitate to reach out if you need help applying these techniques in your own environment!