Author |
Message
|
mvic |
Posted: Tue Nov 04, 2008 2:47 am Post subject: |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
masteringmq wrote: |
I found a JMS code for pub/sub. But I cant find any for MQ Java. |
OK, but JMS is really a much better set of classes for doing pub/sub with MQ. Can your application perhaps use JMS? The classes are provided with an MQ installation. |
|
Back to top |
|
 |
masteringmq |
Posted: Tue Nov 04, 2008 6:47 pm Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
Yes I installed JMS classes which comes along with the MQ 7 installation. I will be using JMS in this case. Also I would like to clarify the following for MQ:
DEFINE TOPIC(FRUIT) TOPICSTR('Price/Fruit') DURSUB(NO)
DISPLAY TPSTATUS('Price/Fruit')
DEFINE TOPIC(ORANGES) TOPICSTR('Price/Fruit/Orange')
DEFINE QALIAS(PRICES) TARGTYPE(TOPIC) TARGET(ORANGES)
DEFINE SUB(ORANGES.TO.Q1) TOPICSTR('Price/Fruit/Orange') DEST(QM1.REPLY)
DEFINE SUB(FruitPrices) TOPICSTR('Price/Fruit/+') DEST(QM1.REPLY)
I realize it only works on MQ 7 and not below. Meaning that when I try to DEFINE TOPIC in MQ 6 it does not work. Please advice.
Last edited by masteringmq on Wed Nov 05, 2008 5:10 am; edited 2 times in total |
|
Back to top |
|
 |
mvic |
Posted: Wed Nov 05, 2008 3:09 am Post subject: |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
I didn't understand what question is being asked, sorry. |
|
Back to top |
|
 |
masteringmq |
Posted: Wed Nov 05, 2008 4:19 am Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
when I try:
7 : DEFINE SUB(ORANGES.TO.Q1) TOPICSTR('Price/Fruit/Orange') DEST(QM1.REPLY)
AMQ8519: The topic object does not permit durable subscription.
I am getting the following error. Please advice. |
|
Back to top |
|
 |
mvic |
Posted: Wed Nov 05, 2008 4:38 am Post subject: |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
masteringmq wrote: |
when I try:
7 : DEFINE SUB(ORANGES.TO.Q1) TOPICSTR('Price/Fruit/Orange') DEST(QM1.REPLY)
AMQ8519: The topic object does not permit durable subscription. |
Code: |
$ mqrc AMQ8519
536904985 0x20008519 urcMS_DURABILITY_NOT_ALLOWED
MESSAGE:
The topic object <insert one> does not permit durable subscription.
EXPLANATION:
The topic object <insert one> has been defined to disallow durable
subscription.
ACTION:
Ensure that the topic object to which you are creating a subscription allows
durable subscription.
|
|
|
Back to top |
|
 |
masteringmq |
Posted: Wed Nov 05, 2008 4:44 am Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
DURSUB(YES) and I can define. |
|
Back to top |
|
 |
masteringmq |
Posted: Wed Nov 05, 2008 4:48 am Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
Now it works  |
|
Back to top |
|
 |
masteringmq |
Posted: Wed Nov 05, 2008 5:13 am Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
when I put a single message in QALIAS(PRICES), two messages appear in QM1.REPLY. Please advice. SUB(ORANGES.TO.Q1) and SUB(FruitPrices) displays a message count of 1 each. |
|
Back to top |
|
 |
mqjeff |
Posted: Wed Nov 05, 2008 5:31 am Post subject: |
|
|
Grand Master
Joined: 25 Jun 2008 Posts: 17447
|
That means that everything is working correctly.
Pub/Sub is one to many. |
|
Back to top |
|
 |
masteringmq |
Posted: Wed Nov 05, 2008 5:34 pm Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
I also know that there is the possibility for a one to one model of pub/sub. |
|
Back to top |
|
 |
masteringmq |
Posted: Wed Nov 05, 2008 9:29 pm Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
Publisher:
Price/Stock/NYSE/
Price/Stock/NYSE/BOA
Price/Stock/NYSE/CITI
Price/Stock/NYSE/CHASE
So on the MQ level I need to create Price/Stock/NYSE/ and from the Java application level I create the topic Price/Stock/NYSE/BOA and assign the value for BOA share. Is this the process?. Please advice. |
|
Back to top |
|
 |
mvic |
Posted: Thu Nov 06, 2008 2:30 am Post subject: |
|
|
 Jedi
Joined: 09 Mar 2004 Posts: 2080
|
masteringmq wrote: |
I also know that there is the possibility for a one to one model of pub/sub. |
If you enforce (somehow, perhaps via API exits?) that there is only one subscriber for a given topic then this would be one-to-one - ie. one producer and one consumer of messages.
But that's not how pub/sub is expected to be used. The expected "pattern" is for the publisher to publish, and for subscribers to subscribe, with the topic string being the only linkage between them. And the linkage is one-to-many. That's the pattern. |
|
Back to top |
|
 |
masteringmq |
Posted: Thu Nov 06, 2008 3:18 pm Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
I came up with a basic publish and subscribe code. However this is within a queue manager QM1. I intent to publish on queue manager QM1 but on queue manager QM2 people will be able to subscribe to the topic. In other words a distributed pub/sub. How can this be achieved?. Please advice.
/**
* @(#)PubSub.java
*
* PubSub application
*
* @author
* @version 1.00 2008/11/6
*/
import javax.jms.*;
import javax.naming.*;
import com.ibm.mq.jms.*;
import com.ibm.jms.JMSTextMessage;
import com.ibm.jms.JMSMessage;
public class PubSub
{
public static void main(String[] args) throws Exception
{
MQTopicConnectionFactory factory = new MQTopicConnectionFactory();
factory.setQueueManager("QM1");
MQTopicConnection connection = (MQTopicConnection)factory.createTopicConnection();
MQTopicSession session = (MQTopicSession)connection.createTopicSession(false, Session.AUTO_ACKNOWLEDGE);
MQTopic topic = (MQTopic)session.createTopic("Price/Fruit/Apple");
MQTopicPublisher publisher = (MQTopicPublisher)session.createPublisher(topic);
MQTopicSubscriber subscriber = (MQTopicSubscriber)session.createSubscriber(topic);
JMSTextMessage message = (JMSTextMessage)session.createTextMessage("hello");
connection.start();
publisher.publish(message);
JMSMessage receivedMessage = (JMSMessage)subscriber.receive(1000);
System.out.println(receivedMessage);
publisher.close();
session.close();
connection.close();
}
}
MQTopicConnectionFactory methods
- setHostName
- setPort
- setTransportType
- setChannel
I imagine the above menthod is applicable if I were to publish VIA server con channel to a host machine from a client. |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Nov 06, 2008 8:13 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20763 Location: LI,NY
|
Connecting to QM2 you need to specify on the topic connection factory that your broker is QM1. Also in the topic uri when you subscribe you need to specify the subscription queue being QM2/something....
Play around with rfhutil support pack IH03 and the file based JNDI and have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
masteringmq |
Posted: Thu Nov 06, 2008 9:16 pm Post subject: |
|
|
Master
Joined: 20 Oct 2008 Posts: 200
|
|
Back to top |
|
 |
|