| |
Struts Tutorials:
Struts2 Tag CheckBoxList , Checkbox, Iterator, IF
Struts2 Tag Library Example
Struts2 Tiles Example
Struts2 Tiles I18N Example
Struts2 Questions
Struts Tiles I18N Example
Struts Eclipse MVC
Struts2 Tags
Struts2 Example and Tutorial
Struts MVC
Struts2 Validation
Hibernate Tutorials:
Hibernate Case Study
Class Hierarchy Persist Example
Using Hibernate Interceptor
Hibernate Questions with Answer
Hibernate Many-to-Many Mapping Example
Hibernate one-to-many Mapping Example
Hibernate and ORM tools
Spring Hibernate Example
Hibernate SessionFactory Example
Hibernate Mapping Class Hierarchy
Hibernate Questions
Hibernate SessionFactory Questions
Spring Hibernate Example:
Spring Hibernate Case Study
| Tags/Keywords : How-to-Tutorial - JMS-Topic-and-Publish-Subscribe - J2EE-Technology Example Author : Sameer Date (Year/Month/Date): 2009-02-03
JMS Topic and Publish Subscribe using Java | | |
|
There are many aspects of
messaging using JMS.
1. Message delivery system
and it can be synchronous
and asynchronous.
2. Messaging model, and it
can be queue (that is point
to point) and publish subscribe.
3. Durability - storing messages
in persistence in case of messaging
server fail over conditions.
For showing/demonstrating or
understanding all these aspects
of JMS I have used OpenJMS from
http://openjms.sourceforge.net/
As it is Open Source implementation
of JMS, I found this easy to use
for debugging purposes.
|
By using OpenJMS v0.7.7-alpha, I am dealing with implementation of JMS
specification of Java Message Service 1.1.
Basic steps of using either Topic or Queue are as follows:
1. set properties related to the JMS server/provider URL and
the initial context factory implementation class file.
1.1. java.naming.provider.url=tcp://localhost:3035
"tcp://localhost:3035" is for the OpenJMS JMS implementation
and can vary based on JMS server.
1.2. java.naming.factory.initial=org.exolab.jms.jndi.InitialContextFactory
Again this class file "org.exolab.jms.jndi.InitialContextFactory" is
dependent on the JMS server used.
2. Using JNDI initial context, look up for the
JMS Connection Factory.
Type cast any particular required connection
factory like QueueConnectionFactory in case
of JMS Queue implementation.
and TopicConnectionFactory in case of JMS
Topic implementation.
3. Using specific connection factory, a specific
QueueConnection or TopicConnection can be created.
4. Based on these connections like,
QuestionConnection or TopicConnection specific
Sessions line QueueSession or TopicSession are created,
respectively.
5. Again using JNDI context, proper queue or topic (as defined in JMS server
configuration) are to be looked up.
6. Using Session (QueueSession or TopicSession)
either a Sender (in case of queue)
or a Publisher (in case of topic) is created by
passing either queue or topic
as parameter to method createSender(Queue) or
createPublisher(Topic).
7. using Session (TopicSession or QueueSession),
create a specific type of Message (here I have
used TextMessage) and send this message to either
a queue or a topic by using either Sender or Publisher.
8. Closing connections (either TopicConnection or
QueueConnection) could be done in finally block.
Portion of Sample code based on the above mentioned steps:
For Queue Message sender
For Queue Message receiver, and this Receiver class implements
javax.jms.MessageListener. This class handles any incoming message
by the onMessage method handler.
Incase of two receivers are pointing or referring to a single queue
and on message arrival to this queue, who gets the message?
To my understanding, in this case, message delivery happens
automatically and no way it can be determined that which receiver
gets the message, after the message is delivered to one out of two
listeners, message gets deleted from the queue and other listener
won't get any message. So it is advisable to configure one only
receiver to any queue.
If you want to contradict this understanding of mine, please do so.
and add your suggestions or note by using Reply Box, after log in.
|
| Are you interested in solving a very interesting Technology Stack while Playing this Game 
|
|
| Home >>> J2EE Technology >>> JMS Topic and Publish Subscribe >>> How to Tutorial |
|
|
Visitor/User referred related external URL:
(Visible upon review and approved by this site Administrator)
|
|
|
|
|
<- requires login | Log in or Register | |
Copyright © 2008-2009, Interview-Questions-Tips-Forum, All Rights Reserved. | CONTACT PRIVACY POLICY DISCLAIMER |
 |
Terms of Use and Disclaimer :
This web site provides some of the information about various technologies, example
code, tips, tutorials etc. Like any printed materials, content of these pages may
become out of date over a period of time. Therefore all visitor/users of this web
site are requested/advised to refer to the originating parties/sources for the
latest changes and happenings for detailed information. This information is not
intended to be a substitute for the original reference provided by the originating
parties/sources.
By accessing and using this website in any ways, including, without
limitation, browsing the website pages, using any information, using any content and/or
downloading any materials, you agree to and are bound by the terms of use
described in this page and Usage Terms and Conditions.
If you do not agree to all of
the terms and conditions contained in the terms of use described in this
page and Usage Terms and Conditions, do not use this
website in any manner. If you are using the website on behalf of your
employer, you represent that you are authorized to accept these Terms of Use
on your employer's behalf.
All Trademarks are property of their respective owner. Appropriate measure is being
taken for providing accurate and up-to-date information but like any printed materials,
these blog(s)/contents may eventually be outdated one day, so if you are using any
of these information, please refer original content/documentation from respective sources.
And under no circumstances shall the Author of these contents and/or this web site
be liable for any loss, damage, expense incurred or suffered which is claimed to have
occurred because of usage of the contents of this web site.
If you have any questions/queries/feedback/suggestions then please write to this web
site owner at contact.
|  |
|
|
|
|
|