Java-MQ Management

Source: Internet
Author: User

The application uses MQ, but MQ does not have a suitable monitoring page. The monitoring methods are relatively scarce and there was a fault last Saturday. If there was a monitoring method for MQ at that time, it can detect problems in time and prevent faults. Before that, I want to write a program to monitor the queue depth in MQ and determine whether the system is working. However, I have never been able to obtain the depth of the MQ queue based on the information on the Internet. Although this function is a piece of simple code, it is a piece of code from IBM engineers until today, help me locate the previous error.

First, you need to have a basic understanding of MQ and understand some basic concepts (I am not familiar with some basic concepts, leading to some parameter errors). Then, I will read the following post:

MQ system management programming Overview

The management programming of MQ is well explained here, and the attached code is also very detailed. I am using PCF. I have completed the team-level access and downloaded a lib,ms0b.zip file on the ibmsite, with a com. IBM. MQ. pcf-6.1.jar. The related code is as follows:

1 pcfmessageagent agent;
2 pcfmessage request;
3 pcfmessage [] responses;
4 // connect a pcfagent to the specified Queue Manager
5 agent = new pcfmessageagent ("134.175.7.84", 14146, "system. admin. svrconn ");
6 // build the request
7 Request = new pcfmessage (cmqcfc. mq1__inquire_q );
8 request. addparameter (cmqc. mqca_q_name ,"*");
9 request. addparameter (cmqc. mqia_q_type, cmqc. mqqt_local );
10 request. addparameter (cmqcfc. mqiacf_q_attrs,
11 new int [] {cmqc. mqca_q_name, cmqc. mqia_current_q_depth });
12 // use the agent to send the request
13 responses = agent. Send (request );
14 // display the results
15 For (INT I = 0; I <responses. length; I ++)
16 {
17 string name = responses [I]. getstringparametervalue (cmqc. mqca_q_name );
18 int depth = responses [I]. getintparametervalue (cmqc. mqia_current_q_depth );
19}
20 // disconnect
21 agent. Disconnect ();

The error code is pcfmessageagent ("134.175.7.84", 14146, "system. admin. svrconn ");

The Code provided by IBM engineers is very simple, but there are key Annotations:

Mqenvironment. ccsid = 1381; // same as the queue manager
Mqenvironment. hostname = "localhost"; // name of the machine where the queue manager is located, which must be pinged
Mqenvironment. Port = 1414; // listening port of the queue manager
Mqenvironment. Channel = "chtest ";
Mqqueuemanager qmgr = new mqqueuemanager ("testqm"); // Queue Manager name
Mqqueue queue = qmgr. accessqueue ("qtest", MQC. mqoo_input_as_q_def); // queue
Mqmessage themessage = new mqmessage ();
Mqgetmessageoptions GMO = new mqgetmessageoptions ();
Queue. Get (themessage, GMO );
// System. Out. println ("The message length is:" + themessage. getdatalength ());
// Int I = themessage. getdatalength ();
System. Out. println ("The message is:" + themessage. Readline ());
Queue. Close ();
Qmgr. Disconnect ();

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.