Advanced java code dealing with real world problems.

Friday, September 4, 2009

Simple IBM MQ Queue Depth Monitor

For those that are still running IBM MQ (or Websphere MQ) on mainframes, presented here is a simple java queue depth monitor program that polls a queue manager periodically for the number of messages in a queue. The program utilizes the classes provided in the PCF package to get the queue depth information. This sample code will output a message to the console when the queue contains more than 10 messages at the moment of polling. You can change it to send out an email or snmp alert instead.
In order to compile and run this program, PCF package (MS0B) is needed and can be downloaded from IBM. You will also need "com.ibm.mq.jar" and IBM's "j2ee.jar". They can be found from IBM's WSAD or RAD IDE development tools.
/*
 * blog/javaclue/ibmmq/QueueDepthMonitor.java
 * 
 * Copyright (C) 2009 JackW
 * 
 * This program is free software: you can redistribute it and/or modify it under the terms of the
 * GNU Lesser General Public License as published by the Free Software Foundation, either version 3
 * of the License, or (at your option) any later version.
 * 
 * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without
 * even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * 
 * You should have received a copy of the GNU Lesser General Public License along with this library.
 * If not, see <http://www.gnu.org/licenses/>.
 */
package blog.javaclue.ibmmq;

import java.io.IOException;

import org.apache.log4j.Logger;

import com.ibm.mq.MQException;
import com.ibm.mq.pcf.CMQC;
import com.ibm.mq.pcf.CMQCFC;
import com.ibm.mq.pcf.PCFException;
import com.ibm.mq.pcf.PCFMessage;
import com.ibm.mq.pcf.PCFMessageAgent;

/**
 * Simple queue depth monitor program that uses PCFAgent to generate and parse
 * a PCF query.
 */
public class QueueDepthMonitor implements Runnable {
 protected static Logger logger = Logger.getLogger(QueueDepthMonitor.class);
 protected static boolean isDebugEnabled = logger.isDebugEnabled();

 final String qmgrName;
 final String host;
 final int port;
 final String channel;
 final String queueName;
 final int alertDepth;

 final static int Polling_Freq = 30 * 1000; // 30 seconds

 QueueDepthMonitor(String name, String host, String port, String channel, String queueName,
   int alertDepth) {
  this.qmgrName = name;
  this.host = host;
  this.channel = channel;
  this.port = Integer.parseInt(port);
  this.queueName = queueName;
  this.alertDepth = alertDepth;
 }

 public void run() {
  if (isDebugEnabled)
   logger.debug("Starting Queue Depth monitor for " + queueName + "...");
  while (true) {
   checkDepth();
   try {
    Thread.sleep(Polling_Freq); // sleep for 30 seconds
   }
   catch (InterruptedException e) {
    logger.info("The monitor has been interrupted, exit...");
    break;
   }
  }
 }

 private void checkDepth() {
  PCFMessageAgent agent = null;
  int[] attrs = { CMQC.MQCA_Q_NAME, CMQC.MQIA_CURRENT_Q_DEPTH };
  PCFMessage request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q);
  request.addParameter(CMQC.MQCA_Q_NAME, queueName);
  request.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_LOCAL);
  request.addParameter(CMQCFC.MQIACF_Q_ATTRS, attrs);
  PCFMessage[] responses;

  if (isDebugEnabled) {
   logger.debug("Connecting to " + qmgrName + " at " + host + ":" + port + " over " + channel);
  }
  try {
   // Connect a PCFAgent to the queue manager
   agent = new PCFMessageAgent(host, port, channel);
   // Use the agent to send the request
   responses = agent.send(request);
   // retrieving queue depth
   for (int i = 0; i < responses.length; i++) {
    String name = responses[i].getStringParameterValue(CMQC.MQCA_Q_NAME);
    int depth = responses[i].getIntParameterValue(CMQC.MQIA_CURRENT_Q_DEPTH);
    if (isDebugEnabled && name != null)
     logger.debug("Queue " + name + " Depth " + depth);
    if (name != null && queueName.equals(name.trim())) { // just for safety
     if (depth > alertDepth) {
      logger.info(qmgrName + "/" + queueName + " depth = " + depth
        + ", exceeded alert threshold: " + alertDepth);
      // XXX: add your code here to send out alert
     }
    }
   }
  }
  catch (PCFException pcfe) {
   logger.error("PCFException caught", pcfe);
   PCFMessage[] msgs = (PCFMessage[]) pcfe.exceptionSource;
   for (int i = 0; i < msgs.length; i++) {
    logger.error(msgs[i]);
   }
  }
  catch (MQException mqe) {
   logger.error("MQException caught", mqe);
  }
  catch (IOException ioe) {
   logger.error("IOException caught", ioe);
  }
  finally {
   // Disconnect
   if (agent != null) {
    try {
     agent.disconnect();
    }
    catch (Exception e) {
     logger.error("Exception caught during disconnect", e);
    }
   }
   else {
    logger.warn("unable to disconnect, agent is null.");
   }
  }
 }
 
 public static void main(String[] args) {
  String qmgrName = "QMGR";
  String host = "localhost";
  String port = "1450";
  String channel = "SYSTEM.DEF.SVRCONN";
  String queueName = "TEST_QUEUE";

  QueueDepthMonitor monitor = new QueueDepthMonitor(qmgrName, host, port, channel, queueName, 10);
  new Thread(monitor).start();
 }
}

59 comments:

  1. MQJE027: Queue manager security exit rejected connection with error code 23

    What do we do when this happens?

    ReplyDelete
  2. I assume that your queue manager requires login, try adding following logic before line: agent = new PCFMessageAgent(host, port, channel)
    MQEnvironment.disableTracing();
    MQException.log = null;
    MQEnvironment.hostname = host;
    MQEnvironment.port = port;
    MQEnvironment.channel = channel;
    MQEnvironment.userID = "";
    MQEnvironment.password = "";
    MQQueueManager qm = new MQQueueManager("");

    And replace that line with:
    agent = new PCFMessageAgent(qm);

    ReplyDelete
  3. I left "MQEnvironment.userID" and "MQEnvironment.password" blank, you need to enter your values there.

    ReplyDelete
  4. For me it gives

    MQJE001: Completion Code '2', Reason '2033'.
    MQJE001: Completion Code '2', Reason '2195'.
    MQJE001: Completion Code '2', Reason '2195'.

    I am connecting to Solaris server where MQ server is running. The above errors would mean no messages available.
    All i am interested is to know the queue depth.

    PCFMessageAgent agent = null;
    int[] attrs = { CMQC.MQCA_Q_NAME, CMQC.MQIA_CURRENT_Q_DEPTH };
    PCFMessage request = new PCFMessage(CMQCFC.MQCMD_INQUIRE_Q);
    request.addParameter(CMQC.MQCA_Q_NAME, queueName);
    request.addParameter(CMQC.MQIA_Q_TYPE, CMQC.MQQT_REMOTE);
    request.addParameter(CMQCFC.MQIACF_Q_ATTRS, attrs);

    ReplyDelete
  5. Great work, works just fine.
    I love it. Now I'm able to build up my Shellscript around this java-class to do some jobs on current queue depth.

    ReplyDelete
  6. How to set multiple Queue : request.addParameter(CMQC.MQCA_Q_NAME, queueName);

    ReplyDelete
  7. This post is probably where I got the most useful information for my research. Thanks for posting, maybe we can see more on this.
    Are you aware of any other websites on this
    IBM-MQ WEBSPHERE Online training


    ReplyDelete
  8. Nice guidance and steps which includes on JAVA, keep it up for more Core and Adv JAVA online training

    ReplyDelete
  9. Do you think you're confident about this? Or even, this could be basically the right time to get the QuickBooks Tech Support Number. We have trained staff to soft your issue. Sometimes errors may possibly also happen because of some small mistakes. Those are decimals, comma, backspace, etc. Are you go through to cope with this? Unless you, we have been here that will help you.

    ReplyDelete
  10. By using Quickbooks Payroll Customer Support Number, you're able to create employee payment on time. However in any case, you might be facing some problem when making use of QuickBooks payroll such as for instance issue during installation, data integration error, direct deposit issue, file taxes, and paychecks errors, installation or up-gradation or simply just about some other than you don’t panic, we provide quality Quickbooks Payroll Support Phone Number.

    ReplyDelete
  11. QuickBooks Enterprise Support Phone Number provides end-to end business accounting experience. With feature packed tools and features, this application is effective at managing custom

    ReplyDelete
  12. time for QuickBooks Support Phone Number The traders can’t make money. But, we've been here to aid a forecast.

    ReplyDelete
  13. QuickBooks Support Phone Number want to supply you with the immediate support by our well- masterly technicians. A team of QuickBooks tech Support dedicated professionals is invariably accessible for you personally so as to arranged all of your problems in an attempt that you’ll be able to do your work whilst not hampering the productivity.

    ReplyDelete
  14. According to statics released by the Bing & Google search insights a lot more than 50,000 folks searching the net to find the Quickbooks Support Phone Number on a regular basis and more than 2,000 quarries pertaining to Quickbooks issues and errors .

    ReplyDelete
  15. Inventory controller will generate Inventory Items and enter inventory details to QuickBooks Enterprise Tech support Number, Sales personal will generate customer invoices, Vendor developer will show up into vendor creation and payments and finance managers will require financial decisions looking at the financial reports.

    ReplyDelete
  16. The support team at Support for QuickBooks 2019 is trained by well experienced experts that are making our customer support executives quite robust and resilient. It really works twenty-four hours each day in just one element of mind as an example.

    ReplyDelete
  17. QuickBooks Customer Support Number also troubleshoot any type of error which can be encountered in this version or this version in a multi-user mode.

    ReplyDelete
  18. QuickBooks Customer Support Number, there's absolutely no part of wasting your own time, getting worried for the problem you will be facing and so forth. Just call and you'll get instant relief from the problem caused by various QuickBooks errors.

    ReplyDelete
  19. Get In Touch With Us. Consult a professional through live chat. Our QuickBooks Tech Support Number executives are here twenty-four hours a day to attend you. Whatever channel you choose to call us, you are getting an undivided awareness of your trouble from our people. You are receiving a number of fixes here with only one ring. Why be satisfied with less then? Give us a call, let us know your problem and fix it.

    ReplyDelete
  20. We plan to give you the immediate support by our well- masterly technicians. A group of QuickBooks Technical Support Number dedicated professionals is invariably accessible to suit your needs so as to arranged all of your problems in an attempt that you’ll be able to do your projects while not hampering the productivity.

    ReplyDelete
  21. There needs to be a premier mix solution. Quickbooks Support Number often helps. Proper outsource is crucial. You'll discover updates about the tax table. This saves huge cost. All experts usually takes place. A group operates 24/7. You get stress free. Traders become free. No body will blame you. The outsourced team will see all.

    ReplyDelete
  22. Comprises of an attractive lot of accounting versions, viz., QuickBooks Pro, QuickBooks Premier, QuickBooks Enterprise, QuickBooks POS, QuickBooks Mac, QuickBooks Windows, and QuickBooks Enterprise Support Phone Number, QuickBooks is becoming a dependable accounting software that one may tailor depending on your industry prerequisite.

    ReplyDelete
  23. For such kind of information, be always in contact with us through our blogs. To locate the reliable way to obtain assist to create customer checklist in QB desktop, QuickBooks online and intuit online payroll? Our QuickBooks Payroll Technical Support Number service may help you better.

    ReplyDelete
  24. Enterprise type of the QuickBooks Enterprise Tech Support Number for your requirements, a good idea is not to ever waste another second in trying to find an answer for the problems.

    ReplyDelete
  25. Intuit QuickBooks Support Number is ideal for managing the work flow flawless and smooth by prints the payroll components and exchange report are necessary for the modern bookkeepers etc. It is centered on application or the cloud based service. Its versions such as:, Payroll, Contractor , Enterprises and Pro Advisor which helps the countless small business world wide .

    ReplyDelete
  26. This issue wouldn't normally arise in the event that you closely monitor every single transaction that takes place on a monthly basis. If this dilemma arises, the greatest you are able to do is make contact with the QuickBooks Payroll Tech Support Number.

    ReplyDelete
  27. Many of us resolves most of the QuickBooks Payroll Support Phone Number issue this type of a fashion that you'll yourself believe that your issue is resolved without you wasting the time into it. We take toll on every issue through the use of our highly trained customer care

    ReplyDelete
  28. By using Phone Number for QuickBooks Payroll Supportt, you're able to create employee payment on time. However in any case, you might be facing some problem when making use of QuickBooks payroll such as for instance issue during installation, data integration error, direct deposit issue, file taxes, and paychecks errors, installation or up-gradation or simply just about some other than you don’t panic, we provide quality QuickBooks Payroll help service. Here are some features handle by our QB online payroll service.

    ReplyDelete
  29. But sometimes many customers are unable to get perfect solution on call If any customer is unable to get a perfect solution on call or unable to fix QuickBooks Tech Support Number troubles by self then our professionals help customers by accessing their laptop or PC remotely with complete satisfaction.

    ReplyDelete
  30. Resolve any QuickBook Support issue by the QB technicians instantly . Company owner these days completely depend on QuickBooks in order to prevent the hassle of the types of work. The most popular QB versions: Pro Advisor, Payroll and Enterprise have brought a revolution in the present business competition .

    ReplyDelete
  31. QuickBooks Tech Support Number might face problem in reconciling your hard earned dollars, there might be problems while you attempt to reconcile your bank cards, you will find problem in the settings of this report and so on and so on. An extra

    ReplyDelete
  32. There are lots of features in QuickBooks that produces the software that makes it accountant’s first choice. It is possible to call our experts at QuickBooks Tech Support Phone Number to get on-demand QuickBooks help by experts.

    ReplyDelete
  33. QuickBooks Support Number advisors are certified Pro-advisors’ and has forte in furnishing any kind of technical issues for QuickBooks. They have been expert and certified technicians of these domains like QuickBooks accounting,QuickBooks Payroll, Point of Sales, QuickBooks Merchant Services and Inventory issues to provide 24/7 service to our esteemed customers.

    ReplyDelete
  34. HP print head errors are typical between the HP Printer Support Number device. These HP Printer error messages arise for the consumer to inform them in regards to the trouble the device is facing, as well as for them to solve the same.

    ReplyDelete
  35. Meanwhile, here we now have come up with some of the basic troubleshooting tips to fix various types of issues associated with the HP Laptops. Moreover, the HP laptop overheating and shutting down issues will also be fixed here. You just have to follow the HP Inkjet Printer Support Number tips and you may able to repair HP laptops.

    ReplyDelete
  36. To have more enhanced results and optimized benefits, you are able to take the help of experts making a call at QuickBooks Payroll Support Number. Well! If you’re not in a position to customize employee payroll in Quickbooks while making the list optimally, in QB and QB desktop, then browse the description ahead.

    ReplyDelete
  37. QuickBooks Pro is some type of class accounting software which has benefited its customers with various accounting services. It offers brought ease to you by enabling some extra ordinary features and also at QuickBooks Technical Support Phone Number it is simple to seek optimal solutions if any error hinders your work. With QuickBooks Pro you can easily easily effortlessly create invoices and keep close tabs on every little thing like exacltly what the shoppers bought, just how much they paid etc. In addition it lets you have a crystal-clear insight of your business that can help someone to monitor your cash, taxes as well as sales report, everything at one place.

    ReplyDelete
  38. Our hard-working QuickBooks Tech Support team that contributes into the over all functioning of the business by fixing the errors that will pop up in QuickBooks Payroll saves you from getting into any problem further.

    ReplyDelete
  39. QuickBooks Support Number

    QuickBooks Support Number +1 [(888)-422-3444].
    and get rid of issues related to QuickBooks. Direct access to certified Pro-Advisors with diagnosis of all Issues and anticipated issues. Get in touch with for all QuickBooks errors and issues.

    ReplyDelete
  40. dell Printer Support Phone Number

    Dell Printer Support Phone Number + 1-888-600-5222.
    Dell users must contact them with the experts and specialist via dell support number for a better and effective solution. Dell technical support has a remedy to every issue that you are facing. This service is available 24×7 to help users with their distressed problem.








    ReplyDelete

  41. Intuit has developed these products by keeping contractor’s needs in your mind; also, cared for the application solution in line with the company size. At the moment, QuickBooks Support Number software covers more than 80% associated with small-business share of the market.

    ReplyDelete
  42. Payroll management is actually an essential part these days. Every organization has its own employees. Employers want to manage their pay. The yearly medical benefit is vital. The employer needs to allocate. But, accomplishing this manually will require enough time. Aim for QuickBooks Payroll Support Phone Number. This can be an excellent software. You can actually manage your finances here.

    ReplyDelete
  43. Unfortunately, you'll find fewer options available for the client to talk directly to agents or QuickBooks Payroll Technical Support. Posting questions on payroll community page is a good idea not the best way to obtain a sudden solution; in the event that you wanna to keep in contact with a person.

    ReplyDelete
  44. Since quantity of issues are enormous on occasion, QuickBooks Tech Support Phone Number could seem very basic to you and as a consequence will make you are taking backseat and you will not ask for virtually any help.

    ReplyDelete
  45. QuickBooks Tech Support is provided by technicians who are trained every so often to meet with almost any queries pertaining to integrating QuickBooks Premier with Microsoft Office related software.

    ReplyDelete
  46. QuickBooks Enterprise Tech Support Phone Number will help you in getting the latest version of QuickBooks Enterprise, which has been created and designed particularly to manage and handle complex business operations. With its advanced features, it is booming among the users of QuickBooks across the world. With our QB Enterprise Technical Support, users can fetch benefits to use the latest characteristics of this accounting software

    ReplyDelete
  47. Get tried and tested solutions for QuickBooks Error 6000 1076 at QuickBooks Payroll Support Phone Number 1-855-236-7529. QuickBooks Payroll is the supreme accounting software that can help you in managing your daily accounting tasks like invoicing and payroll. No doubt QuickBooks Payroll slacken the difficulty of payroll management but unlike any other software, QuickBooks Payroll is also not devoid of errors. However, at times, it is seen that QuickBooks company files get corrupt and throws QuickBooks Error 6000 1076 when you try to open them. To fix this error, you can try the workarounds that are mentioned in this blog. In case you want quick technical help for this error then simply consult our proficient technicians at QuickBooks Payroll Support Phone Number 1-855-236-7529.
    Read more: https://tinyurl.com/y2hwz69t

    ReplyDelete
  48. QuickBooks support phone number 1-833-441-8848 get you one-demand technical help for QuickBooks. QuickBooks allows a number of third-party software integration. QuickBooks software integration is one of the most useful solution offered by the software to manage the accounting tasks in a simpler and precise way. No need to worry about the costing of this software integration as it offers a wide range of pocket-friendly plans that can be used to manage payroll with ease.

    ReplyDelete
  49. Hi, thanks for this amazing piece of information. Although short and accurate, yet it provides ample information. These types of blogs are so rare to be found in the present time. Keep posting such informative posts with consistency. I would like to suggest you to use QuickBooks to complete all the business formalities. Contact the personnel for QuickBooks assistance at QuickBooks Support Phone Number 1-833-441-8848

    ReplyDelete
  50. Hey! I simply couldn’t leave your website without notifying you that I liked your work. QuickBooks is a big name in the accounting world. It has helped many organizations in getting established. In case you are using any other accounting software then switch to QuickBooks. You can take experts help at QuickBooks Contact Number 1-833-441-8848 for the installation of QuickBooks software.

    ReplyDelete
  51. I really like to spend my time getting through such productive pieces of information. Nice blog by the way! Just go on and wish you success in further efforts. While you seek technical services for QuickBooks, you can buzz at the 24*7 accessible Number for QuickBooks Enterprise Support +1 (888) 238-7409.Read more:- https://tinyurl.com/yxv7m3tl & Visit us:- https://www.enetquickbookenterprise.com/

    ReplyDelete
  52. Hey! Great work. I feel so happy to be here reading your post. Do you know QuickBooks Desktop is the leading brand in the accounting world? I have been using this software for the past 3 years. I love the ease of use and the different tools provided by the software. In case you want any help regarding your software then dial QuickBooks Desktop Support Phone Number 1-833-441-8848.

    ReplyDelete
  53. The team at QuickBooks POS Support Phone Number +1 (855)-907-0605 constitutes of highly enthusiastic professionals who have years of experience in deciphering the technical grievances of QuickBooks POS software. Traits like vigilance, resilient, and amiable make our team one of the most dependable squad.

    ReplyDelete
  54. Hi! Amazing Write-up. Your blog contains a fabulous quality of content. I feel good to be here reading your magnificent post. If you are searching for accounting software that has lots of features for managing business accounts, then try using QuickBooks software. It is a leading accounting software that manages your business accounts effectively and efficiently.
    To get support for QuickBooks errors, call us immediately at our QuickBooks Helpline Number +1-844-232-O2O2 .
    visit us:-http://www.authorstream.com/Presentation/QBPAYROLL1234-4133537-quickbooks-helpline-number/

    ReplyDelete
  55. QuickBooks Error 9999 can occur while you are installing a program or Intuit Inc. related software program (e.g. QuickBooks) is running. Also, it might occur to take place during Windows startup or shutdown, and even if the Windows operating system will be installed. This is why you should keep an eye on when and where the 9999 error takes place which acts as a very crucial bit of information in troubleshooting the problem.

    ReplyDelete
  56. During software design, programmers code anticipating the occurrence of errors. However, there are no perfect designs, as errors can be expected even with the best program design. Glitches can happen during runtime if a certain error is not experienced and addressed during design and testing. If you would like to learn how to Fix Quickbooks Error 9999 yourself, you can continue reading this blog.

    ReplyDelete

Followers

About Me

An IT professional with more than 20 years of experience in enterprise computing. An Audio enthusiast designed and built DIY audio gears and speakers.