Websphere MQ Development Instance

Source: Internet
Author: User
Tags mqseries time limit
IBM MQSeries consists essentially of a messaging system and an application interface with resources for messages and queues (messaging and Queuing). Queue Manager: A system that manages queues, implements network communications, and ensures that messages are securely transmitted to destinations. Used to ensure the availability of information between queues, including the provision of information between remote queues on different systems on the network. and to ensure network failure or recovery after shutdown. Queues: A secure information store. Because information is stored in queues, applications can be run independently of each other at different speeds, at different times, in different locations. Local queues: For programs, the local queue belongs to the queue Manager that the program is connected to. Remote queue: This queue is not part of the queue manager that the program is connected to, but is the local definition of the queue for the remote Queue Manager. Transport queue: It is a local queue that holds messages that specify the remote to send to. Dead-letter queue: It is a local queue for messages that cannot be delivered. Channel: A data transmission link established between two queue managers. Application interface: an interface implemented through the MQSeries API between applications and information systems.

Import Com.ibm.mq.MQC;
Import com.ibm.mq.MQEnvironment;
Import com.ibm.mq.MQException;
Import Com.ibm.mq.MQMessage;
Import com.ibm.mq.MQPutMessageOptions;
Import Com.ibm.mq.MQQueue;
Import Com.ibm.mq.MQQueueManager;

/**
* Send a message program
*/
public class Send {

public static void Main (string[] args) {
try {

     //Host name
      String hostName = "192.168.1.101";
     //port (default 1414)
      int port = 1515;
     //Channel name (default)
      String channel = "SYSTEM. Def. Svrconn ";
     //Queue Manager name
      String qmanager = "send";
     //queue name (remote queue name)
      String qName = "Q1";

     //Set up the Mqenvironment properties for Client connections.
     //Establish Mqenvironment properties for client connections.
      mqenvironment.hostname = hostname;
      mqenvironment.port = port;
      mqenvironment.channel = channel;
      MQEnvironment.properties.put (MQC. Transport_property, MQC. Transport_mqseries);
      mqenvironment.ccsid = 1381;
     
     //Connection to the Queue Manager.
     //Connect to Queue Manager.
      Mqqueuemanager qMgr = new Mqqueuemanager (Qmanager);

/**
* Set up the open options to open the queue
* and additionally we have set the option to fail if the queue Manager
* is quiescing.
*
* Set open options to open the queue for output, and further, if the queue Manager is
* Pause, we have set options to deal with unsuccessful situations.
*/
int openoptions = MQC. Mqoo_output | MQC. mqoo_fail_if_quiescing;

Open the queue.
Open the queue.
Mqqueue queue = Qmgr.accessqueue (qName, openoptions, NULL, NULL,
NULL);

Set the put message options, we'll use the default setting.
Set the DROP message option we will use the default settings.
Mqputmessageoptions PMO = new Mqputmessageoptions ();

/**
* Next We build a message the Mqmessage class encapsulates the data
* Buffer that contains the actual message data, together and all MQMD
* Parameters that describe.
*
* Next we build the message that the Mqmessage class compresses the data buffers that contain the actual message data.
* and all MQMD parameters that describe the message.
*
* To build a new message, create a new instance of Mqmessage class
* and use WRITXXX (we'll be using WriteString method).
* The put () method of Mqqueue also takes a instance of the
* Mqputmessageoptions class as a parameter.
*
* To build new messages, create new instances of Mqmessage classes, and use WRITXXX (we'll use the WriteString method.).
* Mqqueue's put () method can also be used as an instance of the parameter Mqputmessageoptions class.
*/

Create the message buffer.
Creates a message buffer.
Mqmessage outmsg = new Mqmessage ();

Set the MQMD format field.
Sets the MQMD format field.
Outmsg.format = MQC. mqfmt_string;

Prepare message with user data.
Prepares user data messages.
      String msgstring = "head7c5218991310615536   bocomc      0100521899        200909170720470020090917101000000022164428000000020000000000000000000000020000  1110408715  0000     0 1564439990000044399900000                           1 1  000                                                  domn200909170720470016100115400000000156           HA1310011130028738445 at032007101900000068835700000110000000000000000020090915000000010000000000431643000000000000                        PENG ping          6532cafcr102                                                                        000281548016372856dqpd        2007100120071030                                0000020000000000000000000000688357000001100000000000000000000000010000000000431643000000484119000000100000006200909170720 55550                                                                                                                                             19790117                                                                  518000          20090917000000272977113714719646         1310710130979        male                     ssno180001016790                               ms0000000000                2007101920090912000000002007103001                   0           00000004841192007102004064394c       000000000           TAIL ";

Now we put the "message" on the Queue.
Now we're putting messages on the queue.
Outmsg.writestring (msgstring);


Commit the transaction.
Commits a transaction.
Queue.put (Outmsg, PMO);
Qmgr.commit ();
SYSTEM.OUT.PRINTLN ("The message has been sussesfully put/n/n#########");

Close the the queue and Queue manager objects.
Closes the queue and Queue manager objects.
Queue.close ();
Qmgr.disconnect ();

catch (Mqexception ex) {

System.out.println ("An MQ Error occurred:completion Code is:/T" +
Ex.completioncode + "/n/n the Reason Code is:/T" + ex.reasoncode);
Ex.printstacktrace ();

catch (Exception e) {

E.printstacktrace ();

}

}

}

Import Com.ibm.mq.MQC;
Import com.ibm.mq.MQEnvironment;
Import com.ibm.mq.MQException;
Import com.ibm.mq.MQGetMessageOptions;
Import Com.ibm.mq.MQMessage;
Import Com.ibm.mq.MQQueue;
Import Com.ibm.mq.MQQueueManager;

/**
* Message receiver Application
*
* Transfer into MQSeries Java API package
* Set environment properties for client connections
* Connect to Queue Manager
* Set options for open MQSeries queues
* Open application for getting messages
* Set options to get messages from the application queue
* Create a message buffer
* Get messages from queue to message buffer
* Read user data from the message buffer and display it on the console
*/

public class Receiver {

public static void Ptpreceiver () {
try {

Host Name
String hostName = "192.168.1.101";
Port (default 1414)
int port = 1616;
Channel name (default)
String channel = "SYSTEM. Def. Svrconn ";
Queue Manager Name
String Qmanager = "Receive";
Queue name (local to column name)
String qName = "Q1";

    //Establish Mqenvironment properties for client connections
     mqenvironment.hostname = HostName;
     mqenvironment.port = port;
     mqenvironment.channel = channel;
     MQEnvironment.properties.put (MQC. Transport_property, MQC. Transport_mqseries);
     mqenvironment.ccsid = 1381;
    
    //Connection to the Queue Manager.
    //Connect to Queue Manager.
     Mqqueuemanager qMgr = new Mqqueuemanager (Qmanager);

/**
* Set up the open options to open the \
* Additionally we have set the option to fail if the queue Manager
* is quiescing.
*
* Set open options to open the queue for output,
* Further, if the queue Manager is paused, we also
* An option has been set to deal with the unsuccessful situation.
*/

Open the queue.
Open the queue.
int openoptions = MQC. mqoo_input_shared | MQC. mqoo_fail_if_quiescing;

Set the put message options.
Sets the drop message option.
Mqqueue queue = Qmgr.accessqueue (qName, openoptions, NULL, NULL, NULL);

Mqgetmessageoptions GMO = new Mqgetmessageoptions ();

Get messages under the Sync Point control.
Gets the message under the control of the synchronization point.
Gmo.options = Gmo.options + MQC. Mqgmo_syncpoint;

Wait if no messages on the Queue.
Wait if there is no message on the queue.
Gmo.options = Gmo.options + MQC. mqgmo_wait;

Fail if Qeuemanager quiescing.
Fails if the Queue manager pauses.
Gmo.options = Gmo.options + MQC. mqgmo_fail_if_quiescing;

Sets the time limit for the wait.
Sets the time limit for the wait.
Gmo.waitinterval = 3000;

/**
* Next We build a message the Mqmessage class encapsulates the data
* Buffer that contains the actual message data, together and all MQMD
* Parameters that describe.
*
* Next we build the message, Mqmessage
The * class compresses the data buffers that contain the actual message data.
* and all MQMD parameters that describe the message.
*/

Create the message buffer.
Creates a message buffer.
Mqmessage inmsg = new Mqmessage ();

Get the "message" from the "queue" to the "message buffer".
Gets the message from the queue to the message buffer.
Queue.get (Inmsg, GMO);

Read the User data from the.
Reads user data from a message.
String msgstring = inmsg.readstring (Inmsg.getmessagelength ());
Console output
SYSTEM.OUT.PRINTLN ("The message from the Queue is:/n/n" + msgstring);

Commit the transaction.
Commits a transaction.
Qmgr.commit ();

Close the the queue and Queue manager objects.
Closes the queue and Queue manager objects.
Queue.close ();
Qmgr.disconnect ();

catch (Mqexception ex) {

System.out.println ("An MQ Error occurred:completion Code is:/T" +
Ex.completioncode + "/n/n the Reason Code is:/T" + ex.reasoncode);
Ex.printstacktrace ();

catch (Exception e) {

E.printstacktrace ();

}

}

/**
* @param args
*/
public static void Main (string[] args) {
TODO auto-generated Method Stub
Ptpreceiver ();
}

}

Attention to character set issues

One: Mqenvironment.ccsid = 1381; (Specify the character set when Java connects code)

Two: Modify character set settings

In general, the MQ default character set in Unix andLinux is 819, and the Windows platform is 1381, so you have to change its character set so that the character set on both sides is the same. Change the method:

1. Through DOS into the MQ installation directory, into the/bin. If the queue manager you want to change is a

2. Use the instruction "strmqm a" to start the queue Manager a.

3. Use the instruction "RUNMQSC a" to start a mqsc.

4. The run instruction "alter QMGR CCSID (819)" "End" modifies the character set to 819

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.