|
RSS Feed - WebSphere MQ Support
|
RSS Feed - Message Broker Support
|
 |
|
publish/subscribe - How to ensure persistent delivery |
« View previous topic :: View next topic » |
Author |
Message
|
igor.beslic |
Posted: Wed Feb 23, 2011 7:20 am Post subject: publish/subscribe - How to ensure persistent delivery |
|
|
Novice
Joined: 15 Oct 2009 Posts: 14 Location: Zagreb, Croatia
|
Hi, plese help me to solve my Publish/Subscribe problem. I have publisher that publishes to topic named FEED every 5min.
There are random number of subscribers who occationaly connects to MQ and read latest message from topic.
My problem is that when subscriber connects there is nothing at topic. After while when publisher was triggered by timer and message is published, subscriber receives message.
My scenario requires that subscribers connect to FEED, read last published message and disconnect - not to wait 5 min for publisher to publish fresh message.
I use:
IBM WSMQ 7 for Linux
wmq.jmsra.rar adapter for IBM WSMQ 7 deployed to JBoss 5.1.0.GA
Connection Factory definition:
Code: |
<tx-connection-factory>
<jndi-name>wmqCF</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">MY_JMS_CHL</config-property>
<config-property name="hostName" type="java.lang.String">xx.xx.xx.xx</config-property>
<config-property name="port" type="java.lang.String">1414</config-property>
<config-property name="queueManager" type="java.lang.String">MY_QM_TEST</config-property>
<config-property name="transportType" type="java.lang.String">CLIENT</config-property>
<config-property name="username" type="java.lang.String">myuser</config-property>
<config-property name="messageRetention" type="java.lang.Boolean">true</config-property>
<config-property name="providerVersion" type="java.lang.String">7</config-property>
<!-- define security domain -->
<security-domain-and-application>JmsXARealm</security-domain-and-application>
</tx-connection-factory>
|
Java code placed in EJB3 message driven bean:
Code: |
@Resource(mappedName="java:/wmqCF")
private ConnectionFactory wmqCF;
...
...
...
try {
Connection conn = wmqCF.createConnection();
conn.start();
Session jmsSession = conn.createSession(true,Session.AUTO_ACKNOWLEDGE);
Topic feedTopic = jmsSession.createTopic("FEED");
MessageProducer mp = jmsSession.createProducer(feedTopic);
mp.setDeliveryMode(DeliveryMode.PERSISTENT);
mp.setTimeToLive(0);
mp.send(jmsSession.createTextMessage("My new message-"+(new Date())));
log.info("SUCCESS!");
jmsSession.close();
conn.close();
} catch (JMSException e) {
log.error("FAILED!");
e.printStackTrace();
}
|
If it is possible can you pint me to some docs. I checked Websphere MQ - Using Java but seems Publish/Subscribe is described just in context of using native MQ Java API. |
|
Back to top |
|
 |
Vitor |
Posted: Wed Feb 23, 2011 7:37 am Post subject: Re: publish/subscribe - How to ensure persistent delivery |
|
|
 Grand High Poobah
Joined: 11 Nov 2005 Posts: 26093 Location: Texas, USA
|
igor.beslic wrote: |
My scenario requires that subscribers connect to FEED, read last published message and disconnect - not to wait 5 min for publisher to publish fresh message. |
You're describing a retained publication. Look it up.  _________________ Honesty is the best policy.
Insanity is the best defence. |
|
Back to top |
|
 |
igor.beslic |
Posted: Thu Feb 24, 2011 2:57 am Post subject: Problem solved |
|
|
Novice
Joined: 15 Oct 2009 Posts: 14 Location: Zagreb, Croatia
|
Vitor thanks!
I made changes according docs you pointed and I got my retained publications:
Code: |
MessageProducer mp = jmsSession.createProducer(feedTopic);
mp.setDeliveryMode(DeliveryMode.PERSISTENT);
mp.setTimeToLive(0);
Message txtMsg = jmsSession.createTextMessage("My new message-"+(new Date()));
txtMsg.setIntProperty(JMS_IBM_RETAIN, RETAIN_PUBLICATION);
mp.send(txtMsg);
log.info("SUCCESS!");
mp.close();
jmsSession.close();
conn.close(); |
Values for JMS_IBM_RETAIN and RETAIN_PUBLICATION I've grab from:
http://publib.boulder.ibm.com/infocenter/wmqv7/v7r0/index.jsp?topic=/com.ibm.mq.javadoc.doc/WMQJMSClasses/constant-values.html
I'll link this post to one of mine previous posts related to similar problem but never solved. Now I solved both
Thanks again! |
|
Back to top |
|
 |
gbaddeley |
Posted: Thu Feb 24, 2011 2:47 pm Post subject: |
|
|
 Jedi Knight
Joined: 25 Mar 2003 Posts: 2538 Location: Melbourne, Australia
|
Quote: |
Hi, plese help me to solve my Publish/Subscribe problem. I have publisher that publishes to topic named FEED every 5min.
There are random number of subscribers who occationaly connects to MQ and read latest message from topic.
My problem is that when subscriber connects there is nothing at topic. After while when publisher was triggered by timer and message is published, subscriber receives message. |
The default paradigm for pub/sub in MQ is that a subscriber will receive the *next* message which is published on the topic. If there are no active or persistent subscribers when a message is published, the message is discarded by MQ.
The "retained publication" feature allows subscribers to access the *most recently* published message on a topic. _________________ Glenn |
|
Back to top |
|
 |
|
|
 |
|
Page 1 of 1 |
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|
|
|