MQ--API Summary

Source: Internet
Author: User

Study MQ for a long time, each class, method, have looked for a long time, in this summary!

Java writing program to access MQ

1. mqqueuemanager――― Queue Manager Access Class

Common methods:
Public Mqqueuemanager (String queuemanagername)--Build a manager instance

There are two ways to create a queue manager:

1: Binding method, this way requires that the MQ server and the application belong to a server, the efficiency is high.

2: Client way: This way the application and MQ server can not be on the same server, but to consider the issue of MQ permissions, especially after the MQ7.5, the permissions become very complex, careful treatment.
Note: If you use bindings, you can create a new instance of the queue manager directly. However, in some platforms such direct creation would be an error and must be connected in a mqclient manner. At this point, you need to define the service channel, port, service name and other environment variables, and then create a Queue manager instance. Such as:

[HTML]View PlainCopy
    1. Mqenvironment.hostname = "IP address";
    2. Mqenvironment.channel = "ChannelName";
    3. Mqenvironment.port = Port;
    4. Mqenvironment.ccsid = CCSID;
    5. Mqqueuemanager qMgr = new Mqqueuemanager (hostname);

where hostname represents the address of the machine where the queue Manager resides (typically local, localhost or 127.0.0.1).

Port is the queue manager's listening port.

Channel definition of the server path name to access (you need to define it yourself in the queue Manager, which is similar to the definition of a generic channel, but the type is a server channel)

public bool IsConnected ()---Returns whether the queue Manager is in a connected state

Public synchronized void Disconnect ()--Disconnect the queue Manager

2. Mqqueue――― Queue Access Class

Common methods:
Typically, the generation of a Mqqueue instance is instantiated by calling the Accessqueue method class of Mqqueuemanager.

Public synchornized mqqueue accessqueue (String queuename,int openoptions)---Returns an instance of a connection queue (class name: Mqqueue)

Common methods:
Public synchronized void Get (Mqmessage message,mqgetmessageoptions GMO)--read one from the queue Manager

The message is returned through the message instance. The usage of mqgetmessageoptions is described in more detail below.

Public synchronized void put (Mqmessage message,mqputmessageoptions PMO)--Go to the queue manager and put a

The usage of message mqputmessageoptions is detailed below

Public synchronized void Close ()--Close queue connection

3.openOptions---How queues are opened

Common values are:
MQC. Mqoo_fail_if_quiescing――― return failure If the queue manager is stopped

MQC. Mqoo_output―――― to open a queue in write mode
MQC. Mqoo_input_as_q_def――― open Queue by queue default read mode can be used with the operation to implement a variety of open queue mode,

MQC. Mqoo_browse;―――― to open a queue as a browse mode

MQC. Mqgmo_browse_next; ―――― Browsing the next message

Such as:
int openoptions = MQC. mqoo_fail_if_quiescing | MQC. Mqoo_output | MQC. Mqoo_input_as_q_def; Indicates that the queue is opened in read and write mode

Common methods for 4.mqmessage――― message operations:

Public Mqmessage ()---default constructor
public int getdatalength ()--Returns the length of the message that can be read (in byte units)
public void readfully (byte b[])---reads the message into array B, the length of the array length of B is whichever

Property:

Format = MQC. mqfmt_string;

Msg.characterset = ccsid;//Character Set
msg.encoding = ccsid;//Write Character set


The general read message operation is:

[HTML]View PlainCopy
    1. Mqmessage message = new Mqmessage ();
    2. int length = message.getdatalength ();
    3. byte buffer[] = new Byte[length];
    4. message.readfully (buffer);

public void Write (Byte b[])--write the specified byte array to the message
The general write message operation is:

[HTML]View PlainCopy
    1. byte[] buffer = "Asdasdad". GetBytes ();
    2. Mqmessage message = new Mqmessage ();
    3. Message.write (buffer);
    4. Queue.put (Message ....)

5.mqgetmessageoptions――― fetching message operation options

Common methods:
Public mqgetmessageoptions ()---default constructor

public int options――― Operation option (bitwise operation)
public int matchoptions――― Conditional option (Gets the message in a certain condition)
public int waitinterval――― Wait time (in milliseconds) only valid if the options option has mqc.mqgmo_wait

6.mqputmessageoptions――― Message Operation Options

Common methods:
Public mqputmessageoptions ()---default constructor

public int options――― Operation option (bitwise operation)

7.MQ own Connection Pool

The MQ Queue Manager has its own connection pool and can use connection pooling to get a connection

We can use MQ's own default connection pool

Mqpooltoken Token=mqenvironment.addconnectionpooltoken ();

This will include the connection to the queue manager in this thread into the MQ's thread management mechanism (Qm.disconnect () is actually putting the QM's connection back into the pool qm= new Mqqueuemanager () will go to the pool to find an available connection to the QM)

Because the queue Manager is selecting a listening port, you can use Netstat-an |grep 9004 to see connections to this queue manager.

MQ--API Summary

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.