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 » IBM MQ Java / JMS » Inquiring Channel status

Post new topic  Reply to topic Goto page 1, 2  Next
 Inquiring Channel status « View previous topic :: View next topic » 
Author Message
d
PostPosted: Sun Jun 02, 2002 10:41 pm    Post subject: Inquiring Channel status Reply with quote

Apprentice

Joined: 24 May 2002
Posts: 25

Hi,
I'm trying to inquire channel status by using the import com.ibm.mq.pcf jar file. I have downloaded the ms0b.zip and was trying to modify one of the sample examples to suit my need (since there weren't any ex on how to obtain channel status)....
But I'm not very sure of what all attributes to set....

I'm getting the following error result :

Connecting to local queue manager QM_sr229_11442... Connected.
Sending PCF request... Received reply.
PCF error:
com.ibm.mq.pcf.MQCFH:
- type: 2
- strucLength: 36
- version: 1
- command: 42
- msgSeqNumber: 1
- control: 0
- compCode: 2
- reason: 3013
- parameterCount: 1

com.ibm.mq.pcf.MQCFIN:
- type: 3
- strucLength: 16
- parameter: 1012
- value: 1527

Disconnecting... Done.

-----------------------------------------------------------------------------

My code is

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.
*
*
*/

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

reserved.";

public static void main (String [] args)
{
int [] attrs = { CMQC.MQOT_SENDER_CHANNEL };
PCFAgent agent;
PCFParameter [] parameters = { new MQCFIL (CMQCFC.MQIACH_CHANNEL_STATUS,
attrs) };

MQMessage [] responses;
MQCFH cfh;
PCFParameter p;

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

if (args.length == 1)
{
System.out.print ("Connecting to local queue manager " +
args [0] + "... ");
agent = new PCFAgent (args [0]);
}
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]), args

[2]);
}

System.out.println ("Connected.");

// Use the agent to send the request

System.out.print ("Sending PCF request... ");
responses = agent.send (CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS, parameters);
System.out.println ("Received reply.");
cfh = new MQCFH (responses [0]);

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

if (cfh.reason == 0)
{
System.out.println ("Queue manager attributes:");

for (int i = 0; i < cfh.parameterCount; i++)
{
// Walk through the returned attributes

p = PCFParameter.nextParameter (responses [0]);
System.out.println ("\t attribute id " +
p.getParameter () + "=" + p.getValue ());
}
}
else
{
System.out.println ("PCF error:\n" + cfh);

// Walk through the returned parameters describing the error

for (int i = 0; i < cfh.parameterCount; i++)
{
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 ListQManagerAttrs queue-manager\n" +
"\tjava ListQManagerAttrs host port channel");
}

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

catch (MQException mqe)
{
System.err.println (mqe);
}

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

---------------------------------------------------------------------------
Highlighted are the portions where I am not sure of the options....

If anybody knows what parameters are to be set, please update me.

Thanks in advance,
d
Back to top
View user's profile Send private message
RogerLacroix
PostPosted: Tue Jun 04, 2002 8:37 pm    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Hi,

You appear to have your "attrs" incorrectly set.

Here's a Java program that has been floating around the MQ ListServer that inquires on a channel(s) status and a queue.

ftp://24.102.134.9/pub/code/java/ListChannelStatus.zip

Sorry, I don't remember who the author is.

later
Roger...
Back to top
View user's profile Send private message Visit poster's website
RogerLacroix
PostPosted: Mon Sep 13, 2004 8:02 am    Post subject: Reply with quote

Jedi Knight

Joined: 15 May 2001
Posts: 3264
Location: London, ON Canada

Here's a copy of the code that I have since that link is dead.
Code:
import java.io.*;
import java.util.*;
import com.ibm.mq.*;
import com.ibm.mq.pcf.*;
public class ListChannelStatus
{
   private Properties properties = new Properties(); // Contains system settings.
   //***********
   //** main()
   //***********
   static public void main(String args[])
   {
      ListChannelStatus lcs = new ListChannelStatus();
      try
      {
         lcs.init();
         lcs.channelStatus(lcs.properties);
         lcs.queueDepth(lcs.properties);
      }
      catch (Exception e)
      {
         System.out.println("general exception NOT handled in main");
         e.printStackTrace();
      }
   }
   //***********
   //** method init()
   //***********
   public void init() throws Exception
   {
      // Load system properties from file "properties.ini"
      FileInputStream fis = new FileInputStream("ListChannelStatus.properties");
      properties.load(fis);
      fis.close();
      // List system properties
      ByteArrayOutputStream baos = new ByteArrayOutputStream();
      properties.list(new PrintWriter(baos, true));
      System.out.println(baos.toString());
      // turn off the mqji messages, since we're handling some of them
      MQException.log = null;
   }
   //***********
   //** method void channelStatus(Properties p)
   //  This method accepts a Properties Oject which contains the details about the
   //  channel whose status is to be monitored
   // Monitor_IP - the IP or DNS name for the Server which hosts the channel
   // Monitor_Port - the listening port for the MQSeries Qmgr
   // Monitor_Channel - svrconn channel used to connect to qmgr being monitored
   //                   (this is not necessarily the channel being monitored)
   // Target_Channel_Name - the channel being monitored
   //
   //***********
   public void channelStatus(Properties p) throws Exception
   {
      // Set the situation variables
      String monitorIP = new String(p.getProperty("Monitor_IP"));
      int monitorPort = Integer.parseInt(p.getProperty("Monitor_Port"));
      String monitorChannel = new String(p.getProperty("Monitor_Channel"));
      String targetName = new String(p.getProperty("Target_Channel_Name"));
      int chlCount = 0;
      // set up the PCF agent
      PCFMessageAgent agent;
      PCFMessage request;
      PCFMessage[] responses;
      // build a request
      request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_CHANNEL_STATUS);
      // add a parameter designating the name of the channel for which status is requested
      request.addParameter(CMQCFC.MQCACH_CHANNEL_NAME, targetName);
      // add a parameter designating the instance type (current) desired
      request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_TYPE, CMQC.MQOT_CURRENT_CHANNEL);
      // add a parameter designating the attributes desired, but first...
      // ...build an array list of attributes desired
      int[] attrs = {CMQCFC.MQCACH_CHANNEL_NAME,
                     CMQCFC.MQCACH_CONNECTION_NAME,
                     CMQCFC.MQIACH_MSGS,
                     CMQCFC.MQCACH_LAST_MSG_DATE,
                     CMQCFC.MQCACH_LAST_MSG_TIME,
                     CMQCFC.MQIACH_CHANNEL_STATUS};
      // ...now add the parameter for these attributes
      request.addParameter(CMQCFC.MQIACH_CHANNEL_INSTANCE_ATTRS, attrs);
      try
      {
         // connect to the queue manager using the PCFMessageAgent
         agent = new PCFMessageAgent();
         agent.connect(monitorIP, monitorPort, monitorChannel);
      }
      catch (Exception e)
      {
         throw e;
      }
      try
      {
         // send the request and collect the responses
         responses = agent.send(request);
         for (int i = 0; i < responses.length; i++)
         {
            //  get the channel name and trim the spaces
            String temp = responses[i].getStringParameterValue(CMQCFC.MQCACH_CHANNEL_NAME);
            String channelName = temp.trim();
            //  get the channel name and trim the spaces
            temp = responses[i].getStringParameterValue(CMQCFC.MQCACH_CONNECTION_NAME);
            String connectionName = temp.trim();
            //  get the channel last message date/time
            temp = responses[i].getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_DATE);
            String lstMsgDate = temp.trim();
            temp = responses[i].getStringParameterValue(CMQCFC.MQCACH_LAST_MSG_TIME);
            String lstMsgTime = temp.trim();
            //  get the channel current messages total
            int totalMsgs = responses[i].getIntParameterValue(CMQCFC.MQIACH_MSGS);
            //  get the channel status
            int chlStatus = responses[i].getIntParameterValue(CMQCFC.MQIACH_CHANNEL_STATUS);
            if (chlStatus != CMQCFC.MQCHS_INACTIVE)
            {
               //System.out.println(" chlStatus = " + chlStatus);
               chlCount++;
            }
            System.out.println("chl: " + channelName + " IP: " + connectionName + " msgs: " + totalMsgs +
                  " last msg time: " + lstMsgDate + " " + lstMsgTime + " status: " + chlStatus);
         }
         System.out.println(targetName + " count=" + chlCount);
      }
      catch (PCFException pcfEx)
      {
         switch (pcfEx.reasonCode)
         {
            case CMQCFC.MQRCCF_CHL_STATUS_NOT_FOUND :
            {
               System.out.println(targetName + " count=" + chlCount);
               break;
            }
            default :
               System.out.println("PCF Exception NOT!! handled in ChannelStatus");
               throw pcfEx;
         }
      }
      finally
      {
         agent.disconnect();
      }
   }
   //***********
   //** method void queueDepth(Properties p)
   //  This method accepts a Properties Oject which contains the details about the
   //  queue whose depth is to be monitored and returns true if an alert is to be sent
   // Monitor_IP - the IP or DNS name for the Server which hosts the channel
   // Monitor_Port - the listening port for the MQSeries Qmgr
   // Monitor_Channel - svrconn channel used to connect to qmgr being monitored
   //                   (this is not necessarily the channel being monitored)
   // Target_Queue_Name - the queue being monitored
   //
   //***********
   public void queueDepth(Properties p) throws Exception
   {
      // Set the situation variables
      String monitorIP = new String(p.getProperty("Monitor_IP"));
      int monitorPort = Integer.parseInt(p.getProperty("Monitor_Port"));
      String monitorChannel = new String(p.getProperty("Monitor_Channel"));
      String targetName = new String(p.getProperty("Target_Queue_Name"));
      int qDepth = 0;
      // set up the PCF agent
      PCFMessageAgent agent;
      PCFMessage request;
      PCFMessage[] responses;
      // build a request
      request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q);
      // add a parameter designating the name of the channel for which status is requested
      request.addParameter(CMQC.MQCA_Q_NAME, targetName);
      try
      {
         // connect to the queue manager using the PCFMessageAgent
         agent = new PCFMessageAgent();
         agent.connect(monitorIP, monitorPort, monitorChannel);
      }
      catch (Exception e)
      {
         throw e;
      }
      try
      {
         // send the request and collect the responses
         responses = agent.send(request);
         for (int i = 0; i < responses.length; i++)
         {
            //  get the queue depth
            qDepth = responses[i].getIntParameterValue(CMQC.MQIA_CURRENT_Q_DEPTH);
            System.out.println("queue depth of " + targetName + " = " + qDepth);
         }
      }
      catch (PCFException pcfEx)
      {
         System.out.println("PCF Exception NOT!! handled in ChannelStatus");
         throw pcfEx;
      }
      finally
      {
         agent.disconnect();
      }
   }
}



And here is what the listchannelstatus.properties file looks like:
Code:
Monitor_IP=127.0.0.1
Monitor_Port=1430
Monitor_Channel=CLIENT.TO.MQA1
Target_Channel_Name=*
Target_Queue_Name=INPUT.TEST.QUEUE


Hope that helps.

Regards,
Roger Lacroix
_________________
Capitalware: Transforming tomorrow into today.
Connected to MQ!
Twitter
Back to top
View user's profile Send private message Visit poster's website
fireguok
PostPosted: Sun Mar 15, 2009 12:01 am    Post subject: Reply with quote

Novice

Joined: 03 Apr 2007
Posts: 22

I only retrieved the status of monitor channel not all the channels by the code above.
Can anyone explain?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sun Mar 15, 2009 1:03 am    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

fireguok wrote:
I only retrieved the status of monitor channel not all the channels by the code above.
Can anyone explain?

Could it be that you don't have permission to display any other channel than yours?
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
fireguok
PostPosted: Sun Mar 15, 2009 5:18 am    Post subject: Reply with quote

Novice

Joined: 03 Apr 2007
Posts: 22

I used the default channel below as the monitored channel. The mcauser is MUSR_MQADMIN.

SYSTEM.DEF.SVRCONN
Back to top
View user's profile Send private message
mqjeff
PostPosted: Sun Mar 15, 2009 9:25 am    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

fireguok wrote:
I used the default channel below as the monitored channel. The mcauser is MUSR_MQADMIN.

SYSTEM.DEF.SVRCONN


This means that your queue manager is entirely unsecure and everyone on the entire planet who can establish a network connection to your queue manager's listener port can do anything they want to that queue manager, and the machine that it is running on.

You may want to consider changing that.

Have you compared the results of "your" code with the results of DIS CHSTATUS? Are they different, or the same?
Back to top
View user's profile Send private message
fireguok
PostPosted: Sun Mar 15, 2009 3:45 pm    Post subject: Reply with quote

Novice

Joined: 03 Apr 2007
Posts: 22

Yes. This is only for the test.

Ideally i need to list all the status of the channel. If I issue dis chstatus, it won't list the channel which has inactive, stopped status.
Back to top
View user's profile Send private message
gbaddeley
PostPosted: Sun Mar 15, 2009 4:37 pm    Post subject: Reply with quote

Jedi Knight

Joined: 25 Mar 2003
Posts: 2538
Location: Melbourne, Australia

fireguok wrote:
Yes. This is only for the test.

Ideally i need to list all the status of the channel. If I issue dis chstatus, it won't list the channel which has inactive, stopped status.


DIS CHS( ) should display channels that are STATUS(STOPPED). It does for me.

It won't display inactive channels because inactive means there are no active instances in the qmgr and hence no "current" status. There can however be "saved" status info for inactive channels.
_________________
Glenn
Back to top
View user's profile Send private message
fireguok
PostPosted: Sun Mar 15, 2009 9:59 pm    Post subject: Reply with quote

Novice

Joined: 03 Apr 2007
Posts: 22

Thanks for your information. Have you tried PCF to list all the channel status including inactive?
Back to top
View user's profile Send private message
fjb_saper
PostPosted: Sun Mar 15, 2009 10:21 pm    Post subject: Reply with quote

Grand High Poobah

Joined: 18 Nov 2003
Posts: 20756
Location: LI,NY

fireguok wrote:
Thanks for your information. Have you tried PCF to list all the channel status including inactive?

The point here was that an inactive channel has no status and therefore can only be listed by comparing the channel status list to the channel list.

Have fun
_________________
MQ & Broker admin
Back to top
View user's profile Send private message Send e-mail
fireguok
PostPosted: Sun Mar 15, 2009 10:34 pm    Post subject: Reply with quote

Novice

Joined: 03 Apr 2007
Posts: 22

I'm not sure if I understand you.

My objective is to list status of all the channel no matther what the status is.
Can I use PCF here?
Back to top
View user's profile Send private message
Mr Butcher
PostPosted: Sun Mar 15, 2009 11:19 pm    Post subject: Reply with quote

Padawan

Joined: 23 May 2005
Posts: 1716

not every channel has a status (e.g. when it was never active).
_________________
Regards, Butcher
Back to top
View user's profile Send private message
mqjeff
PostPosted: Sun Mar 15, 2009 11:51 pm    Post subject: Reply with quote

Grand Master

Joined: 25 Jun 2008
Posts: 17447

fireguok wrote:
My objective is to list status of all the channel no matther what the status is.


Then you need to change the code.

Quote:
Can I use PCF here?


Yes.
Back to top
View user's profile Send private message
fireguok
PostPosted: Mon Mar 16, 2009 12:13 am    Post subject: Reply with quote

Novice

Joined: 03 Apr 2007
Posts: 22

How can i change the code?
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Goto page 1, 2  Next Page 1 of 2

MQSeries.net Forum Index » IBM MQ Java / JMS » Inquiring Channel status
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.