Here is how to build a test case that browses all the messages in an IBM MQ Queue without removing them
1. Create a copy of your Queue asset and edit it. Make sure 'PRO' is enabled, find 'Open Options' and click 'Open Editor...', find 'Input Options' and select 'Browse'.
2. Create an IBM MQ Send Receive step. Call it "Start" and make the following changes:
2.1: Disable the 'IBM MQ PUT' section
2.2: Get Queue: Select your "browse" queue asset
2.3: Timeout: Make sure it's something small, like 5 seconds. The only way to know that we've browsed to the end of the queue is to wait for a timeout, so we don't want to wait a long time.
2.4: Get Options: Click 'Open Editor...", find 'Browse Options', click 'Open Editor...', find 'Navigation', select 'Browse First'.
2.5: Scope: Select 'Model'.
3. Create a copy of this step. Call it "Loop". It should be identical to "Start", except for the following change:
3.1: Get Options: Click 'Open Editor...", find 'Browse Options', click 'Open Editor...', find 'Navigation', select 'Browse Next'.
4. Build your test case so the "Loop" step loops back to itself. On both the "Start" and "Loop" steps, change the 'If Timeout' connection from Fail to End, or to another step if you have things that need to happen after all messages are processed. If you need an additional step or steps to process each message then you can insert them in between "Start" and "Loop", and have "Loop" loop back to that step instead of itself. The message processing step can just used {{LASTRESPONSE}} to get the last message body.
> store in any of temp file
I don't think we have a built-in step that just writes stuff to a file. However, You can accomplish this with a pretty simple script step.
1. Use a Script step as the "Process Last Message" step in the above test model.
2. Add a data set to the script step, 'Create a Numeric Counting Data Set'.
2.1. Local: checked
2.2. Property Key: use 'COUNT'
2.3. From: 1
2.4: To: 9999999, just something large
3. Enter the following contents for the script step:
fileName = "C:/<file path>/message" + testExec.getStateValue("COUNT") + ".txt";
messageBody = testExec.getStateValue("LASTRESPONSE");
java.nio.file.Files.write(java.nio.file.FileSystems.getDefault().getPath(fileName), messageBody.getBytes());
Where "<file path>" is wherever you want your message files to go.
Your test should look something like this:
> Note : Messages will be picked from queue when it is more than one consumer. So, whenever message is available in queue. We should store it in any of Temp File.
I don't understand what this means.
> But, it will be complicated when it is 100's or 1000's of messages to validate... In real time my interface is picking 1000's and 10000's of messages from queue in seconds or minimum of 15 minutes time period and reaches to target DB.
My earlier caveat still stands. This method of counting the messages in a queue may not have a well-defined result if messages are being added and removed from the queue at the same time it's being counted. The only way to be 100% sure you have an accurate count, and no other messages arrive or are removed before you are done with your validation, is to use a proxy queue, and have your test case actually move messages from the proxy queue to the live queue as they are being counted.