Author |
Message
|
nilendu |
Posted: Wed Aug 27, 2008 10:56 am Post subject: Create a Topic and subscriber to a Topic |
|
|
Novice
Joined: 14 Sep 2006 Posts: 16
|
Hi All,
I am using JMS API to create a Topic and Subscribe to the Topic.
My question is how do we specify the queue name where the messages for a particular Topic be sent?
When I use JMS API as follows
-----------------------
TopicSession tSess = tConn.createTopicSession(false, Session.AUTO_ACKNOWLEDGE );
Topic t = (Topic)tSess.createTopic("test");
tSub = tSess.createSubscriber(t);
msg = (TextMessage)tSub.receive();
-----------------------
I cannot specify the QUEUE where the messages for the topic 'test' be sent. I believe they go to the broker default queue.
Please suggest!!!
Thanks,
Nilendu |
|
Back to top |
|
 |
bower5932 |
Posted: Wed Aug 27, 2008 12:17 pm Post subject: |
|
|
 Jedi Knight
Joined: 27 Aug 2001 Posts: 3023 Location: Dallas, TX, USA
|
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 27, 2008 1:00 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Try :
Topic t = session.createTopic("topic://mytopic?brokerDurSubQueue=SYSTEM.JMS.D.MYALIAS&brokerVersion=1")
Where SYSTEM.JMS.D.MYALIAS is an alias queue pointing to the real queue you want to receive your subscription on.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
nilendu |
Posted: Wed Aug 27, 2008 4:19 pm Post subject: |
|
|
Novice
Joined: 14 Sep 2006 Posts: 16
|
Hi fjb_saper,
Nope this didnt work. I created an ALIAS queue and made it part of my
createTopic() call -
topic://test?brokerDurSubQueue=MYALIAS&brokerVersion=1
These messages did arrive at the base Queue for MYALIAS. Where can I find the list of available parameter to topic://topicname URI?
I did make some progess though. When I burried the pubQueue name in the TopicConnectionFactory the message arrived at my pubQueue.
However, this is not what I want. I cannot ceate new connectionFactory object everytime I change my publisher queue.
--------------------
MQTopicConnectionFactory tcf = new MQTopicConnectionFactory();
tcf.setHostName("localhost");
tcf.setPort(1414);
tcf.setTransportType(JMSC.MQJMS_TP_CLIENT_MQ_TCPIP);
tcf.setQueueManager("QM_jxwgti4x9z9d1");
tcf.setChannel("SYSTEM.DEF.SVRCONN");
tcf.setBrokerPubQueue("TEST"); TopicConnection tConn;
tConn = tcf.createTopicConnection();
TopicSession tSess = tConn.createTopicSession(false,Session.AUTO_ACKNOWLEDGE);
Topic topic = (Topic)tSess.createTopic("topic://test");
MQTopicPublisher tp = (MQTopicPublisher)tSess.createPublisher(topic);
MessageProducer mprod = tSess.createProducer(d);
JMSTextMessage msg = (JMSTextMessage)tSess.createTextMessage("Hi Nilendu");
tp.publish(msg)
-----------------------
What am I missing in the Topic URI?
Thanks in advance to all,
Nilendu |
|
Back to top |
|
 |
fjb_saper |
Posted: Wed Aug 27, 2008 9:10 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
You got it all wrong.
What you want is the subscriber queue. (final destination of the published message).
You set this by creating the Topic as I showed you. You need to subscribe with this topic. Then all your publications for this topic will be sent to the subscription queue. You may be able to do this differently using RFHUtil(c)..., (played around with RFHUtil(c) and alias queues and inspected the message... this is how I found out the specific URI form for the topic...) however if you want to specify the queue dynamically at subscription time you will need to do something like what I showed you.
Remember that to change the destination queue you need to change the subscription. Also for the queue name the start SYSTEM.JMS.D. is mandatory for durable subscription (see pub/sub manual).
I went around it by creating an alias for my true base queue.
Once this is done you can either receive messages to the topic or you can receive messages to the queue. Receiving messages to the queue will give them to you in arrival order (or priority) regardless of topic. If you want them by topic use a topic receiver.
Finally read the documentation for version 7. There are a lot of changes in pub/sub and you can have the admin subscribe you (I think).
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
nilendu |
Posted: Thu Aug 28, 2008 1:45 pm Post subject: |
|
|
Novice
Joined: 14 Sep 2006 Posts: 16
|
Hi fjb_saper,
Thanks for your help. I used the rfhutil today.
Here are the steps I followed
1) selected reg pub ->
registered a publisher and provided a topic name 'test'
used SYSTEM.BROKER.CONTROL.QUEUE as the queue name
provided my SYSTEM.BROKER.D.MYALIAS.QUEUE as the subscription Queue
2) Selected Publish tab
provided the topic name - 'test'
Queue name as SYSTEM.BROKER.CONTROL.QUEUE
3) Selected Sub tab
provided the topic name 'test'
SubName - SYSTEM.BROKER.D.MYALIAS.QUEUE
And then wrote a message. I can see the message waiting at SYSTEM.BROKER.CONTROL.QUEUE
when I end the broker. As soon as I start the broker the messages move from my borker control
queue but doesnt apprear in my alias/base queue.
Wondering what's going wrong here.
I have checked that my alias/base queue config is correct since when I use p2p mode and puta message
onto alias queue, the message arrives at my base queue.
Please advice....
Thanks,
Nilendu |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Aug 28, 2008 3:14 pm Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
nilendu wrote: |
Hi fjb_saper,
Thanks for your help. I used the rfhutil today.
Here are the steps I followed
1) selected reg pub ->
registered a publisher and provided a topic name 'test'
used SYSTEM.BROKER.CONTROL.QUEUE as the queue name
provided my SYSTEM.BROKER.D.MYALIAS.QUEUE as the subscription Queue
2) Selected Publish tab
provided the topic name - 'test'
Queue name as SYSTEM.BROKER.CONTROL.QUEUE
3) Selected Sub tab
provided the topic name 'test'
SubName - SYSTEM.BROKER.D.MYALIAS.QUEUE
And then wrote a message. I can see the message waiting at SYSTEM.BROKER.CONTROL.QUEUE
when I end the broker. As soon as I start the broker the messages move from my borker control
queue but doesnt apprear in my alias/base queue.
Wondering what's going wrong here.
I have checked that my alias/base queue config is correct since when I use p2p mode and puta message
onto alias queue, the message arrives at my base queue.
Please advise....
Thanks,
Nilendu |
2) You need to publish a message. The default pub queue is something like SYSTEM.BROKER.DEFAULT.STREAM but I would check the pub/sub manual.
Enjoy  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|