Author |
Message
|
igor.beslic |
Posted: Thu Oct 15, 2009 1:34 am Post subject: JMS - How to publish Retained Message |
|
|
Novice
Joined: 15 Oct 2009 Posts: 14 Location: Zagreb, Croatia
|
Hi!
I'm trying to migrate MQ Java application to JMS application. After first tests when first subscribers connected I realized messages were not retained. (I got just messages published to topics after subscription). Unfortunetly, I can't find any appropriate way to publish retained message in JMS app.
My old MQ Java Code which retains messages:
Code: |
String message = "Some message...";
MessageParams params = new MessageParams();
params.setMessage(message); mqqueuemanager = getActiveMQManager(queueManagerOut);
MQMessage mqmessage = new MQMessage();
mqmessage.format = CMQC.MQFMT_STRING;
mqmessage.persistence = CMQC.MQPER_PERSISTENT;
mqmessage.expiry = -1;
mqmessage.write(params.getMessage().getBytes("UTF-8"));
mqmessage.characterSet = 1208; // set ccsid to 1208
MQPutMessageOptions options = new MQPutMessageOptions();
options.options += CMQC.MQPMO_RETAIN;
mqqueuemanager.put(CMQC.MQOT_TOPIC, "", queueManagerOut, topic, mqmessage, options); |
My new JMS Java Code which doesn't retain messages:
Code: |
MyMessage msg = new MyMessage("Some message...");
Session jmsSession = null;
MessageProducer mp = null;
Topic topic = null;
InitialContext ic = new InitialContext();
ConnectionFactory cf = (javax.jms.ConnectionFactory) ic.lookup("java:wmq/myFC");
javax.jms.Connection jmsConnection = cf.createConnection();
jmsConnection.start();
jmsSession = jmsConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
topic = jmsSession.createTopic(msg.getTargetTopic());
mp = jmsSession.createProducer(topic);
mp.send(jmsSession.createTextMessage(msg.getMessageText()));
mp.close();
jmsSession.close();
jmsConnection.close(); |
I use MQ7 Java API in old app and for new MQ7 JMS adapter deployed at JBoss 5.1.0.
this is connection factory configuration:
Code: |
<tx-connection-factory>
<jndi-name>wmq/myFC</jndi-name>
<xa-transaction />
<rar-name>wmq.jmsra.rar</rar-name>
<connection-definition>javax.jms.ConnectionFactory</connection-definition>
<config-property name="channel" type="java.lang.String">SYSTEM.DEF.SVRCONN</config-property>
<config-property name="hostName" type="java.lang.String">localhost</config-property>
<config-property name="port" type="java.lang.String">1414</config-property>
<config-property name="queueManager" type="java.lang.String">QM_MYQM</config-property>
<config-property name="transportType" type="java.lang.String">CLIENT</config-property>
<config-property name="username" type="java.lang.String">me@MYDOMAIN</config-property>
<security-domain-and-application>JmsXARealm</security-domain-and-application>
</tx-connection-factory> |
Thank you very much![/code] |
|
Back to top |
|
 |
fjb_saper |
Posted: Thu Oct 15, 2009 6:20 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
Quote: |
topic = jmsSession.createTopic(msg.getTargetTopic());
|
This seems just plain wrong to me.
At this point your message has been defined by new MyMessage();
We have no insight as to the topic definition you are going to use.
You do not "publish" retained messages. You publish to a topic.
That topic has been setup for retained publications i.e. the last published message on the topic is kept in the retained publication cache/store.
When you subscribe to the topic the first message available for consumption will be that retained message. It will be available only once, after subscription.
It would help if you could log the Topic in URI form before publishing to it, and the contents of the RFH psc folder
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
gbaddeley |
Posted: Thu Oct 15, 2009 4:05 pm Post subject: Re: JMS - How to publish Retained Message |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
igor.beslic wrote: |
Hi!
I'm trying to migrate MQ Java application to JMS application. After first tests when first subscribers connected I realized messages were not retained. (I got just messages published to topics after subscription). Unfortunetly, I can't find any appropriate way to publish retained message in JMS app.
|
Are you sure you are not confusing "retained message" (MQ saves one message per topic) with "durable subscription" (MQ saves all messages for durable subscribers that are not running) ? _________________ Glenn |
|
Back to top |
|
 |
igor.beslic |
Posted: Fri Oct 16, 2009 2:49 am Post subject: Re: JMS - How to publish Retained Message |
|
|
Novice
Joined: 15 Oct 2009 Posts: 14 Location: Zagreb, Croatia
|
gbaddeley wrote: |
Are you sure you are not confusing "retained message" |
I'm not sure In my project I'm publisher, another company team writes subscriber software. What they told me was that when they made durable subscription for the first time ever they haven't found any message at any of aproximately 500 topics I publish on. In eg. I started publisihing before two days. They subscribed today and were expected most recent message at every of topics. Unfortunetly they got nothing. BUT they started getting messages which I published after they subscribed.
They told me my messages weren't retained or what is probably more right my topics are not setuped for retained publication. |
|
Back to top |
|
 |
igor.beslic |
Posted: Fri Oct 16, 2009 3:12 am Post subject: |
|
|
Novice
Joined: 15 Oct 2009 Posts: 14 Location: Zagreb, Croatia
|
fjb_saper wrote: |
Quote: |
topic = jmsSession.createTopic(msg.getTargetTopic());
|
This seems just plain wrong to me.
At this point your message has been defined by new MyMessage();
|
OK. We have well known and defined TOPIC TREE structure but since messages comes via JCA resource adapter from another EIS I'm able to decode which topic I'm going to publish on in message time. Additionaly in message receive time I can't predict does TOPIC for that message already exists so I always do
Code: |
topic = jmsSession.createTopic(msg.getTargetTopic()); |
This is TOPIC TREE structure:
Code: |
STATUS/SYSTEM
STATUS/SYSTEM/SYSTEM01
STATUS/SYSTEM/SYSTEM02
STATUS/SYSTEM/SYSTEM03
... |
etc...
STATUS/SYSTEM is topic where global availability of publisher is published. Sub topics - I don't know the number of systems that will participate or even will they ever send a message. What I know that MAX_NUMBER could be around 500. Probably, when I receive message I should check is TOPIC available and if not create it.
Now when I know that I have to create topic enabled for retained publications I have 2 questions:
1. How to create topic enabled for retained publications using JMS interfaces only?
2. How to check an topic already exists using JMS interfaces only?
I say JMS interfaces because my code will be implementation vendor independent.
thanks. |
|
Back to top |
|
 |
fjb_saper |
Posted: Fri Oct 16, 2009 10:21 am Post subject: |
|
|
 Grand High Poobah
Joined: 18 Nov 2003 Posts: 20756 Location: LI,NY
|
This is just plain wrong. A topic for a publisher may look different in URI form than the same topic for the subscriber.
Think about delivery queue, think about additional topic attributes.
What you should at best be retrieving from the incoming message is not the topic but just the base topic string. You need then to incorporate that into the publisher's topic URI.
Check out the difference by stopping the broker.
Check a message that you create => look at the message using a queue browser and display the destination type and URI
Check a message created through RFHUtil => look at the message and do the same checks as above using the queue browser.
You will most probably note quite a difference in the Topic URI.
Have fun  _________________ MQ & Broker admin |
|
Back to top |
|
 |
|