WMQ
ConfigurationHostName Channel
A one-way point-to-point communication connection between queue managers, where messages flow in the channel Port QueueManager
Message Queuing Manager connectionnamelist
Cluster cluster, a queue manager belongs to multiple clusters clientreconnectoptions CCSID TransportType
API
dependencies:
* Mq-x
* Connector-x
* Jmqi-x
* Commonservices-x
* Headers-x
* Mqjms-x
public static void Send (String qName, String msg) throws Mqexception, IOException {
hashtable<string, object> PR operties = new hashtable<string, object> ();
Properties.put (Mqconstants.connect_options_property, mqconstants.mqcno_reconnect);
Properties.put (Mqconstants.host_name_property, connectionname);
Properties.put (Mqconstants.port_property, PORT);
Properties.put (Mqconstants.channel_property, CHANNEL);
Properties.put (Mqconstants.ccsid_property, CCSID);
Mqqueuemanager queuemgr = new Mqqueuemanager (Qmanager, properties);
Mqqueue queue = Queuemgr.accessqueue (qName, openoptions, NULL, NULL, NULL);
Mqmessage outmsg = new Mqmessage ();
Outmsg.write (Msg.getbytes ("UTF-8"));
Queue.put (outmsg, New Mqputmessageoptions ());
Queuemgr.commit ();
Queue.close ();
Queuemgr.disconnect ();
}
Connection Pool
By default, each new Mqqueuemanger () call means that the application has one more connection to the Queue manager and is represented as a TCP/IP connection in the MQ Clinet/server fabric. This connection disconnects each time mqqueuemanger.disconnect (), which is the TCP/IP connection. For example, in the same thread, if you repeatedly connect and then disconnect MQ Connection, in the MQ Clinet/server fabric as a recurring connection and then disconnect the TCP/IP connection, you can see traces in the system with the Netstat command, that is, after each disconnection time_ The wait state.
Cases:
for (int i = 0; i < i++) {
qmgr = new Mqqueuemanager (smqname);
...
Qmgr.disconnect ();
}
If the connection pool Connection pool is used, the MQ connection is not actually disconnected at mqqueuemanger.disconnect (), but only the connection pool is returned and reused at the next new Mqqueuemanager.
Mqpooltoken token = Mqenvironment.addconnectionpooltoken ();
for (int i = 0; i <; i + +)
{
qmgr = new Mqqueuemanager (sqmname);
...
Qmgr.disconnect ();
}
Mqenvironment.removeconnectionpooltoken (token);
In the case of concurrent threads, if the new Mqqueuemanager () between the threads is serial, the connection can be shared across threads;
If it is concurrent, you can create a connection reuse environment for each thread that is reused between the serial new Mqqueuemanager () operations of this thread.
for (int i = 0; i < 3; i + +)
{
thread = new Mqconnectionpoolthread (sqmname);
Thread.Start ();
}
Class Mqconnectionpoolthread extends Thread
{
...
public void Run ()
{
token = Mqenvironment.addconnectionpooltoken ();
for (int i = 0; i < 5; i + +)
{
try
{
***synchronized (getclass ()) * * *
{
qmgr = new Mqqueu Emanager (sqmname);
Sleep (+);
Qmgr.disconnect ();
}}} Mqenvironment.removeconnectionpooltoken (token);
}
}
The default connection pool in Mqenvironment can hold up to 10 useless connections, each of which remains 5min long.
For example: There are 15 concurrent new Mqqueuemanager (), and there will be 15 useful connections.
12 of them are soon mqqueuemanager.disconnect (), when the application will have 3 useful connections, 10 useless connections, and 2 disconnected.
You can use Mqenvironment.setdefaultconnectionmanager (Mqconnectionmanager) to set the Connection pool you created as the default Connection pool.
Mqconnectionmanager is a private interface, and there is only one class in MQ Java Base that implements this interface: Mqsimpleconnectionmanager
The Mqqueuemanager constructor has one of the following: public Mqqueuemanager (String
Queuemanagername,mqconnectionmanager Cxmanager) indicates that the created connection joins the Connection Pool in Cxmanager, which is managed by Cxmanager (most useless connections, timeouts, and so on). spring-cachingconnectionfactory
dependencies:
* Jms-api-x
* Dhbcore-x configuration
<bean id= "Mqqueueconnectionfactory" class= "Com.ibm.mq.jms.MQQueueConnectionFactory" >
<!--See configuration--
</bean>
<bean id= "cachingconnectionfactory" class= " Org.springframework.jms.connection.CachingConnectionFactory ">
<property name=" targetconnectionfactory "ref=" Mqqueueconnectionfactory "/>
<property name=" sessioncachesize "value=" x "/>
</bean>
<bean id= "Senderqueue" class= "Com.ibm.mq.jms.MQQueue" >
<property name= "basequeuename" value= "XX" />
<property name= "basequeuemanagername" value= "xx"/>
</bean>
<bean id= " Jmstemplate "class=" org.springframework.jms.core.JmsTemplate ">
<property name=" ConnectionFactory "ref= "Cachingconnectionfactory"/>
<property name= "Pubsubdomain" value= "false"/>
Note Item
Return code=2082 mqrc_unknown_alias_base_q Opening a queue in the cluster.
Just leave the Basequeuemanagername blank
Reference
When sending, when there are multiple queues, it is recommended to use
Jmstemplate.convertandsend (QueueName, msg); JNDI Configure Tomcat
<!--context.xml Start-to <resource name= "Jms/xxxmq" auth= "Container" type= "Com.ibm.mq.jms.MQQueueConnec Tionfactory "factory=" com.ibm.mq.jms.MQQueueConnectionFactoryFactory "description=" "host=" xxx "port=" xxx " chan= "xxx" tran= "1" ccsid= "xxx" qmgr= "xxx"/> <resource name= "Jms/sendqueue" auth= "Container" type = "Com.ibm.mq.jms.MQQueue" factory= "Com.ibm.mq.jms.MQQueueFactory" description= "ACTIVITY message input queue" qu= "C Mf_inputq "ccsid=" 1208 "/> <!--context.xml End--<!--spring cfg start-to <jee:jndi-lookup id=" Mqco Nnectionfactory "Jndi-name=" Jms/xxxmq "resource-ref=" true "/> <bean id=" jmstemplate "class=" Org.springframework.jms.core.JmsTemplate "> <property name=" connectionfactory "ref=" mqconnectionfactory "/ > <property name= "defaultdestination" ref= "Sendqueue"/> <property name= "Pubsubdomain" Valu E= "false"/> </bean> <!--SPRing CFG end---
Java Code
@AutoWired
jmstemplate jmstemplate;
...
Jmstemplate.convertandsend (msg);
Jmstemplate.convertandsend (Destinationname, msg);
...
PS: omitted the MQ interface on the queue and other configurations