ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » IBM MQ Java / JMS » publish/subscribe - How to ensure persistent delivery

Post new topic  Reply to topic
 publish/subscribe - How to ensure persistent delivery « View previous topic :: View next topic » 
Author Message
igor.beslic
PostPosted: Wed Feb 23, 2011 7:20 am    Post subject: publish/subscribe - How to ensure persistent delivery Reply with quote

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
View user's profile Send private message Visit poster's website
Vitor
PostPosted: Wed Feb 23, 2011 7:37 am    Post subject: Re: publish/subscribe - How to ensure persistent delivery Reply with quote

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
View user's profile Send private message
igor.beslic
PostPosted: Thu Feb 24, 2011 2:57 am    Post subject: Problem solved Reply with quote

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
View user's profile Send private message Visit poster's website
gbaddeley
PostPosted: Thu Feb 24, 2011 2:47 pm    Post subject: Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » IBM MQ Java / JMS » publish/subscribe - How to ensure persistent delivery
Jump to:  



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
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.