As an IBM Websphere MQ administrator we come across several situations where in we need to create a lot of IBM Websphere MQ components as a part of an implementation and creation of these components manually could be a tedious job which might also be prone to errors sometimes. To overcome this tedious work, we will learn how to create IBM Websphere MQ components using a batch file through which the mqsc commands can be executed to create queues, channels, topics, subscriptions, listeners, clusters and other MQ components. A batch file is a script file used in Windows through which a series of commands can be executed which are stored in a plain text file.
Pre-Requisites:
- IBM Websphere MQ should be installed in a system operating in Microsoft Windows OS
- The user executing the batch script should have access to create MQ components in the IBM Websphere MQ Queue Manager
Batch file:
Name: QueueCreation.bat
@echo off
REM ##### Author: Karthik Selvaraj #####
REM ##### Description: Batch script to create local queues #####
REM ##### Version: 0.1 #####
REM ##### Published Date: 06 Oct 2016 #####
REM ##### Script Usage: QueueCreation.bat <<Queue Manager Name>> #####
REM ##### Defining local queue for a Test Queue #####
@echo DEFINE QLOCAL (TESTQUEUE) + >>Script.txt
@echo DESCR(‘Queue for Test’) + >>Script.txt
@echo PUT (ENABLED) + >>Script.txt
@echo GET (ENABLED) + >>Script.txt
@echo NOTRIGGER + >>Script.txt
@echo MSGDLVSQ (PRIORITY) + >>Script.txt
@echo MAXDEPTH (5000) + >>Script.txt
@echo MAXMSGL (4194304) + >>Script.txt
@echo USAGE (NORMAL) >>Script.txt >>Script.txt
runmqsc %1 < Script.txt >> Logs.txt
del Script.txt
Batch file usage:
QueueCreation.bat <<Queue Manager Name>>
Note: In this example the queue manager in which the local queue will be created is “DEMOQM”
Batch file Explained:
@echo off
The echo off function will not display the output in command prompt
REM ##### Author: Karthik Selvaraj #####
REM ##### Description: Batch script to create local queues #####
REM ##### Version: 0.1 #####
REM ##### Published Date: 05 Oct 2016 #####
REM ##### Script Usage: QueueCreation.bat <<Queue Manager Name>> #####
REM ##### Defining local queue for a Test Queue #####
REM command is used to comment in a batch file. It’s a good practice to mention the author, script description, Version, Published date and script usage details as a comment.
echo DEFINE QLOCAL (TESTQUEUE) + >>Script.txt
@echo DESCR(‘Queue for Test’) + >>Script.txt
@echo PUT (ENABLED) + >>Script.txt
@echo GET (ENABLED) + >>Script.txt
@echo NOTRIGGER + >>Script.txt
@echo MSGDLVSQ (PRIORITY) + >>Script.txt
@echo MAXDEPTH (5000) + >>Script.txt
@echo MAXMSGL (4194304) + >>Script.txt
@echo USAGE (NORMAL) >>Script.txt >>Script.txt
A definition text file (Script.txt) to create local queue using mqsc command is created in the folder in which the batch file is executed.
runmqsc %1 < Script.txt >> Logs.txt
The input argument to the runmqsc command will be the queue manager name which will be passed during the invocation of the batch script. The file from which the mqsc commands will be executed is Script.txt. The results of the mqsc commands executed are redirected to a file named Logs.txt in the directory in which the batch file is executed.
del Script.txt
Once the mqsc commands are executed from the Script file, the file is deleted from the directory.
Script.txt:
DEFINE QLOCAL (TESTQUEUE) +
DESCR(‘Queue for Test’) +
PUT (ENABLED) +
GET (ENABLED) +
NOTRIGGER +
MSGDLVSQ (PRIORITY) +
MAXDEPTH (5000) +
MAXMSGL (4194304) +
USAGE (NORMAL)
Logs.txt:
5724-H72 (C) Copyright IBM Corp. 1994, 2015.
Starting MQSC for queue manager DEMOQM.
1 : DEFINE QLOCAL (TESTQUEUE) +
: DESCR(‘Queue for Test’) +
: PUT (ENABLED) +
: GET (ENABLED) +
: NOTRIGGER +
: MSGDLVSQ (PRIORITY) +
: MAXDEPTH (5000) +
: MAXMSGL (4194304) +
: USAGE (NORMAL)
AMQ8006: WebSphere MQ queue created.
One MQSC command read.
No commands have a syntax error.
All valid MQSC commands were processed.
Local Queue Created in Queue Manager “DEMOQM”: