ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » General IBM MQ Support » Clear Queue pcf example

Post new topic  Reply to topic
 Clear Queue pcf example « View previous topic :: View next topic » 
Author Message
ryno
PostPosted: Thu Aug 08, 2002 11:56 am    Post subject: Clear Queue pcf example Reply with quote

Novice

Joined: 22 Jul 2002
Posts: 17

pcf sample code is so scarce and very vague for what little is out there, for any one of you MQ gurus out there, if I wanted to write a function in C, for the as400 that could clear a specific queue when called can anyone code me a little example? There are several other things I need to do also, but showing me how to write the clear queue method would be a perfect start I would appreciate it very much being such a newbie to mq series. Thanks
Back to top
View user's profile Send private message
mrlinux
PostPosted: Fri Aug 09, 2002 11:05 am    Post subject: Reply with quote

Grand Master

Joined: 14 Feb 2002
Posts: 1261
Location: Detroit,MI USA

Any intrest in java version ???
_________________
Jeff

IBM Certified Developer MQSeries
IBM Certified Specialist MQSeries
IBM Certified Solutions Expert MQSeries
Back to top
View user's profile Send private message Send e-mail
ryno
PostPosted: Fri Aug 09, 2002 12:42 pm    Post subject: Reply with quote

Novice

Joined: 22 Jul 2002
Posts: 17

sure, Java is my fav lang anyway. but this little project happens to call for C code- and on top of that Im a newbie at the MQ stuff. but hey, anything helps. thanks alot man
Back to top
View user's profile Send private message
clindsey
PostPosted: Fri Aug 09, 2002 1:21 pm    Post subject: Clear q pcf example Reply with quote

Knight

Joined: 12 Jul 2002
Posts: 586
Location: Dallas, Tx

I am not sure what samples are shipped with the AS/400 but
on the distributed platforms there are a couple of pcf c samples.
For example, take a look at amqsaicq.c, which defines a local
queue. This should provide a good base to build from.

This code uses the Administration Interface (MQAI) which is supported on the AS/400.
Back to top
View user's profile Send private message
kingsley
PostPosted: Fri Aug 09, 2002 7:53 pm    Post subject: Reply with quote

Disciple

Joined: 30 Sep 2001
Posts: 175
Location: Hursley

Hi Guyz,

For AS/400 & S/390 Mid Range Server, i think the Command Servers cannot interpret PCF Commands. These Command Servers are to interpret MQSC Commands which are sent through runmqsc -w TargetQM Name

I never had access to these midRange Systems but i found these things in the manuals.

Just cross check and let me know.

Bye
kalyan
Back to top
View user's profile Send private message Visit poster's website
clindsey
PostPosted: Sat Aug 10, 2002 6:36 am    Post subject: Reply with quote

Knight

Joined: 12 Jul 2002
Posts: 586
Location: Dallas, Tx

The AS/400 command server does support PCF.

There are a couple of SupportPacs that also provide pcf samples. MS02 is an example of using pcf to list queues without the MQAI if you want to do it the old fashioned way. You can compare it against amqsailq.c which uses MQAI. Both submit MQCMD_INQUIRE_Q.


Also, look at MS03. This shows how to save all the definitons of
a queue manager. The nice thing about it is that it provides makefiles for almost all platforms including AS/400.

Hope this helps,
Charlie
Back to top
View user's profile Send private message
clindsey
PostPosted: Sat Aug 10, 2002 10:16 am    Post subject: Reply with quote

Knight

Joined: 12 Jul 2002
Posts: 586
Location: Dallas, Tx

Ok, it is raining in Dallas this morning and I am stuck in doors,
so here is a c sample to clear a queue. I made very minor modifications to amqsailq.c. Note though that MQCMD_CLEAR_Q
does not return any attributes, so you still need to refer to amqsailq.c when you get ready to code up a command that returns information.

/******************************************************************************/
/* */
/* Program name: CLEARQ.C */
/* */
/* Description: Sample C program to clear all messages from a queue using */
/* the MQSeries Administration Interface (MQAI). */
/******************************************************************************/
/* */
/* Function: */
/* CLEARQ is a sample C program that demonstrates how to clear all */
/* messages from a local queue using the MQAI interface. */
/* */
/* - A PCF command is built from items placed into an MQAI administration */
/* bag. */
/* These are:- */
/* - The name argv[1] */
/* */
/* - The mqExecute call is executed with the command MQCMD_CLEAR_Q. */
/* The call generates the correct PCF structure. */
/* The default options to the call are used so that the command is sent */
/* to the SYSTEM.ADMIN.COMMAND.QUEUE. */
/* The reply from the command server is placed on a temporary dynamic */
/* queue. */
/* The reply from the MQCMD_CLEAR_Q command is read from the */
/* temporary queue and formatted into the response bag. */
/* */
/* - The completion code from the mqExecute call is checked and if there */
/* is a failure from the command server, then the code returned by the */
/* command server is retrieved from the system bag that has been */
/* embedded in the response bag to the mqExecute call. */
/* */
/* - If the call is successful, there are no attributes returned for */
/* MQCMD_CLEAR_Q other than complettion code information. */
/* */
/* Note: The command server must be running. */
/* */
/******************************************************************************/
/* */
/* clearq has 2 parameters: */
/* queue name (required) */
/* 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 errorBag; /* bag containing cmd server error */
MQLONG mqExecuteCC; /* mqExecute completion code */
MQLONG mqExecuteRC; /* mqExecute reason code */


/***************************************************************************/
/* Connect to the queue manager */
/***************************************************************************/
if (argc > 2)
strncpy(qmName, argv[2], (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 queue name into the admin bag */
/***************************************************************************/
mqAddString(adminBag, MQCA_Q_NAME, MQBL_NULL_TERMINATED, argv[1], &compCode, &reason);
CheckCallResult("Add q name", compCode, reason);


/***************************************************************************/
/* Send the command to clear the local queue. */
/* 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. */
/***************************************************************************/
mqExecute(hConn, /* MQ connection handle */
MQCMD_CLEAR_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(9;
}

/***************************************************************************/
/* Check the result from mqExecute call. If successful find the current */
/* depths of all the local queues. If failed find the error. */
/***************************************************************************/
switch (reason)
{
case MQCC_OK:
printf("Queue %s successfully cleared\n", argv[1]);
break;

case MQRCCF_COMMAND_FAILED:
/*************************************************************************/
/* 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. */
/*************************************************************************/
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);
if (mqExecuteRC == MQRC_Q_NOT_EMPTY)
{
printf("Queue contains uncommitted messages and cannot be cleared.\n");
}
else
{
printf("Error returned by the command server: Completion Code = %ld : Reason = %ld\n",
mqExecuteCC, mqExecuteRC);
}
break;

default:
printf("PCF command failed: Completion Code = %ld : Reason = %ld\n",
compCode, reason);
break;

}

/***************************************************************************/
/* 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 = %ld : Reason = %ld\n", callText, cc, rc);
}
Back to top
View user's profile Send private message
mrlinux
PostPosted: Mon Aug 12, 2002 3:37 am    Post subject: Reply with quote

Grand Master

Joined: 14 Feb 2002
Posts: 1261
Location: Detroit,MI USA

Here is the java code



import java.io.*;
import com.ibm.mq.*;
import com.ibm.mq.pcf.*;

/**
* PCF example class showing use of PCFAgent and com.ibm.mq.pcf structure types
* to generate and parse a PCF query.
*
* @author Chris Markes
*/

public class clearQ
{
final public static String copyright = "Copyright (c) IBM Corp. 1998, 2000 All rights reserved.";

public static void main (String [] args)
{
PCFAgent agent;
int [] attrs =
{
CMQC.MQCA_Q_NAME,
CMQC.MQIA_CURRENT_Q_DEPTH
};

MQMessage [] responses;
MQCFH cfh;
PCFParameter p;
String name = null;

try
{
// Connect a PCFAgent to the specified queue manager

if (args.length == 2)
{
System.out.print ("Connecting to local queue manager " +
args [0] + "... ");
agent = new PCFAgent (args [0]);
name = args[1];
}
else
{
System.out.print ("Connecting to queue manager at " +
args [0] + ":" + args [1] + " over channel " + args [2] + "... ");
agent = new PCFAgent (args [0], Integer.parseInt (args [1]), "SYSTEM.DEF.SVRCONN");
name = args[2];
}
PCFParameter [] parameters =
{
new MQCFST (CMQC.MQCA_Q_NAME, name)
};
System.out.println ("Connected.");

// Use the agent to send the request

System.out.print ("Sending PCF request... ");
responses = agent.send (CMQCFC.MQCMD_CLEAR_Q,parameters);

System.out.println ("Received reply. Number of Respone Records=" + responses.length);

for (int i = 0; i < responses.length; i++)
{
cfh = new MQCFH (responses [i]);

// Check the PCF header (MQCFH) in the response message

if (cfh.reason == 0)
{
for (int j = 0; j < cfh.parameterCount; j++)
{
// Extract what we want from the returned attributes

p = PCFParameter.nextParameter (responses [i]);


switch (p.getParameter ())
{
case CMQC.MQCA_Q_NAME:
name = (String) p.getValue ();
break;
default:

}
}

System.out.println("Q=" + name);
}
else
{
System.out.println ("PCF error:\n" + cfh);

// Walk through the returned parameters describing the error

for (int j = 0; j < cfh.parameterCount; j++)
{
System.out.println (PCFParameter.nextParameter (responses [0]));
}
}
}

// Disconnect

System.out.print ("Disconnecting... ");
agent.disconnect ();
System.out.println ("Done.");
}

catch (ArrayIndexOutOfBoundsException abe)
{
System.out.println ("Usage: \n" +
"\tjava ListQueueDepth queue-manager\n" +
"\tjava ListQueueDepth host port channel");
}

catch (NumberFormatException nfe)
{
System.out.println ("Invalid port: " + args [1]);
System.out.println ("Usage: \n" +
"\tjava ListQueueDepth queue-manager\n" +
"\tjava ListQueueDepth host port channel");
}

catch (MQException mqe)
{

System.err.println ("Reason Code=" + mqe.reasonCode);
}

catch (IOException ioe)
{
System.err.println (ioe);
}
}
}
_________________
Jeff

IBM Certified Developer MQSeries
IBM Certified Specialist MQSeries
IBM Certified Solutions Expert MQSeries
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » General IBM MQ Support » Clear Queue pcf example
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.