Research MQ7.0 IntelligentMulticast
转载请注明出处:http://blog.csdn.net/javalover_yao/article/details/8612569
一、Preparative
MQ Server: MQ7.0.1.5
Operating System: Windows 7 Enterprise.
MQ Java Client: jdk1.6.0_10
OS : Windows 7 Enterprise
MQ Configure Diagram summary:
二、Test Procedure
2.1 Configure the MQ Server
1. Create Queue Manager: QM1, port:1415
Right click theQueue Manger menu and then click new, you will see the wizard of create queuemanager.
Enter the queuemanager name: QM1, and tick the Create server-connection channel option,t thenclick next
At the nextpanel tick the Create listener configured for TCP/IP option, and define theport to 1415.
Others keepdefault, click finish to accomplish the creation.
2. Create Queue Manager: QM2, port 1416
Follow the step1 to create the queue manger QM2, and define the port to 1416.
3. Create Transmission Queue in QM1
Right click the Queues and the click new, select the Local Queue,you will see the create wizard.
Enter the Queue name and click next button to the next panel.
At the General option, the property of the Usage you must to selectthe Transmission
At the Extended option, the property of the Distribution lists mustselect Supported
And then click the Finish button to accomplish your creation.
You will see the transmission queue:
4. Create Sender/Receiver Channel
At QM2 site,create a receiver channel:
Enter thechannel name and then click Finish:
You will seethe receiver channel:
At QM1 site,create the sender channel:
Enter thesender channel name, note that the sender channel mustbe the same name as the QM2’s receiver channel name. Then click the nextbutton to the next panel:
In this panel,you must enter the Connection name, the connection name pattern will like [ip(port)], in this test, I use 127.0.0.1 (1416), as we know ,port 1416 is pointto the QM2.
Click the Selectbutton to select a transmission queue which I have created in the step 3.
Then clickFinish button , you will see the sender channel:
To start thesender channel in QM1 site, it will connect to QM2’s receiver channel.
5. Create three Local queues in QM2 site, named A, B,C
6. Create three Alian queues in QM2 site, they each pointed to thelocal queue(A,B,C)
Follow thewizard to accomplish:
You will enterthe Base object, it is the name of the local queue which this alian queue willpointed to.
After step 6 and 7, you will see the queues like below:
7. Create Remote queue in QM1 site, they each pointed to the alianqueue(A,B,C) in QM2
Followthe wizard:
Enterthe remote queue name, click next:
Inthe next panle, you must enter the Remote queue(this value is the alian queuename of inQM2), you must enter the Remote queue manager(QM2), you must clickselect button to choose the transmission which you have created in step 3:
Then click Finish button.
Follow the same step below to create othertwo remote queue
8. Create Topic in QM1 site:
Enter the name then click next, Topic mustentered, it is defined by yourself.
Others keep default, then click finish. Youwill see the topic you created:
9. Created three Subscrpitions in QM1:
The three Subscrpitions each used by the threeremote queue in QM1
Follow the wizard:
Enter the name then click next, in the next panel, click the selectbutton to select one topic which you has created in step 8.
Destination queue manager is QM1 and the destination queue is theremote queue.
Then click finish, follow the steps aboveto create other two subscripitions.
You will see like below:
10. Have a test for the Topic
Publish a testmessage to the Topic, the three local queue in QM2 site will receive themessage:
转载请注明出处:http://blog.csdn.net/javalover_yao/article/details/8612569
Click Publishmessage, then we can the message are located in the three local queue in QM2site:
2.2 Using java API to Publish a message to Topic
1. Create some internal queue of MQ Server
Find the file named : MQJMS_PSQ.mqsc at the loacation:
C:\Program Files\IBM\WebSphere MQ\java\bin
Copy this file tothe folder : C:\Program Files\IBM\WebSphere MQ\bin
Use the cmd toexecute the command defined by MQ:
The command is: runmqsc –m QM1 < MQJMS_PSQ.mqsc
Then you will seethe successful information:
2. To start the QM1 message broker
Use the command to start the message broker of QM1:The command is : strmqbrk –m QM1
3.To create a server connection channel in QM1
Enter the name , and then click finish, youwill see the server connection channel:
4.Write java code to test
public static void main(String[] args)throws Exception { try { MQTopicConnectionFactory tcf = new MQTopicConnectionFactory(); tcf.setHostName("10.39.105.99"); tcf.setTransportType(1); tcf.setPort(1415); tcf.setChannel("QM1_SERVER_CHAN"); tcf.setQueueManager("QM1"); tcf.setBrokerQueueManager("QM1"); tcf.setCCSID(1381); TopicConnection tConn = tcf.createTopicConnection(); tConn.start(); TopicSession tSession = tConn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); Topic topic = tSession.createTopic("QM1.CENTER.BANK.PUB.TOPIC"); TopicPublisher tPub = tSession.createPublisher(topic); Message msg = tSession.createTextMessage("hello, Jason"); tPub.publish(msg); tSession.close(); tConn.close(); tPub.close(); }catch(Throwable e) { e.printStackTrace(); }finally {
} } |
After execute this code, the three localqueue of QM2 will receive the message.
2.4 Implement Intelligent Multicast
Think about that if one message are publishto the topic , the three local queue of QM2 will receive it, what if I justwant local queue A to receive message. How to implement?
When we create the subscription, there isan optional field to use, it is the message selector, if we configured thesubscription A like below:
The selector value we entered is HSBC_CNTY_CODE=’AP’
And then we write the code:
public static void main(String[] args)throws Exception { try { MQTopicConnectionFactory tcf = new MQTopicConnectionFactory(); tcf.setHostName("10.39.105.99"); tcf.setTransportType(1); tcf.setPort(1415); tcf.setChannel("QM1_SERVER_CHAN"); tcf.setQueueManager("QM1"); tcf.setBrokerQueueManager("QM1"); tcf.setCCSID(1381); TopicConnection tConn = tcf.createTopicConnection(); tConn.start(); TopicSession tSession = tConn.createTopicSession(false, TopicSession.AUTO_ACKNOWLEDGE); Topic topic = tSession.createTopic("QM1.CENTER.BANK.PUB.TOPIC"); TopicPublisher tPub = tSession.createPublisher(topic); Message msg = tSession.createTextMessage("hello, Jason"); msg.setStringProperty("HSBC_CNTY_CODE","VN"); tPub.publish(msg); tSession.close(); tConn.close(); tPub.close(); }catch(Throwable e) { e.printStackTrace(); }finally {
} } |
You can see I set a named property:
msg.setStringProperty("HSBC_CNTY_CODE", "VN");
转载请注明出处:http://blog.csdn.net/javalover_yao/article/details/8612569
After execute this code, the local queue A ofQM2 will not receive the message while the other two local queues will receivethe message.