MQ information (reproduced)

xiaoxiao2021-03-06  62

One. There are several important components in MQ basic operation MQ: QueueManager, Queue, and Channel. The basic operation method is as follows: Create queue manager CRTMQM -Q qMgrName -q refers to the creation of the default queue manager delete queue manager DLTMQM QMGRNAME Start Queu Manager Strmqm QmgrName If it is the start of the default queue manager, you can bring Its Name Stop Queue Manager ENDMQM QMGRNAME Control Stop Endmqm -i QMGRNAME Stop Endmqm -p QMGRNAME Force Stop Show Queue Manager DSPMQ -M QMGRNAME Run MQSERIES Command Runmqsc QMGRNAME If it is the default queue manager, you can bring your name to the queue Mid-place message amqsput Qname QMGRNAME If the queue is the queue in the default queue manager, you can take the name from the queue manager from the queue amqsget qname QmgrName If the queue is the queue in the default queue manager, you can do not bring its queue Manager's name start channel Runmqchl -c chlname -m qmgrname launched Runmqlsr -t type -p port -m QMGRNAME stop listening endmqlsr -m QMGRNAME MQSERIES command Defining a Dead Letter Qlocal (QNAME) Defpsist (YES) Replace Define QMGR Deadq (QNAME) ALTER QMGR DEADQ (QNAME) Defining Local QMGR Deadq (QNAME) Replace Defining Alias ​​QLINE Qalias (QaliasName) Targq (QNAME) remote queue definition define qRemote (QRNAME) RNAME (AAA) RQMNAME qMGRNAME) XMITQ (QTNAME) defines a model queue dEFINE QMODEL (QNAME) DEFTYPE (TEMPDYN) defines the local transmission queue dEFINE QLOCAL (QTNAME) USAGE (XMITQ) DEFPSIST (YES) INITQ (SYSTEM.CHANNEL.INITQ) PROCESS (PROCESSNAME) Replace Creating Process Definition Define Process (PRONAME) Descr ('String') AppLType (WindowsNT) Applici D ('Runmqchl -c SDR_TEST -M QM_ Test') where the value of AppLType can be: CICS, UNIX, Windows, WindowsNT, etc. Creating a sender channel DEFINE CHANNAME CHLTYPE (SDR) Conname ('100.100.100.215 (1418 ) ') XMitq (QtName) Replace where CHLTYPE can be: SDR, SVR, RCVR, RQSTR, CLNTCONN, SVRCONN, CLUSSDR, and Clusrcvr.

Create Receiver Channel Define Channel (SDR_ Test) CHLTYPE (RCVR) Replace Creating Server Connection Channel Define Channel (SvrConnname) CHLTYPE (SVRCONN) Replace Display Queue All Properties Display Queue (QNAME) [all] Display queue selected Properties Display queue (QNAME) DESCR GET PUT dISPLAY qUEUE (QNAME) MAXDEPTH CURDEPTH display queue manager all attributes dISPLAY QMGR [ALL] display process Definition dISPLAY pROCESS (pRONAME) change properties ALTER QMGR DESCR ( 'NEW DESCRIPTION') ALTER QLOCAL (QNAME) PUT (Disabled) ALTER Qalias (QNAME) Targq (TargqName) Delete Queue DELETE QLOCAL (QRNAME) Delete QLEMOTE (QRNAME) Clear all messages in the queue Clear Qlocal (QNAME). Configuring a remote connection that can communicate with the basic command operation of MQ, but only knows that these are not practical. The ultimate goal of MQ is to implement remote communication, so below will explain how to implement remote connections with a specific example. The purpose of this example is to establish a pair of MQ servers that enable messaging, which are based on NT and UNIX platforms, respectively.

First, build a queue manager CRTMQM -Q qm_nt startup queue manager strMqm QM_NT running the MQ console command Runmqsc QL (NT.DEADQ) DEFPSIST (YES) Replace Change QL (NT.DEADQ) DEFPSIST (YES) Replace Change Queue Manager Properties Dead letter queue ALTER QMGR DEADQ (NT.DEADQ) Creating Process Definition Define Process (P_NT) AppLTYPE (WindowsNT) Applicid ('Runmqchl -c SDR_NT -M QM_NT') Create a local transmission queue Define QL (Qt_NT) USAGE (XMITQ) Defpsist (yes) initq (system.channel.initq) process (p_nt) Replace creates a remote queue definition, corresponding to the local queue Q_Unix on the UNIX machine, the transfer queue is qt_nt define qRemote (QR_NT) RQMNAME ( QM_UNIX) XMITQ (QT_NT) creates a sender channel, and its transmission queue is qt_nt, the remote host address is 10.10.10.2, the listening port is 1414 define channel (SDR_NT) CHLTYPE (SDR) Conname ('10.10.10.2 (1414) ') Xmitq (QT_NT) Replace Creating Server Connection Channel DEFINE CHANEL (S_NT) CHLTYPE (SVRCONN) Replace Create queue Manager CRTMQMQM -QM_UNIX Start Queue Manager Strmqm QM_UNIX Add Listening Program Modify / etc / Services file, join One line: MQSeries 1414 / TCP #MQSeries Channel Listener Modify /etc/inetd.conf file, join a line (start listener) MQSeries stream TCP NOWAIT MQM / USR / LPP / MQM / BIN / AMQCRSTA AMQCRSTA -M QM_UNIX runs the following command, To make the modification, REFRESH -S INETD is running MQ console command Runmqsc QM_Unix creates a dead letter queue define QL (UNIX.deadq) Defpsi ST (YES) Replace Change Queue Manager Properties, sets its dead letter queue ALTER QMGR Deadq (UNIX.DEADQ) to create a recipient channel, and its name must be the same as the remote sender to create a local queue to create a local queue (RCVR) Replace Define QL (Q_Unix) Defpsist (YES) Replace Creating Server Connection Channel Define Channel (S_UNIX) CHLTYPE (SVRCONN) Replace After the above operation, the configuration work of the remote connection is completed. Next, you need to verify that the configuration is correct.

Start the sender channel Runmqchl -c SDR_NT -M QM_NT or START CHL (SDR_NT) from the NT end to UNIX end AMQSPUT QR_NT QM_NT Receive message / USR / MQM / SAMP / BIN / AMQSGET Q_UNIX QM_UNIX Received a message, indicating that the configuration is successful. In addition, in NT, the listener is automatically established when the queue manager is established, and the listener is automatically started when the queue manager is started. Of course, you can also manually configure the listener. Modify the / Winnt / System32 / Drivers / etc / service file, add a line in the file: MQSeries 1414 / TCP #MQSeries Channel Listener launched the listener Runmqlsr -t tcp -p 1414 -m qm_nt above explains how to establish a simple one-way transporting network. The message is sent from the NT terminal to the UNIX terminal. Establish a remote connection from UNIX to the NT side, which is similar, and the same reason is to establish a two-way transport network. three. JNDI is often used when configuring the JNDI to implement the message and reception of messages. Because JNDI is more flexible, it is relatively simple for programming. After installing the MQSeries Client for Java, find the JMSAdmin.config file in the / java / bin directory. This file is mainly used to illustrate the storage mode and storage address of the Context, corresponding to the two parameters in the file, initial_context_factory, and provider_url. Typical JMSAdmin.config document reads as follows: # INITIAL_CONTEXT_FACTORY = com.sun.jndi.ldap.LdapCtxFactory INITIAL_CONTEXT_FACTORY = com.sun.jndi.fscontext.RefFSContextFactory # INITIAL_CONTEXT_FACTORY = com.ibm.ejs.ns.jndi.CNInitialContextFactory # # PROVIDER_URL = LDAP: // Polaris / O = IBM, C = US provider_url = file: / d: / temp # urgeder_url = iiop: // localhost / # security_Authentication = none initial_context_factory represents the service provider used by JMSADMIN TOOL. There are currently three supported values. com.sun.jndi.ldap.ldapctXFactory is used for LDAP, if you use it, you must install an LDAP server. com.sun.jndi.fscontext.reffsContextFactory is used in the file system context, which only requires the user to provide the file path to the context. com.ibm.ejs.ns.jndi.cninitialContextFactory is designed for WebSphere, which needs to be used with WebSphere's CoSNaming repository. Provider_url indicates the URL of the session initial context, and the root of all JNDI operations implemented by JMSADMIN TOOL. It corresponds to initial_context_factory. LDAP: // Hostname / ContextName For LDAP File: [Drive:] / Pathname Used for File System Context IIOP: // Hostname [: Port] / [? TargetContext = CTX] For accessing WebSphere cosnaming namespace, there is one Parameter security_authentication, is used to explain whether JNDI passes security credentials to your service provider. This parameter is only used when using an LDAP service provider.

This parameter has three values, NONE (anonymous authentication), Simple, and CRAM-MD5 authentication mechanism. If no valid value is provided, the default is None. After confirming the configuration file, you can start the JMSADMIN console in the / java / bin directory. You can also start the console in any directory: jmsadmin -cfg mq_java_install_path / java / bin / jmsadmin.config where mq_java_install_path is the root directory installed by MQSeries Client for Java. If the startup fails, check if your environment variable is set correctly. According to my personal experience, in addition to add com.ibm.mq.jar and com.ibm.mqjms.jar, add fscontext.jar and providerutil.jar to the environment variable. Once you enter the JMSADMIN console, you can freely define the Sub Context. For the operation of the sub context, there is a command: Display CTX Define CTX (CTXName) CHANGE CTX (CTXName) CHANGE CTX (= Up) CHANGE CTX (= init) delete ctx (ctxname) Of course, the main task here is not used To define sub context, but use the following objects: MQQueueConnectionFactory MQTopicConnectionFactory MQQueue MQTopic (there are other objects, such as MQXAQUECONNECTIONFAACTORY, are not commonly used, not explained here.) You can use a lot of verbs to manipulate directory namespace Affected object in. Alter, Define, Display, Delete, Copy and Move, their usage is relatively simple, and only one or two will be described here. Example: defining a QueueConnectionFactory, connection to the host 10.10.10.18, port 1414 DEFINE QCF (EXAMPLEQCF) DESC (Example Queue Connection Factory) TRAN (CLIENT) HOST (10.10.10.18) QMGR (QM_EXAMPLE) CHAN (S_EXAMPLE) Port (1414) CCSID (1381) 2: Define a Queue, which corresponds to Q_Example DEFINE Q (EXAMPLEQL) QMGR (QM_Example) QUEUE (QM_EXAMPLE) CCSID (1381) four. Using JMS to implement MQ programming above, we explain how to use JMSADMIN TOOL to define the context of the MQ object. Our ultimate goal is to use JMS to implement MQ programming to implement the MQ queue in the program. So, below will focus on discussing the MQ JMS implementation. If you are familiar with JMS programming, you will use JMS to implement MQ programming, because use JMS to write MQ programs and write a general JMS program without much difference. For example, when we want to send a message to the Queue of MQ, we have four steps when we retrieve the message from the queue. First we have to initialize the object to be used in the program, and then send a message to the queue, and then collect the message, and finally clear those permanent objects. These are quite equivalent to ordinary JMS programs.

The source code follows: import java.util.Hashtable; import javax.jms *; import javax.naming *; import javax.naming.directory *; public class sample {protected QueueConnectionFactory factory = null; protected QueueConnection connection;... protected QueueSession queueSession; protected TextMessage outMessage; protected QueueSender queueSender; protected QueueReceiver queueReceiver; public static final String qcfLookup = "EXAMPLEQCF"; public static final String qLookup = "EXAMPLEQL"; public static final String icf = "com.sun.jndi.fscontext .RefFSContextFactory "; public String url =" file: / d: / temp "; public void sampleInit () throws Exception {Hashtable environment = new Hashtable (); environment.put (Context.INITIAL_CONTEXT_FACTORY, icf); environment.put (Context .PROVIDER_URL, url); environment.put (Context.REFERRAL, "throw"); Context ctx = new InitialDirContext (environment); factory = (QueueConnectionFactory) ctx.lookup (qcfLookup); Queue q1 = null; q1 = (Queue) Ctx.lookup (Qlookup); connection = factory.createqueueConnectio n (); queueSession = connection.createQueueSession (false, Session.AUTO_ACKNOWLEDGE); queueSender = queueSession.createSender (q1); queueSender.setDeliveryMode (DeliveryMode.NON_PERSISTENT); outMessage = queueSession.createTextMessage (); queueReceiver = queueSession.createReceiver (q1 ); connection.start ();} public void sendMessageOut (String message) throws JMSException {outMessage.setText (message); queueSender.send (outMessage);} public String receiveMessage () throws Exception {return ((TextMessage) queueReceiver.receive ()); public void sample (). JMSException {queness.close (); connection.close ();

转载请注明原文地址:https://www.9cbs.com/read-114236.html

New Post(0)