-
Notifications
You must be signed in to change notification settings - Fork 0
/
amqsh.c
371 lines (313 loc) · 20.5 KB
/
amqsh.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
/******************************************************************************/
/* based on amqsail IBM MQ sample */
/* amqsh has 1 parameter - the queue manager name (optional) */
/* */
/******************************************************************************/
/******************************************************************************/
/* Includes */
/******************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <cmqc.h> /* MQI */
#include <cmqcfc.h> /* PCF */
#include <cmqbc.h> /* MQAI */
/******************************************************************************/
/* Function prototypes */
/******************************************************************************/
void CheckCallResult(MQCHAR *, MQLONG , MQLONG);
/******************************************************************************/
/* Function: main */
/******************************************************************************/
int main(int argc, char *argv[])
{
/***************************************************************************/
/* MQAI variables */
/***************************************************************************/
MQHCONN hConn; /* handle to MQ connection */
MQCHAR qmName[MQ_Q_MGR_NAME_LENGTH+1]=""; /* default QMgr name */
MQLONG reason; /* reason code */
MQLONG connReason; /* MQCONN reason code */
MQLONG compCode; /* completion code */
MQHBAG adminBag = MQHB_UNUSABLE_HBAG; /* admin bag for mqExecute */
MQHBAG responseBag = MQHB_UNUSABLE_HBAG;/* response bag for mqExecute */
MQHBAG qAttrsBag; /* bag containing q attributes */
MQHBAG errorBag; /* bag containing cmd server error */
MQLONG mqExecuteCC; /* mqExecute completion code */
MQLONG mqExecuteRC; /* mqExecute reason code */
MQLONG qNameLength; /* Actual length of q name */
MQLONG qClusterLength; /* Actual length of q name */
MQLONG qDepth; /* depth of queue */
MQLONG maxDdepth; /* max depth of queue */
MQLONG qType; /* type of queue */
MQLONG openIC; /* open input count */
MQLONG openOC; /* open output count */
MQCHAR qCluster[MQ_CLUSTER_NAME_LENGTH+1]; /* name of queue extracted from bag*/
MQCHAR xmitQ[MQ_Q_NAME_LENGTH+1]; /* name of queue extracted from bag*/
MQLONG i; /* loop counter */
MQLONG numberOfBags; /* number of bags in response bag */
MQCHAR qName[MQ_Q_NAME_LENGTH+1]; /* name of queue extracted from bag*/
char *qTypePrint;
printf("Display all queues\n");
printf("%-48s %10s %10s %8s %3s %3s %-36s %-9s\n", "Queue Name","QueueDepth","MaxDepth","Cluster","OIC","OOC","XMITQ","Type");
printf("%-48s %10s %10s %8s %3s %3s %-36s %-9s\n","------------------------------------------------","----------","----------","--------","---","---","------------------------------------","---------");
/***************************************************************************/
/* Connect to the queue manager */
/***************************************************************************/
if (argc > 1)
strncpy(qmName, argv[1], (size_t)MQ_Q_MGR_NAME_LENGTH);
MQCONN(qmName, &hConn, &compCode, &connReason);
/***************************************************************************/
/* Report the reason and stop if the connection failed. */
/***************************************************************************/
if (compCode == MQCC_FAILED)
{
CheckCallResult("Queue Manager connection", compCode, connReason);
exit( (int)connReason);
}
/***************************************************************************/
/* Create an admin bag for the mqExecute call */
/***************************************************************************/
mqCreateBag(MQCBO_ADMIN_BAG, &adminBag, &compCode, &reason);
CheckCallResult("Create admin bag", compCode, reason);
/***************************************************************************/
/* Create a response bag for the mqExecute call */
/***************************************************************************/
mqCreateBag(MQCBO_ADMIN_BAG, &responseBag, &compCode, &reason);
CheckCallResult("Create response bag", compCode, reason);
/***************************************************************************/
/* Put the generic queue name into the admin bag */
/***************************************************************************/
mqAddString(adminBag, MQCA_Q_NAME, MQBL_NULL_TERMINATED, "*", &compCode, &reason);
CheckCallResult("Add q name", compCode, reason);
/***************************************************************************/
/* Put the local queue type into the admin bag */
/***************************************************************************/
mqAddInteger(adminBag, MQIA_Q_TYPE, MQQT_ALL, &compCode, &reason);
CheckCallResult("Add q type", compCode, reason);
/***************************************************************************/
/* Send the command to find all the local queue names and queue depths. */
/* The mqExecute call creates the PCF structure required, sends it to */
/* the command server, and receives the reply from the command server into */
/* the response bag. The attributes are contained in system bags that are */
/* embedded in the response bag, one set of attributes per bag. */
/***************************************************************************/
mqExecute(hConn, /* MQ connection handle */
MQCMD_INQUIRE_Q, /* Command to be executed */
MQHB_NONE, /* No options bag */
adminBag, /* Handle to bag containing commands */
responseBag, /* Handle to bag to receive the response*/
MQHO_NONE, /* Put msg on SYSTEM.ADMIN.COMMAND.QUEUE*/
MQHO_NONE, /* Create a dynamic q for the response */
&compCode, /* Completion code from the mqexecute */
&reason); /* Reason code from mqexecute call */
/***************************************************************************/
/* Check the command server is started. If not exit. */
/***************************************************************************/
if (reason == MQRC_CMD_SERVER_NOT_AVAILABLE)
{
printf("Please start the command server: <strmqcsv QMgrName>\n");
MQDISC(&hConn, &compCode, &reason);
CheckCallResult("Disconnect from Queue Manager", compCode, reason);
exit(98);
}
/***************************************************************************/
/* Check the result from mqExecute call. If successful find the current */
/* depths of all the local queues. If failed find the error. */
/***************************************************************************/
if ( compCode == MQCC_OK ) /* Successful mqExecute */
{
/*************************************************************************/
/* Count the number of system bags embedded in the response bag from the */
/* mqExecute call. The attributes for each queue are in a separate bag. */
/*************************************************************************/
mqCountItems(responseBag, MQHA_BAG_HANDLE, &numberOfBags, &compCode, &reason);
CheckCallResult("Count number of bag handles", compCode, reason);
for ( i=0; i<numberOfBags; i++)
{
/***********************************************************************/
/* Get the next system bag handle out of the mqExecute response bag. */
/* This bag contains the queue attributes */
/***********************************************************************/
mqInquireBag(responseBag, MQHA_BAG_HANDLE, i, &qAttrsBag, &compCode, &reason);
CheckCallResult("Get the result bag handle", compCode, reason);
/***********************************************************************/
/* Get the queue name out of the queue attributes bag */
/***********************************************************************/
mqInquireString(qAttrsBag, MQCA_Q_NAME, 0, MQ_Q_NAME_LENGTH, qName,
&qNameLength, NULL, &compCode, &reason);
CheckCallResult("Get queue name", compCode, reason);
/***********************************************************************/
/* Get the type out of the queue attributes bag */
/***********************************************************************/
mqInquireInteger(qAttrsBag, MQIA_Q_TYPE, MQIND_NONE, &qType,
&compCode, &reason);
CheckCallResult("Get depth", compCode, reason);
if (!strstr(qName, "SYSTEM") && !strstr(qName, "MQAI")) {
switch(qType) {
case 1 :
qTypePrint = "LOCAL";
/***********************************************************************/
/* Get the depth out of the queue attributes bag */
/***********************************************************************/
mqInquireInteger(qAttrsBag, MQIA_CURRENT_Q_DEPTH, MQIND_NONE, &qDepth,
&compCode, &reason);
CheckCallResult("Get depth", compCode, reason);
/***********************************************************************/
/* Get the type out of the queue attributes bag */
/***********************************************************************/
mqInquireInteger(qAttrsBag, MQIA_MAX_Q_DEPTH, MQIND_NONE, &maxDdepth,
&compCode, &reason);
CheckCallResult("Get depth", compCode, reason);
/***********************************************************************/
/* Get the type out of the queue attributes bag MQIA_OPEN_INPUT_COUNT */
/***********************************************************************/
mqInquireInteger(qAttrsBag, MQIA_OPEN_INPUT_COUNT, MQIND_NONE, &openIC,
&compCode, &reason);
CheckCallResult("Get depth", compCode, reason);
/***********************************************************************/
/* Get the type out of the queue attributes bag MQIA_OPEN_INPUT_COUNT */
/***********************************************************************/
mqInquireInteger(qAttrsBag, MQIA_OPEN_OUTPUT_COUNT, MQIND_NONE, &openOC,
&compCode, &reason);
CheckCallResult("Get depth", compCode, reason);
/***********************************************************************/
/* Get the type out of the queue attributes bag MQIA_OPEN_INPUT_COUNT */
/***********************************************************************/
mqInquireString(qAttrsBag, MQCA_CLUSTER_NAME, 0, MQ_CLUSTER_NAME_LENGTH, qCluster,
&qClusterLength, NULL, &compCode, &reason);
CheckCallResult("Get queue name", compCode, reason);
/***********************************************************************/
/* Use mqTrim to prepare the queue name for printing. */
/* Print the result. */
/***********************************************************************/
mqTrim(MQ_Q_NAME_LENGTH, qName, qName, &compCode, &reason);
mqTrim(MQ_CLUSTER_NAME_LENGTH, qCluster, qCluster, &compCode, &reason);
if (strlen(qCluster) == 0) { strcpy(qCluster,"(null)"); }
printf("%-48s %10ld %10ld %8s %3ld %3ld %-36s %-9s\n", qName, qDepth, maxDdepth, qCluster, openIC, openOC, "-" ,qTypePrint);
break;
case 2 :
qTypePrint = "MODEL";
mqTrim(MQ_Q_NAME_LENGTH, qName, qName, &compCode, &reason);
mqTrim(MQ_CLUSTER_NAME_LENGTH, qCluster, qCluster, &compCode, &reason);
if (strlen(qCluster) == 0) { strcpy(qCluster,"(null)"); }
printf("%-48s %10s %10s %8s %3s %3s %-36s %-9s\n", qName, "-", "-", qCluster, "-", "-", "-" ,qTypePrint);
break;
case 3 :
qTypePrint = "ALIAS";
/***********************************************************************/
/* Get the type out of the queue attributes bag MQIA_OPEN_INPUT_COUNT */
/***********************************************************************/
mqInquireString(qAttrsBag, MQCA_CLUSTER_NAME, 0, MQ_CLUSTER_NAME_LENGTH, qCluster,
&qClusterLength, NULL, &compCode, &reason);
CheckCallResult("Get queue name", compCode, reason);
mqTrim(MQ_Q_NAME_LENGTH, qName, qName, &compCode, &reason);
mqTrim(MQ_CLUSTER_NAME_LENGTH, qCluster, qCluster, &compCode, &reason);
if (strlen(qCluster) == 0) { strcpy(qCluster,"(null)"); }
printf("%-48s %10s %10s %8s %3s %3s %-36s %-9s\n", qName, "-", "-", qCluster, "-", "-", "-" ,qTypePrint);
break;
case 6 :
qTypePrint = "REMOTE";
/***********************************************************************/
/* Get the type out of the queue attributes bag MQIA_OPEN_INPUT_COUNT */
/***********************************************************************/
mqInquireString(qAttrsBag, MQCA_CLUSTER_NAME, 0, MQ_CLUSTER_NAME_LENGTH, qCluster,
&qClusterLength, NULL, &compCode, &reason);
CheckCallResult("Get queue name", compCode, reason);
/***********************************************************************/
/* Get the type out of the queue attributes bag MQIA_OPEN_INPUT_COUNT */
/***********************************************************************/
mqInquireString(qAttrsBag, MQCA_XMIT_Q_NAME, 0, MQ_Q_NAME_LENGTH, xmitQ,
&qNameLength, NULL, &compCode, &reason);
CheckCallResult("Get queue name", compCode, reason);
mqTrim(MQ_Q_NAME_LENGTH, qName, qName, &compCode, &reason);
mqTrim(MQ_CLUSTER_NAME_LENGTH, qCluster, qCluster, &compCode, &reason);
mqTrim(MQ_Q_NAME_LENGTH, xmitQ, xmitQ, &compCode, &reason);
if (strlen(qCluster) == 0) { strcpy(qCluster,"(null)"); }
if (strlen(xmitQ) == 0) { strcpy(xmitQ,"???"); }
printf("%-48s %10s %10s %8s %3s %3s %-36s %-9s\n", qName, "-", "-", qCluster, "-", "-", xmitQ ,qTypePrint);
break;
default : /* Optional */
// qTypePrint = "OTHER";
mqTrim(MQ_Q_NAME_LENGTH, qName, qName, &compCode, &reason);
mqTrim(MQ_CLUSTER_NAME_LENGTH, qCluster, qCluster, &compCode, &reason);
printf("%-48s %10ld %10ld %8s %3ld %3ld %36s %-9s\n", qName, "qDepth", "maxDdepth", "qCluster", "openIC", "openOC", "XMITQ" ,qTypePrint);
}
}
}
}
else /* Failed mqExecute */
{
printf("Call to get queue attributes failed: Completion Code = %d : Reason = %d\n",
compCode, reason);
/*************************************************************************/
/* If the command fails get the system bag handle out of the mqexecute */
/* response bag.This bag contains the reason from the command server */
/* why the command failed. */
/*************************************************************************/
if (reason == MQRCCF_COMMAND_FAILED)
{
mqInquireBag(responseBag, MQHA_BAG_HANDLE, 0, &errorBag, &compCode, &reason);
CheckCallResult("Get the result bag handle", compCode, reason);
/***********************************************************************/
/* Get the completion code and reason code, returned by the command */
/* server, from the embedded error bag. */
/***********************************************************************/
mqInquireInteger(errorBag, MQIASY_COMP_CODE, MQIND_NONE, &mqExecuteCC,
&compCode, &reason );
CheckCallResult("Get the completion code from the result bag", compCode, reason);
mqInquireInteger(errorBag, MQIASY_REASON, MQIND_NONE, &mqExecuteRC,
&compCode, &reason);
CheckCallResult("Get the reason code from the result bag", compCode, reason);
printf("Error returned by the command server: Completion Code = %d : Reason = %d\n",
mqExecuteCC, mqExecuteRC);
}
}
/***************************************************************************/
/* Delete the admin bag if successfully created. */
/***************************************************************************/
if (adminBag != MQHB_UNUSABLE_HBAG)
{
mqDeleteBag(&adminBag, &compCode, &reason);
CheckCallResult("Delete the admin bag", compCode, reason);
}
/***************************************************************************/
/* Delete the response bag if successfully created. */
/***************************************************************************/
if (responseBag != MQHB_UNUSABLE_HBAG)
{
mqDeleteBag(&responseBag, &compCode, &reason);
CheckCallResult("Delete the response bag", compCode, reason);
}
/***************************************************************************/
/* Disconnect from the queue manager if not already connected */
/***************************************************************************/
if (connReason != MQRC_ALREADY_CONNECTED)
{
MQDISC(&hConn, &compCode, &reason);
CheckCallResult("Disconnect from Queue Manager", compCode, reason);
}
return 0;
}
/******************************************************************************/
/* */
/* Function: CheckCallResult */
/* */
/******************************************************************************/
/* */
/* Input Parameters: Description of call */
/* Completion code */
/* Reason code */
/* */
/* Output Parameters: None */
/* */
/* Logic: Display the description of the call, the completion code and the */
/* reason code if the completion code is not successful */
/* */
/******************************************************************************/
void CheckCallResult(char *callText, MQLONG cc, MQLONG rc)
{
if (cc != MQCC_OK)
printf("%s failed: Completion Code = %d : Reason = %d\n", callText, cc, rc);
}