<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>JavaBeat &#187; JMS</title>
	<atom:link href="http://www.javabeat.net/category/java-j2ee/jms/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.javabeat.net</link>
	<description>Java Technology News</description>
	<lastBuildDate>Fri, 24 May 2013 01:32:07 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.5.1</generator>
		<item>
		<title>How to Configure Java Messaging Service (JMS) in GlassFish 3 Application Server?</title>
		<link>http://www.javabeat.net/2010/09/how-to-configure-java-messaging-service-jms-in-glassfish-3-application-server/</link>
		<comments>http://www.javabeat.net/2010/09/how-to-configure-java-messaging-service-jms-in-glassfish-3-application-server/#comments</comments>
		<pubDate>Fri, 10 Sep 2010 00:46:07 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[JMS]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=1767</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Java EE 6.0 with GlassFish 3 Application Server Buy JMS Books from Amazon Book Store This book begins with the installation of Glassfish 3 and deploying Java applications. It also explains how to develop, configure, package, and deploy servlets. Additionally, we will learn the processing of HTML forms. As we move on, we will develop [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><a id="dd_start"></a><p><H1><CENTER>Java EE 6.0 with GlassFish 3 Application Server </CENTER></H1></p>
<ul>
<li>Buy <a href="http://astore.amazon.com/javabeat-20?_encoding=UTF8&#038;node=26" target="_blank">JMS Books</a> from <a href="http://astore.amazon.com/javabeat-20" target="_blank">Amazon Book Store</a></li>
</ul>
<p><P>This book begins with the installation of Glassfish 3 and deploying Java applications. It<br />
also explains how to develop, configure, package, and deploy servlets. Additionally, we<br />
will learn the processing of HTML forms. As we move on, we will develop Java Server<br />
Pages and get to know about implicit JSP objects. We will also get to know about all the<br />
JSTL (JSP Standard Tag Library) tag libraries. This book gives us a better understanding<br />
on how to manage data from a database through the Java Database Connectivity (JDBC)<br />
API and the Java Persistence API (JPA). We will also learn more about the newly<br />
introduced features of <b>JPA 2.0</b> and develop <b>JSF</b> 2.0 applications to learn how to<br />
customize them. We will then set up Glassfish for the Java Messaging (JMS) API and<br />
understand the working of message queues and message topics. Later, we will use the<br />
Context and Dependency Injection (CDI) API to integrate application layers and study<br />
the SOAP-based web service development using the JAX-WS specification. Finally, we<br />
will learn more about the RESTful web service development using the JAX-RS<br />
specification.</P><br />
<P>The book covers the various Java EE 6 conventions and annotations that can simplify<br />
enterprise Java application development. The latest versions of the Servlet, <b>JSF</b>, JPA,<br />
EJB, and JAX-WS specifications are covered, as well as new additions to the<br />
specification, such as JAX-RS and CDI.</P><br />
<H1>What This Book Covers</H1><br />
<P>Chapter 1, Getting Started with GlassFish will discuss how to download and install<br />
GlassFish. We will look at several methods of deploying a Java EE application through<br />
the GlassFish web console, through the asadmin command, and by copying the file to<br />
the autodeploy directory. We will cover basic GlassFish administration tasks such as<br />
setting up domains and setting up database connectivity by adding connection pools and<br />
data sources.</P><br />
<P>Chapter 2, Servlet Development and Deployment will cover how to develop, configure,<br />
package, and deploy servlets. We will also cover how to process HTML form<br />
information by accessing the HTTP request object. Additionally, forwarding HTTP<br />
requests from one servlet to another will be explained, as well as redirecting the HTTP<br />
response to a different server. We will discuss how to persist objects in memory across<br />
requests by attaching them to the servlet context and the HTTP session. Finally, we will<br />
look at all the major new features of Servlet 3.0, including configuring web applications<br />
via annotations, pluggability through web-fragment. xml , programmatic servlet<br />
configuration, and asynchronous processing.</P><br />
<P>Chapter 3, JavaServer Pages will talk about how to develop and deploy simple JSPs. We<br />
will cover how to access implicit objects such as request, session, and so on, from<br />
JSPs. Additionally, we will look at how to set and get the values of JavaBean properties<br />
via the &lt;jsp:useBean&gt; tag. In addition to that, we will find out how to include a JSP<br />
into another JSP at runtime via the &lt;jsp:include&gt; tag, and at compilation time via the<br />
JSP include directive. We will discuss how to write custom JSP tags by extending<br />
javax.servlet.jsp.tagext.SimpleTagSupport or by writing TAG files. We<br />
will also discuss how to access JavaBeans and their properties via the Unified Expression<br />
Language. Finally, we will cover the JSP XML syntax that allows us to develop XMLcompliant<br />
JavaServer Pages.</P><br />
<P>Chapter 4, JSP Standard Tag Library will cover all JSP Standard Tag Library tags,<br />
including the core, formatting, SQL, and XML tags. Additionally, JSTL functions will be<br />
explained. Examples illustrating the most common JSTL tags and functions will be<br />
provided; additional JSTL tags and functions will be mentioned and described.</P><br />
<P>Chapter 5, Database Connectivity will talk about how to access data in a database via<br />
both the Java Database Connectivity (JDBC) and through the <a href="http://www.javabeat.net/articles/5-introduction-to-java-persistence-apijpa-1.html">Java Persistence API (JPA)</a>.<br />
Defining both unidirectional and bidirectional one-to-one, one-to-many, and many-tomany<br />
relationships between <b>JPA</b> entities will be covered. Additionally, we will discuss<br />
how to use JPA composite primary keys by developing custom primary key classes. We<br />
will also discuss how to retrieve entities from a database by using the Java Persistence<br />
Query Language (JPQL). We will look at how to build queries programmatically through<br />
the JPA 2.0 Criteria API and automating data validation through JPA 2.0&#8242;s Bean<br />
Validation support</P><br />
<P>Chapter 6, <b><a href=="http://www.javabeat.net/articles/11-introduction-to-java-server-faces-1.html">JavaServer Faces</a></b> will cover how to develop web-based applications using<br />
JavaServer Faces—the standard component framework for the Java EE 5 platform. We<br />
will talk about how to write a simple application by creating JSPs containing <b>JSF</b> tags<br />
and managed beans. We will discuss how to validate user input by using <b>JSF</b>&#8216;s standard<br />
validators and by creating our own custom validators, or by writing validator methods.<br />
Additionally, we will look at how to customize standard <b>JSF</b> error messages; both the<br />
message text and the message style (font, color, and so on). Finally, we will discuss how<br />
to write applications by integrating <b>JSF</b> and the Java Persistence API (JPA).</P><br />
<P>Chapter 7, <b><a href="http://astore.amazon.com/javabeat-20?_encoding=UTF8&#038;node=26">Java Messaging Service</a></b> will talk about how to set up JMS connection<br />
factories, JMS message queues, and JMS message topics in <b>GlashFish</b> using the<br />
<b>GlashFish</b> web console. We will cover how to send and receive messages to and from a<br />
message queue. We will discuss how to send and receive messages to and from a JMS<br />
message topic. We will find out how to browse messages in a message queue without<br />
removing the messages from the queue. Finally, we will look at how to set up and interact<br />
with durable subscriptions to JMS topics.</P><br />
<P>Chapter 8, Security will talk about how to use <b>GlashFish</b>&#8216;s default realms to authenticate<br />
our web applications. We will cover the file realm, which stores user information in a flat file, and the certificate realm, which requires client-side certificates for user<br />
authentication. Additionally, we will discuss how to create additional realms that behave<br />
just like the default realms, by using the realm classes included with <b>GlashFish</b>.</P><br />
<P>Chapter 9, Enterprise JavaBeans will cover how to implement business logic via stateless<br />
and stateful session beans. Additionally, we will explain the concept of containermanaged<br />
transactions and bean-managed transactions. We will look at the life cycles for<br />
the different types of Enterprise Java Beans. We will talk about how to have EJB<br />
methods invoked periodically by the EJB container, by taking advantage of the EJB timer<br />
service. Finally, we will explain how to make sure that EJB methods are only invoked by<br />
authorized users.</P><br />
<P>Chapter 10, Contexts and Dependency Injection will talk about how <b>JSF</b> pages can access<br />
CDI named beans as if they were <b>JSF</b> managed beans. We will explain how CDI makes it<br />
easy to inject dependencies into our code. We will discuss how we can use qualifiers to<br />
determine what specigic implementation of dependency to inject into our code. Finally,<br />
we will look at all the scopes that a CDI bean can be placed into.</P><br />
<P>Chapter 11, Web Services with JAX-WS will cover how to develop web services and<br />
web service clients via the JAX-WS API. We will discuss how to send attachments to a<br />
web service. We will explain how to expose an EJB&#8217;s methods as web services. Finally,<br />
we will look at how to secure web services so that they are not accessible to unauthorized<br />
clients.</P><br />
<P>Chapter 12, RESTful Web Services with Jersey and JAX-RS will discuss how to easily<br />
develop RESTful web services using JAX-RS—a new addition to the Java EE<br />
specification. We will explain how to automatically convert data between Java and XML<br />
by taking advantage of the Java API for XML Binding (JAXB). Finally, we will cover<br />
how to pass parameters to our RESTful web services via the @PathParam and<br />
@QueryParam annotations.</P><br />
<H1><CENTER>Java Messaging Service</CENTER></H1><br />
<P>The <B>Java Messaging API (JMS)</B> provides a mechanism for Java EE applications to<br />
send messages to each other. JMS applications do not communicate directly, instead<br />
message producers send messages to a destination and message consumers receive<br />
the message from the destination.</P><br />
<P>The message destination is a message queue when the point-to-point (PTP)<br />
messaging domain is used, or a message topic when the publish/subscribe<br />
(pub/sub) messaging domain is used.</P><br />
<P>In this chapter, we will cover the following topics:</P><br />
<UL><br />
<LI>Setting up <b>GlashFish</b> for JMS</LI><br />
<LI>Working with message queues</LI><br />
<LI>Working with message topics</LI><br />
</UL><br />
<H1>Setting up GlassFish for JMS</H1><br />
<P>Before we start writing code to take advantage of the JMS API, we need to configure<br />
some <b>GlashFish</b> resources. Specifically, we need to set up a <B>JMS connection factory</B>,<br />
a <B>message queue</B>, and a <B>message topic</B>.</P><br />
<H2>Setting up a JMS connection factory</H2><br />
<P>The easiest way to set up a JMS connection factory is via <b>GlashFish</b>&#8216;s web console.<br />
Recall from Chapter 1 that the web console can be accessed by starting our domain,<br />
by entering the following command in the command line:</P><br />
<P><PRE><CODE><B><br />
asadmin start-domain domain1<br />
</B></CODE></PRE></P><br />
<P>Then point the browser to http://localhost:4848 and log in:</P><br />
<P><CENTER><IMG SRC="images/2010/09/java-messaging-service/1.jpg"/></CENTER></P><br />
<P>A connection factory can be added by expanding the <B>Resources</B> node in the tree<br />
at the left-hand side of the web console, expanding the <B>JMS Resources</B> node and<br />
clicking on the <B>Connection Factories</B> node, then clicking on the <B>New&#8230;</B> button in<br />
the main area of the web console.</P><br />
<P><CENTER><IMG SRC="images/2010/09/java-messaging-service/2.jpg"/></CENTER></P><br />
<P>For our purposes, we can take most of the defaults. The only thing we need to do is<br />
enter a <B>Pool Name</B> and pick a <B>Resource Type</B> for our connection factory.</P><br />
<P><PRE><CODE><br />
	It is always a good idea to use a <B>Pool Name</B> starting with &#8220;jms/&#8221; when<br />
	picking a name for JMS resources. This way JMS resources can be<br />
	easily identified when browsing a JNDI tree.<br />
</CODE></PRE></P><br />
<P>In the text field labeled <B>Pool Name</B>, enter <B>jms/GlassFishBookConnectionFactory</B>.<br />
Our code examples later in this chapter will use this JNDI name to obtain a reference<br />
to this connection factory.</P><br />
<P>The <B>Resource Type</B> drop-down menu has three options:</P><br />
<UL><br />
<LI><B>javax.jms.TopicConnectionFactory</B> &#8211; used to create a connection factory that<br />
creates JMS topics for JMS clients using the pub/sub messaging domain</LI><br />
<LI><B>javax.jms.QueueConnectionFactory</B> &#8211; used to create a connection factory<br />
that creates JMS queues for JMS clients using the PTP messaging domain</LI><br />
<LI><B>javax.jms.ConnectionFactory</B> &#8211; used to create a connection factory that<br />
creates either JMS topics or JMS queues</LI><br />
</UL><br />
<P>For our example, we will select <B>javax.jms.ConnectionFactory</B>. This way we can use<br />
the same connection factory for all our examples, those using the PTP messaging<br />
domain and those using the pub/sub messaging domain.</P><br />
<P>After entering the <B>Pool Name</B> for our connection factory, selecting a connection<br />
factory type, and optionally entering a description for our connection factory,<br />
we must click on the <B>OK</B> button for the changes to take effect.</P><br />
<P><CENTER><IMG SRC="images/2010/09/java-messaging-service/3.jpg"/></CENTER></P><br />
<P>We should then see our newly created connection factory listed in the main area of<br />
the <b>GlashFish</b> web console.</P><br />
<H2>Setting up a JMS message queue</H2><br />
<P>A JMS message queue can be added by expanding the <B>Resources</B> node in the tree<br />
at the left-hand side of the web console, expanding the <B>JMS Resources</B> node and<br />
clicking on the <B>Destination Resources</B> node, then clicking on the <B>New&#8230;</B> button in<br />
the main area of the web console.</P><br />
<P><CENTER><IMG SRC="images/2010/09/java-messaging-service/4.jpg"/></CENTER></P><br />
<P>In our example, the JNDI name of the message queue is <B>jms/GlassFishBookQueue</B>.<br />
The resource type for message queues must be <B>javax.jms.Queue</B>. Additionally,<br />
a <B>Physical Destination Name</B> must be entered. In this example, we use<br />
<B>GlassFishBookQueue</B> as the value for this field.</P><br />
<P>After clicking on the <B>New&#8230;</B> button, entering the appropriate information for<br />
our message queue, and clicking on the <B>OK</B> button, we should see the newly<br />
created queue:</P><br />
<P><CENTER><IMG SRC="images/2010/09/java-messaging-service/5.jpg"/></CENTER></P><br />
<H2>Setting up a JMS message topic</H2><br />
<P>Setting up a JMS message topic in <b>GlashFish</b> is very similar to setting up a<br />
message queue.</P><br />
<P>In the <b>GlashFish</b> web console, expand the <B>Resources</B> node in the tree at the left hand<br />
side, then expand the <B>JMS Resouces</B> node and click on the <B>Destination</B> Resources<br />
node, then click on the <B>New&#8230;</B> button in the main area of the web console.</P><br />
<P><CENTER><IMG SRC="images/2010/09/java-messaging-service/6.jpg"/></CENTER></P><br />
<P>Our examples will use a <B>JNDI Name</B> of <B>jms/GlassFishBookTopic</B>. As this is a<br />
message topic, <B>Resource Type</B> must be <B>javax.jms.Topic</B>. The <B>Description</B> field is<br />
optional. The <B>Physical Destination Name</B> property is required. For our example, we<br />
will use <B>GlassFishBookTopic</B> as the value for this property.</P><br />
<P>After clicking on the <B>OK</B> button, we can see our newly created message topic:</P><br />
<P><CENTER><IMG SRC="images/2010/09/java-messaging-service/7.jpg"/></CENTER></P><br />
<P>Now that we have set up a connection factory, a message queue, and a message<br />
topic, we are ready to start writing code using the JMS API.</P></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<h2>JMS Articles</h2>
<ul>
<li><a href="http://www.javabeat.net/articles/90-integrating-spring-with-jms-1.html">Integrating Spring with JMS</a> by <a href="http://www.javabeat.net/authors/Christy/">Christy</a></li>
<li><a href="http://www.javabeat.net/articles/jms/1/">JMS Articles</a></li>
<li><a href="http://www.javabeat.net/articles/170-spring-jms-api-and-weblogic-jms-integration-1.html">Spring JMS API and Weblogic JMS Integration</a> by <a href="http://www.javabeat.net/authors/Sangeetha/">Sangeetha</a></li>
<li><a href=""></a></li>
</ul>
<div class='dd_outer'><div class='dd_inner'><div id='dd_ajax_float'><div class='dd_button_v'><script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like href="http%3A%2F%2Fwww.javabeat.net%2Fcategory%2Fjava-j2ee%2Fjms%2Ffeed%2F" send="false" show_faces="false"  layout="box_count" width="50"  ></fb:like></div><div style='clear:left'></div><div class='dd_button_v'><script type='text/javascript' src='https://apis.google.com/js/plusone.js'></script><g:plusone size='tall' href='http://www.javabeat.net/category/java-j2ee/jms/feed/'></g:plusone></div><div style='clear:left'></div><div class='dd_button_v'><a href="http://twitter.com/share" class="twitter-share-button" data-url="http://www.javabeat.net/category/java-j2ee/jms/feed/" data-count="vertical" data-text="JMS" data-via="javabeat" ></a><script type="text/javascript" src="http://platform.twitter.com/widgets.js"></script></div><div style='clear:left'></div><div class='dd_button_extra_v'><script type="text/javascript">jQuery(document).load(function(){ stLight.options({publisher:'bab47279-62c9-46af-addc-79fd1fe8fee0'}); });</script><div class="st_email_custom"><span id='dd_email_text'>email</span></div></div><div style='clear:left'></div><div class='dd_button_extra_v'><div id='dd_print_button'><span id='dd_print_text'><a href='javascript:window:print()'>print</a></span></div></div><div style='clear:left'></div></div></div></div><script type="text/javascript">var dd_offset_from_content = 44; var dd_top_offset_from_content = 0;</script><script type="text/javascript" src="http://www.javabeat.net/wp-content/plugins/digg-digg//js/diggdigg-floating-bar.js?ver=5.3.0"></script><div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/09/how-to-configure-java-messaging-service-jms-in-glassfish-3-application-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spring JMS API and Weblogic JMS Integration</title>
		<link>http://www.javabeat.net/2010/01/spring-jms-api-and-weblogic-jms-integration/</link>
		<comments>http://www.javabeat.net/2010/01/spring-jms-api-and-weblogic-jms-integration/#comments</comments>
		<pubDate>Sat, 30 Jan 2010 16:00:32 +0000</pubDate>
		<dc:creator>Sangeetha G</dc:creator>
				<category><![CDATA[JMS]]></category>
		<category><![CDATA[WebLogic]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=422</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>1)Introduction JMS API is Java Message Service API that allows components to communicate asynchronously. JMS enables two components to send and receive message without knowing each other. Spring provides support for JMS programming. Spring is a widely used framework to develop enterprise application. It is bundled with many APIs like AOP, IOC Spring MVC,Spring JMS [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>1)Introduction</h2>
<p>JMS API is Java Message Service API that allows components to communicate asynchronously. JMS enables two components to send and receive message without knowing each other. Spring provides support for JMS programming. Spring is a widely used framework to develop enterprise application. It is bundled with many APIs like AOP, IOC Spring MVC,Spring JMS etc. This article can be used by beginners to write simple programs using Spring API to integrate with Weblogic JMS .Here weblogic is used because it supports many features to provide communication between sender and receiver.It acts as a middleware for JMS application.</p>
<h2>2)Why do we need JMS?</h2>
<p>Enterprise Application is a software to solve enterprise problem. It has many business requirements to solve the problem. To have better modularity, the requirements will be developed as different software components and programmer will integrate these components to complete entire enterprise application. The programmer needs to consider many factors while integrating the components. The following scenarios will give the clear picture about the some factors with respect to component integration</p>
<h3>Scenario #1:</h3>
<p>Assume that there two components called OrderProcessing and CreditCardVerification. The OrderProcessing component needs to communicate to the CreditCardVerifcation but it is not having the interface of the CreditCardVerification.<br />
<strong>How it is going to communicate?</strong></p>
<h3>Scenario #2:</h3>
<p>Assume that there are two Components called TransactionBean and HistoryBean(to record each transaction). For each transaction, the TransactionBean is going to send information to the HistoryBean and it doesn?t want to wait till the HistoryBean completes the work.<br />
<strong>How to develop the TransactionBean to have asynchronous communication to HistoryBean?</strong></p>
<p>The solution is provided by JMS.</p>
<h2>3)Introduction to JMS API</h2>
<p>JMS API is Java Message Service API that allows components to communicate asynchronously. JMS enables two components to send and receive message without knowing each other. Messaging provides communication between software components or applications. A messaging component can send messages to, and receive messages from, any other component. This is achieved with help of JMS Provider. The JMSProvider is a MOM (Message Oriented Middleware); sitting between sender and receiver components for asynchronous communication i.e. if a sender sends a message, the same will be stored inside MOM. The MOM then forwards the message to receiver.</p>
<p>To achieve the communication, following components will be configured inside the MOM.</p>
<ul>
<li>Connectionfactoires:Provides the communication to client programs</li>
<li>Destination: Stores the messages.There are two types.
<ol>
<li>Queue:Message will be delivered to Only one receiver</li>
<li>Topic-Message will be delivered to more than one receiver</li>
</ol>
</li>
</ul>
<h2>4) Weblogic JMS Provider</h2>
<p>One of the widely used providers is Web logic. It is widely used because of following features.</p>
<ul>
<li>Provides messaging API.</li>
<li>Supports clustering.</li>
<li>Platform independent.</li>
<li>Resources can be configured using Web Logic Administration Console.</li>
<li>Supports XML message.</li>
<li>Supports multicasting delivery.</li>
</ul>
<h2>5) Spring JMS API</h2>
<p>Spring supports JMS framework that simplifies the complexity of the JMS implementation. The package org.springframework.jms.core provides the API for JMS core functionality. A JMS Programmer can write JMS application using Spring IOC and Spring JMS API easily. Using Spring JMS and Dependency injection, the JMS configuration details are migrated from Java code to xml file</p>
<p>The Spring JMS API supports a template mechanism to hide the details of Java APIs. Programmers can use JDBC Template and JNDI Template classes to use Web logic JMS resource. Spring supports the JMS Template, so developers don&#8217;t have to write the complex code for JMS implementation. Templates are helper classes used to reduce the complexity of JMS and handle the creation and release of JMS resources like connection factories, destinations, and sender/receiver objects.</p>
<p>We attempt to provide you, in this article, a step by step solution for Integrating Spring, JMS and Web logic. It is addressed to the audience who are aware of the basics of Spring IOC, Web logic and JMS. The article also provides the detailed information about the JMS implementation using Spring JMS. This article will help the programmer to write JMS application using Spring. Programmers can use the configuration file as basic setup for JMS application in addition they can develop application as well.</p>
<h2>6) Steps to integrate Spring JMS and Weblogic</h2>
<h3>Step 1:</h3>
<ul>
<li>Configure the following JMS resource inside the web logic server.</li>
<li>ConnectionFactory- jms/connectionFactory and<br />
Queue Destination- jms/testQueue</li>
</ul>
<h3>Step 2:</h3>
<p>Create dynamic web application in the Web logic workshop</p>
<h3>Step 3:</h3>
<p>Import Spring.jar,<br />
Commons-logging.jar and<br />
log4j-1.2.15.jar</p>
<h3>Step 4:</h3>
<p>Create the InvoiceQueueSender class in the package jms. The class InvoiceQueueSender is used to send messages. The JMSTemplate is injected into InvoiceQueueSender using IOC container. JMS Template is used for sending and receiving messages using Message Creator. The Message Creator is a call back interface which has createMessage to create messages. JMS Template has send method which takes the parameter, Queue name and message creator.</p>
<p><strong>Sample Code</strong></p>
<pre class="brush: java; title: ; notranslate">package jms;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
public class InvoiceQueueSender {
	private JmsTemplate jmsTemplate;
	public void setJmsTemplate(JmsTemplate jmsTemplate) {
		this.jmsTemplate = jmsTemplate;
	}

	public void sendMesage() {
		MessageCreator messageCreator=new MessageCreator() {
		public Message createMessage(Session session) throws
		JMSException {
		return session.createTextMessage(&quot;I am 
                               sending Invoice message&quot;);}
		};

		jmsTemplate.send(&quot;jms/testQueue&quot;, messageCreator);
	}
}</pre>
<h3>Step 5:</h3>
<p>Create the InvoiceMDB class in the package jms. It is a MessageDrivenBean. The InvoiceMDB is a MDB and it implements MessageListener interface. The onMessage will be executed automatically whenever message is delivered to the Queue or Topic.</p>
<p><strong>Sample Code</strong></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<pre class="brush: java; title: ; notranslate">package jms;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

public class InvoiceMDB implements MessageListener {
	public void onMessage(Message message) {
	 try {
	   System.out.println(((TextMessage) message).getText());
	   System.out.println(&quot;Hello&quot;);
	 } catch (JMSException ex) {
	   throw new RuntimeException(ex);
	 }
	}
}</pre>
<h3>Step 6:</h3>
<p>The following details will be configured inside spring configuration file. Here the file name is applicationContext.xml.</p>
<h5>JNDITemplate</h5>
<p>It helps us to perform JNDI operations. It has methods to do lookup and binding operation. The web logic context details are configured using this interface.</p>
<pre class="brush: java; title: ; notranslate">	
&lt;bean id=&quot;jndiTemplate&quot; class=&quot;org.springframework
       .jndi.JndiTemplate&quot;&gt;
&lt;property name=&quot;environment&quot;&gt;
 &lt;props&gt;
   &lt;prop key=&quot;java.naming.factory.initial&quot;&gt;
           weblogic.jndi.WLInitialContextFactory&lt;/prop&gt;
   &lt;prop key=&quot;java.naming.provider.url&quot;&gt;t3://localhost:7001&lt;/prop&gt;
 &lt;/props&gt;
&lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>JndiObjectFactoryBean</h5>
<p>It is used to look up the JNDI object on startup and cache it. This interface is used to configure connection factory.</p>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;queueConnectionFactory&quot; 
      class=&quot;org.springframework.jndi.JndiObjectFactoryBean&quot;&gt;
&lt;property name=&quot;jndiTemplate&quot;&gt;
 &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;jndiName&quot;&gt;
 &lt;value&gt;jms/connectionFactory&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>DestinationResolver</h5>
<p>It is used by JmsTemplate to resolve destination names</p>
<pre class="brush: java; title: ; notranslate">
&lt;bean id=&quot;jmsDestinationResolver&quot; 
       class=&quot;org.springframework.jms.support.destination
       .JndiDestinationResolver&quot;&gt;
&lt;property name=&quot;jndiTemplate&quot;&gt;
 &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;cache&quot;&gt;
 &lt;value&gt;true&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>JMSTemplate</h5>
<p>It is used to send messages. This requires information about connection factory and destination resolver while configuring.</p>
<pre class="brush: java; title: ; notranslate">	
&lt;bean id=&quot;invoiceQueueTemplate&quot; class=&quot;org.springframework.jms
        .core.JmsTemplate&quot;&gt;
&lt;property name=&quot;connectionFactory&quot;&gt;
 &lt;ref bean=&quot;queueConnectionFactory&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;destinationResolver&quot;&gt;
 &lt;ref bean=&quot;jmsDestinationResolver&quot; /&gt;
&lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>Queue</h5>
<p>The destination details will be configured using JndiObjectFactoryBean</p>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;invoiceQueue&quot; class=&quot;org.springframework
            .jndi.JndiObjectFactoryBean&quot;&gt;
 &lt;property name=&quot;jndiTemplate&quot;&gt;
   &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
 &lt;/property&gt;
 &lt;property name=&quot;jndiName&quot;&gt;
   &lt;value&gt;jms/testQueue&lt;/value&gt;
 &lt;/property&gt;
&lt;/bean&gt;</pre>
<h5>MDB(MessageDrivenBean)</h5>
<p>The details about Message driven will configured as a normal bean</p>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;invoiceListener&quot; class=&quot;jms.InvoiceMDB&quot; /&gt;</pre>
<h5>Listener Configuarion</h5>
<p>This class is used to configure the normal bean as message driven bean. While configuring, the destination details will be supplied so that the framework can have the relationship between MDB and destination</p>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;Invoicelistener&quot; class=&quot;org.springframework.jms
           .listener.DefaultMessageListenerContainer&quot;&gt;
    &lt;property name=&quot;concurrentConsumers&quot; value=&quot;5&quot; /&gt;
    &lt;property name=&quot;connectionFactory&quot; ref=&quot;queueConnectionFactory&quot; /&gt;
    &lt;property name=&quot;destination&quot; ref=&quot;invoiceQueue&quot; /&gt;
    &lt;property name=&quot;messageListener&quot; ref=&quot;invoiceListener&quot; /&gt;
&lt;/bean&gt;</pre>
<h5>SenderBean</h5>
<pre class="brush: java; title: ; notranslate">&lt;bean id=&quot;jmsInvoiceSender&quot; class=&quot;jms.InvoiceQueueSender&quot;&gt;
&lt;property name=&quot;jmsTemplate&quot;&gt;
&lt;ref bean=&quot;invoiceQueueTemplate&quot; /&gt;</pre>
<h5>The final contents will be</h5>
<pre class="brush: java; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;!DOCTYPE beans PUBLIC &quot;-//SPRING//DTD BEAN//EN&quot;
&quot;http://www.springframework.org/dtd/spring-beans.dtd&quot;&gt;
&lt;beans&gt;

&lt;bean id=&quot;invoiceListener&quot; class=&quot;jms.InvoiceMDB&quot; /&gt;

&lt;bean id=&quot;jndiTemplate&quot; class=&quot;org.springframework.jndi.JndiTemplate&quot;&gt;
&lt;property name=&quot;environment&quot;&gt;
 &lt;props&gt;
   &lt;prop key=&quot;java.naming.factory.initial&quot;&gt;weblogic.jndi
                   .WLInitialContextFactory&lt;/prop&gt;
   &lt;prop key=&quot;java.naming.provider.url&quot;&gt;t3://localhost:7001&lt;/prop&gt;
 &lt;/props&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;queueConnectionFactory&quot; class=&quot;org.springframework.
             jndi.JndiObjectFactoryBean&quot;&gt;
&lt;property name=&quot;jndiTemplate&quot;&gt;
 &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;jndiName&quot;&gt;
 &lt;value&gt;jms/connectionFactory&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;jmsDestinationResolver&quot; class=&quot;org.springframework
            .jms.support.destination.JndiDestinationResolver&quot;&gt;
&lt;property name=&quot;jndiTemplate&quot;&gt;
 &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;cache&quot;&gt;
 &lt;value&gt;true&lt;/value&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;invoiceQueueTemplate&quot; class=&quot;org.springframework
             .jms.core.JmsTemplate&quot;&gt;
&lt;property name=&quot;connectionFactory&quot;&gt;
 &lt;ref bean=&quot;queueConnectionFactory&quot; /&gt;
&lt;/property&gt;
&lt;property name=&quot;destinationResolver&quot;&gt;
 &lt;ref bean=&quot;jmsDestinationResolver&quot; /&gt;
&lt;/property&gt;
&lt;/bean&gt;

&lt;bean id=&quot;jmsInvoiceSender&quot; class=&quot;jms.InvoiceQueueSender&quot;&gt;
&lt;property name=&quot;jmsTemplate&quot;&gt;
 &lt;ref bean=&quot;invoiceQueueTemplate&quot; /&gt;
&lt;/property&gt;

&lt;/bean&gt;

&lt;bean id=&quot;invoiceQueue&quot; class=&quot;org.springframework.jndi
        .JndiObjectFactoryBean&quot;&gt;
 &lt;property name=&quot;jndiTemplate&quot;&gt;
   &lt;ref bean=&quot;jndiTemplate&quot; /&gt;
 &lt;/property&gt;
 &lt;property name=&quot;jndiName&quot;&gt;
   &lt;value&gt;jms/testQueue&lt;/value&gt;
 &lt;/property&gt;
&lt;/bean&gt;
&lt;bean id=&quot;Invoicelistener&quot; class=&quot;org.springframework.jms
               .listener.DefaultMessageListenerContainer&quot;&gt;
    &lt;property name=&quot;concurrentConsumers&quot; value=&quot;5&quot; /&gt;
    &lt;property name=&quot;connectionFactory&quot; ref=&quot;queueConnectionFactory&quot; /&gt;
    &lt;property name=&quot;destination&quot; ref=&quot;invoiceQueue&quot; /&gt;
    &lt;property name=&quot;messageListener&quot; ref=&quot;invoiceListener&quot; /&gt;
  &lt;/bean&gt;
&lt;/beans&gt;</pre>
<h3>Step 7:</h3>
<p>Create Servlet to send message</p>
<pre class="brush: java; title: ; notranslate">package jms;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class InvoiceSenderServlet extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
   protected void service(HttpServletRequest request,
          HttpServletResponse response) throws ServletException, IOException {
	     WebApplicationContext ctx = WebApplicationContextUtils
		.getRequiredWebApplicationContext(this.getServletContext());

		InvoiceQueueSender sender = (InvoiceQueueSender) ctx
				.getBean(&quot;jmsInvoiceSender&quot;);
		sender.sendMesage();
	}
}</pre>
<h3>Step 8:</h3>
<p>Configure the spring configuration details in the web.xml</p>
<pre class="brush: java; title: ; notranslate">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;
&lt;web-app id=&quot;WebApp_ID&quot; version=&quot;2.4&quot; 
  xmlns=&quot;http://java.sun.com/xml/ns/j2ee&quot; 
  xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot; 
  xsi:schemaLocation=&quot;http://java.sun.com/xml/ns/j2ee 

http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd&quot;&gt;

	&lt;display-name&gt;
	SpringJMS&lt;/display-name&gt;
	&lt;servlet&gt;
		&lt;description&gt;
		&lt;/description&gt;
		&lt;display-name&gt;
		InvoiceSenderServlet&lt;/display-name&gt;
		&lt;servlet-name&gt;InvoiceSenderServlet&lt;/servlet-name&gt;
		&lt;servlet-class&gt;
		jms.InvoiceSenderServlet&lt;/servlet-class&gt;
	&lt;/servlet&gt;
	&lt;servlet-mapping&gt;
		&lt;servlet-name&gt;InvoiceSenderServlet&lt;/servlet-name&gt;
		&lt;url-pattern&gt;/InvoiceSenderServlet&lt;/url-pattern&gt;
	&lt;/servlet-mapping&gt;
	&lt;welcome-file-list&gt;
		&lt;welcome-file&gt;index.html&lt;/welcome-file&gt;
		&lt;/welcome-file-list&gt;

	&lt;listener&gt;
	&lt;listener-class&gt;org.springframework.web.context.
                  ContextLoaderListener&lt;/listener-class&gt;
	&lt;/listener&gt;
&lt;/web-app&gt;</pre>
<h3>Step 9:</h3>
<p>Run the servlet and check the console.</p>
<h3>Conclusion</h3>
<p>Spring JMS API is used to achieve asynchronous communication. The bean configuration file plays very important role because all the resources required for JMS is configured inside xml file.The MOM is acting as a mediator between sender and receiver. Weblogic MOM supports many features for JMS.</p>
<p>Once the programmers start using Spring in JMS applications, they will appreciate its simplicity for asynchronous messaging. The Spring JMS framework provides a variety of Java classes to implement JMS application.<br />
Hope this article will be useful for beginners to write JMS application using Spring and Web logic.</p>
<h3>Acknowledgements</h3>
<p>The Author wants to express her sincere thanks to a group of personnel from Infosys Technology who have been instrumental in bringing this article to fruition.</p>
<p>Sangeetha S was instrumental in conducting the technical review for this article.The author sincerely thanks Raghavendran N, Rajagopalan P, Satheesha BN and SV Subrahmanya for the<br />
continued encouragement and support.</p>
<h3>About the Author</h3>
<p>G. Sangeetha is a Senior Technical Evangelist in Infosys Technologies, Ltd., Mysore D.C. She is a post graduate in Computer Applications from the Bharathidasan University. She has over 8 years of teaching experience in the field of Computer Technology in varied organizations. She specializes in Java, J2EE and related technologies.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2010/01/spring-jms-api-and-weblogic-jms-integration/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>JMS Interview Questions</title>
		<link>http://www.javabeat.net/2009/02/jms-interview-questions/</link>
		<comments>http://www.javabeat.net/2009/02/jms-interview-questions/#comments</comments>
		<pubDate>Fri, 13 Feb 2009 15:36:12 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[Interview Questions]]></category>
		<category><![CDATA[JMS]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=395</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>1) What is JMS? Java Message Service is the new standard for interclient communication. It allows J2EE application components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous. 2) What type messaging is provided by JMS Both synchronous and asynchronous 3) How may messaging models do [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>1) What is JMS?</h2>
<p>Java Message Service is the new standard for interclient communication. It allows J2EE application components to create, send, receive, and read messages. It enables distributed communication that is loosely coupled, reliable, and asynchronous.</p>
<h2>2) What type messaging is provided by JMS</h2>
<p>Both synchronous and asynchronous</p>
<h2>3) How may messaging models do JMS provide for and what are they?</h2>
<p>JMS provides for two messaging models, publish-and-subscribe and point-to-point queuing.</p>
<h2>4) What are the types of messaging?</h2>
<p>There are two kinds of Messaging:</p>
<ul>
<li>Synchronous messaging involves a client that waits for the server to respond to a message.</li>
<li>Asynchronous messaging involves a client that does not wait for a message from the server. An event is used to trigger a message from a server.</li>
</ul>
<h2>5) What is publish/subscribe messaging?</h2>
<p>With publish/subscribe message passing the sending application/client establishes a named topic in the JMS broker/server and publishes messages to this queue. The receiving clients register (specifically, subscribe) via the broker to messages by topic; every subscriber to a topic receives each message published to that topic. There is a one-to-many relationship between the publishing client and the subscribing clients.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<h2>6) Why doesn’t the JMS API provide end-to-end synchronous message delivery and notification of delivery?</h2>
<p>Some messaging systems provide synchronous delivery to destinations as a mechanism for implementing reliable applications. Some systems provide clients with various forms of delivery notification so that the clients can detect dropped or ignored messages. This is not the model defined by the JMS API. JMS API messaging provides guaranteed delivery via the once-and-only-once delivery semantics of PERSISTENT messages. In addition, message consumers can insure reliable processing of messages by using either CLIENT_ACKNOWLEDGE mode or transacted sessions. This achieves reliable delivery with minimum synchronization and is the enterprise messaging model most vendors and developers prefer. The JMS API does not define a schema of systems messages (such as delivery notifications). If an application requires acknowledgment of message receipt, it can define an application-level acknowledgment message.</p>
<h2>7) What are the core JMS-related objects required for each JMS-enabled application?</h2>
<p>Each JMS-enabled client must establish the following:</p>
<ul>
<li>A connection object provided by the JMS server (the message broker)</li>
<li>Within a connection, one or more sessions, which provide a context for message sending and receiving</li>
<li>Within a session, either a queue or topic object representing the destination (the message staging area) within the message broker</li>
<li>Within a session, the appropriate sender or publisher or receiver or subscriber object (depending on whether the client is a message producer or consumer and uses a point-to-point or publish/subscribe strategy, respectively). Within a session, a message object (to send or to receive)</li>
</ul>
<h2>8) What is the Role of the JMS Provider?</h2>
<p>The JMS provider handles security of the messages, data conversion and the client triggering. The JMS provider specifies the level of encryption and the security level of the message, the best data type for the non-JMS client.</p>
<h2>9) How does a typical client perform the communication?</h2>
<ol>
<li>Use JNDI to locate administrative objects.</li>
<li>Locate a single ConnectionFactory object.</li>
<li>Locate one or more Destination objects.</li>
<li>Use the ConnectionFactory to create a JMS Connection.</li>
<li>Use the Connection to create one or more Session(s).</li>
<li>Use a Session and the Destinations to create the MessageProducers and MessageConsumers needed.</li>
<li>Perform your communication.</li>
</ol>
<h2>10) Give an example of using the point-to-point model.</h2>
<p>The point-to-point model is used when the information is specific to a single client. For example, a client can send a message for a print out, and the server can send information back to this client after completion of the print job.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2009/02/jms-interview-questions/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Integrating Spring with JMS</title>
		<link>http://www.javabeat.net/2008/12/integrating-spring-with-jms/</link>
		<comments>http://www.javabeat.net/2008/12/integrating-spring-with-jms/#comments</comments>
		<pubDate>Tue, 16 Dec 2008 07:41:08 +0000</pubDate>
		<dc:creator>krishnas</dc:creator>
				<category><![CDATA[JMS]]></category>
		<category><![CDATA[Spring Framework]]></category>
		<category><![CDATA[Spring]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/?p=208</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Java Messaging Service opened the door for modeling the asynchronous mode of communication. It provides a common way of sending and receiving messages by having a middle man, also called as Message Broker or Message oriented Middleware. Now with the capability of an asynchronous framework like JMS being integrated with Spring, it can take all [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p id="Introduction"><strong style="font-size: 13px;"><em>Java Messaging Service</em></strong><span style="font-size: 13px;"> opened the door for modeling the asynchronous mode of communication. It provides a common way of </span><em style="font-size: 13px;">sending and receiving messages</em><span style="font-size: 13px;"> by having a middle man, also called as </span><strong style="font-size: 13px;"><em>Message Broker</em></strong><span style="font-size: 13px;"> or </span><strong style="font-size: 13px;"><em>Message oriented Middleware</em></strong><span style="font-size: 13px;">. Now with the capability of an asynchronous framework like </span><strong style="font-size: 13px;"><em>JMS</em></strong><span style="font-size: 13px;"> being integrated with </span><strong style="font-size: 13px;"><em>Spring</em></strong><span style="font-size: 13px;">, it can take all the benefits of </span><strong style="font-size: 13px;"><em>Spring</em></strong><span style="font-size: 13px;"> and this article shows you the steps of integrating </span><strong style="font-size: 13px;"><em>Spring</em></strong><span style="font-size: 13px;"> with the </span><strong style="font-size: 13px;"><em>JMS framework</em></strong><span style="font-size: 13px;">. This article assumes that you have a fair bit of knowledge in Spring as well as in </span><strong style="font-size: 13px;"><em>JMS</em></strong><span style="font-size: 13px;">.</span></p>
<h2>1. The Spring&#8217;s way</h2>
<ul>
<li><a href="../2007/10/integrating-spring-and-jsf/">Spring and JSF Integration</a></li>
<li><a href="../2007/10/integrating-spring-framework-with-hibernate-orm-framework/">Spring and Hibernate Integration</a></li>
<li><a href="../2009/02/spring-framework-interview-questions/">Spring Interview Questions</a></li>
</ul>
<p align="justify">Let&#8217;s us see how we can integrate the Spring for programming the asynchronous model using <strong><em>JMS</em></strong>. For that to happen, we need to use a <strong><em>Message Broker</em></strong> that acts as a middle man sitting between the sender and the receiving application. The example we are going to use makes use of the popular open source <strong><em>Message Broker</em></strong>, the <strong><em>ActiveMQ</em></strong>. Before continuing with the sample application, the necessary softwares, the Spring framework and the <strong><em>ActiveMQ Message Broker</em></strong> can be downloaded from &#8216;http://www.springsource.com/download/community?project=Spring%20Framework&#8217; and &#8216;https://activemq.apache.org/&#8217;.</p>
<h2>2. Configuring the Connection Factory</h2>
<p align="justify">In this section, we shall see how we can define a connection factory instance that provides the entry point for interacting with the JMS. It can be used to interact with the <strong><em>ActiveMQ Message Broker</em></strong> for creating a connection, through which a session can be established for <strong><em>sending and receiving messages</em></strong>. Examine the following definition,</p>
<pre class="brush: java; title: ; notranslate">
&lt;bean id=&quot;activeMQConnectionFactory&quot;
class=&quot;org.apache.activemq.ActiveMQConnectionFactory&quot;&gt;
&lt;property name=&quot;brokerURL&quot; value=&quot;tcp://jmsserver:9999&quot;/&gt;
&lt;/bean&gt;</pre>
<p>Note that when defining the bean it is mandatory that the class name that corresponds to the name of the Connection Factory of the <strong><em>Message Broker</em></strong> has to be known by looking into the vendor&#8217;s documentation, in our case, this happens to be <code>'org.apache.activemq.ActiveMQConnectionFactory'</code>. We have also specified the URL where the server is running by making use of the property <code>'brokerURL'</code>.</p>
<h2>3. Configuring the Message Destination</h2>
<p>A message destination refers to an abstract location where a message can be posted by a sender that will be received, later on, by the receiver. <strong><em>JMS</em></strong> supports two forms of messaging mode. They are</p>
<ul>
<li>Point to Point Messaging</li>
<li>Publish Subscribe Messaging</li>
</ul>
<h2>3.1. Point to Point Messaging</h2>
<p>In <strong><em>point to point messaging</em></strong>, the sender will post a message in a message destination called <strong><em>Queue</em></strong>. The sender application will make use of the Message Broker for placing the message in the <strong><em>Queue</em></strong>. Even though there may be multiple receiving applications that will be waiting for the message to get picked up, as soon as a receiver picks up the message, the copy of the message will be destroyed. The following code declares a JMS queue by name <code>'sampleQueue'</code>.</p>
<pre class="brush: java; title: ; notranslate">

&lt;bean id=&quot;sampleQueue&quot;
class=&quot;org.apache.activemq.command.ActiveMQQueue&quot;&gt;
&lt;/bean&gt;

</pre>
<h2>3.2. Publish Subscribe Messaging</h2>
<p align="justify">As the name suggests, in publish-subscribe messaging, the sending application will post the message in a message destination and there can be more than one receiving applications who will get the message. The message destination in publish subscribe messaging is called <strong><em>Topic</em></strong>. For defining a topic with name <code>'sampleTopic'</code> using Spring&#8217;s bean definition, use the following code,</p>
<pre class="brush: java; title: ; notranslate">&lt;/p&gt;
&lt;p align=&quot;justify&quot;&gt;&lt;bean id=&quot;sampleTopic&quot;
class=&quot;org.apache.activemq.command.ActiveMQTopic&quot;&gt;
&lt;/bean&gt;&lt;/p&gt;
&lt;p align=&quot;justify&quot;&gt;</pre>
<h2 id="JMSTemplateClass">4. Defining the JMS Template class</h2>
<p align="justify">In a traditional <strong><em>JMS application</em></strong> that acts as a sender, there will be huge amount of boilerplate code right from creating the connection factory instance, creating the session and sending the message as well as enclosing the code in a bunch of try-catch constructs for catching any JMS Exceptions. Spring&#8217;s <strong><em>JMSTemplate</em></strong> class simplifies the life of sending the message by eradicating all the boiler plate code asking the developer to concentrate only on the core business logic, i.e sending the message. Here is the declaration of the <strong><em>JMS Template</em></strong> class as a Spring bean,</p>
<pre class="brush: java; title: ; notranslate">
&lt;bean id=&quot;sampleJmsTemplate&quot;
class=&quot;org.springframework.jms.core.JmsTemplate&quot;&gt;
&lt;property name=&quot; connectionFactory&quot; ref=&quot; activeMQConnectionFactory&quot; /&gt;
&lt;/bean&gt;
</pre>
<p align="justify">Note that the <strong><em>JMS Template</em></strong> object needs to be aware of the connection factory reference through which it will contact the <strong><em>Message Broker</em></strong> for establishing connection and session.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<h2>5. Sending a message</h2>
<p align="justify">Let us keep the example as simple as sending the traditional &#8216;Hello World&#8217; message since the main motive of this sample is to show that how <strong><em>Spring</em></strong> can be integrated with <strong><em>JMS</em></strong>. Let us see the declaration of the sample message sending application class which is shown below,</p>
<p><strong>MessageSender.java</strong></p>
<pre class="brush: java; title: ; notranslate">
package net.javabeat.spring.jms;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class MessageSender
{
    private Destination destination;
    private JmsTemplate jmsTemplate;

    public MessageSender() {}

    public void setJmsTemplate(JmsTemplate jmsTemplate)
    {
        this.jmsTemplate = jmsTemplate;
    }

    public void setDestination(Destination destination)
    {
        this.destination = destination;
    }

    public void sendMessage()
    {
        MessageCreator creator = new MessageCreator()
        {
            public Message createMessage(Session session)
            {
                TextMessage message = null;
                try
                {
                    message = session.createTextMessage();
                    message.setStringProperty(&quot;text&quot;, &quot;Hello World&quot;);
                }
                catch (JMSException e)
                {
                    e.printStackTrace();
                }
                return message;
        }
    };

    jmsTemplate.send(destination, creator);
    }
}
</pre>
<p align="justify">The MessageSender class needs to be aware of two things, one is the destination object where the message has to be sent and the other being the JMSTemplate object that simplifies the process of sending the message. The sending of the message is defined by the method <code>JMSTemplate.send()</code> that takes 2 arguments. The first argument is the message destination itself and the second argument is the message creator object that knows how to create a message that can be sent later. In our example case, we had constructed a simple &#8216;Hello World&#8217; message and the following shows how to encapsulate the message sender class as a spring bean.</p>
<h2 id="ReceivingMessage">6. Receiving the message</h2>
<p align="justify">Receiving the message from the <strong><em>Message Broker</em></strong> is as simple as sending the message as the following code justifies it.</p>
<p><strong>MessageReceiver.java</strong></p>
<pre class="brush: java; title: ; notranslate">
package net.javabeat.spring.jms;

import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.TextMessage;

import org.springframework.jms.core.JmsTemplate;

public class MessageReceiver
{
    private JmsTemplate jmsTemplate;
    private Destination destination;

    public MessageReceiver() {}

    public void setJmsTemplate(JmsTemplate jmsTemplate)
    {
        this.jmsTemplate = jmsTemplate;
    }

    public void setDestination(Destination destination)
    {
        this.destination = destination;
    }

    public void receiveMessage()
    {
        Message message = jmsTemplate.receive();
        TextMessage textMessage = null;
        if (message instanceof TextMessage)
        {
            textMessage = (TextMessage)message;
            try
            {
                System.out.println(textMessage.getStringProperty(&quot;text&quot;));
            }
            catch (JMSException e)
            {
                e.printStackTrace();
            }
       }
    }
}
</pre>
<p align="justify">And here is the bean definition for the message receiver class,</p>
<h2>7. Summary</h2>
<p align="justify">In this article, we have learnt about the basic usage of JMS in the Spring environment. As we can see, it is very simple to create, send and receive messages in JMS using Spring&#8217;s simplified configuration mechanism.</p>
<p align="justify">If you have any doubts on the spring framework integration with JMS, please post it in the comments section. Also search in our website to find lot of other interesting articles related to the spring framework. There are some interesting articles about <a href="http://www.javabeat.net/2007/08/introduction-to-spring-web-framework/">spring framework</a>, <a href="http://www.javabeat.net/2009/02/spring-framework-interview-questions/">interview questions</a>, <a href="http://www.javabeat.net/2007/10/integrating-spring-framework-with-hibernate-orm-framework/">spring and hibernate integration</a>,etc. If you are looking for the detailed knowledge, buy any of the following books for the spring framework.</p>
<ul>
<li><a href="http://www.flipkart.com/spring-action-9350042096/p/itmdfjfg9hhwjk2z?pid=9789350042090&amp;affid=suthukrish" target="_blank">Spring In Action:Covers Spring 3.0</a></li>
<li><a href="http://www.flipkart.com/spring-batch-action-9350042592/p/itmd4v8gru2gxxvm?pid=9789350042595&amp;affid=suthukrish" target="_blank">Spring Batch In Action</a></li>
<li><a href="http://www.flipkart.com/spring-dynamic-modules-action-9350040621/p/itmdf85jgmxfv8hk?pid=9789350040621&amp;affid=suthukrish" target="_blank">Spring Dynamic Modules In Action</a></li>
</ul>
<p>If you would like to receive the future java articles from our website, please subscribe <a href="http://www.javabeat.net/subscribe/">here</a>.</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2008/12/integrating-spring-with-jms/feed/</wfw:commentRss>
		<slash:comments>8</slash:comments>
		</item>
		<item>
		<title>Publish and Subscribe messages using JMS Topic in JBoss Server</title>
		<link>http://www.javabeat.net/2008/07/publish-and-subscribe-messages-using-jms-topic-in-jboss-server/</link>
		<comments>http://www.javabeat.net/2008/07/publish-and-subscribe-messages-using-jms-topic-in-jboss-server/#comments</comments>
		<pubDate>Thu, 10 Jul 2008 10:29:08 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JBoss]]></category>
		<category><![CDATA[JMS]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=132</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Publish and Subscribe using JMS Topic This tips gives overview on how to write Java Messaging Service(JMS) code for creating Topic in the Tomcat server. This is very basic example and only show how to get started instead of looking into the advanced concepts in JMS technology. In JMS, publish/subscribe messaging uses a JMS-managed object [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><h2>Publish and Subscribe using JMS Topic</h2>
<p>This tips gives overview on how to write <b><i>Java Messaging Service(JMS)</i></b> code for creating Topic in the Tomcat server. This is very basic example and only show how to get started instead of looking into the advanced concepts in JMS technology.</p>
<p>In <b><i>JMS</i></b>, publish/subscribe messaging uses a JMS-managed object called a Topic to manage message flow from publishers to subscribers. <b><i>JMS</i></b> publishers are called message producers, and <b><i>JMS</i></b> subscribers are called message consumers. A message producer acquires a reference to a <b><i>JMS Topic</i></b> on a server, and sends messages to that Topic. When a message arrives, the <b><i>JMS provider</i></b> is responsible for notifying all message consumers subscribed to that Topic. The JMS provider (optionally) receives acknowledgment of the message receipt each time it sends the message. </p>
<p>This example is used <b><i>JBoss server</i></b> for the testing of application. Before run this example please start your <b><i>JBoss server</i></b> and put the following jar files in the classpath. JAR files are specific to the JBoss server MQ operations. It may not work with other vendor provided application servers.</p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p>The example program just simply add a message into the <b><i>JMS Topic</i></b> and subscribe to the topic.</p>
<h3>JAR files</h3>
<ul>
<h4>jms.jar</h4>
<h4>jnp-client.jar</h4>
<h4>jboss-common.jar</h4>
<h4>concurrent.jar</h4>
<h4>jbossmq-client.jar</h4>
<h3>JMSExample.java</h3>
</ul>
<h3>jbossmq-destinations-service.xml</h3>
<p>The following code needs to be added in the JBoss configuration xml file for creating the Topic while server<br />
is started.</p>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
</pre></td><td class="code"><pre class="language" style="font-family:monospace;"> &lt;mbean code=&quot;org.jboss.mq.server.jmx.Topic&quot;
     name=&quot;jboss.mq.destination:service=Topic,name=testTopic&quot;&gt;
    &lt;depends optional-attribute-name=&quot;DestinationManager&quot;&gt;jboss.mq:service=DestinationManager&lt;/depends&gt;
    &lt;depends optional-attribute-name=&quot;SecurityManager&quot;&gt;jboss.mq:service=SecurityManager&lt;/depends&gt;
    &lt;attribute name=&quot;SecurityConf&quot;&gt;
      &lt;security&gt;
        &lt;role name=&quot;guest&quot; read=&quot;true&quot; write=&quot;true&quot;/&gt;
        &lt;role name=&quot;publisher&quot; read=&quot;true&quot; write=&quot;true&quot; create=&quot;false&quot;/&gt;
        &lt;role name=&quot;durpublisher&quot; read=&quot;true&quot; write=&quot;true&quot; create=&quot;true&quot;/&gt;
      &lt;/security&gt;
    &lt;/attribute&gt;
  &lt;/mbean&gt;</pre></td></tr></table></div>

<h3>jbossmq-destinations-service.xml</h3>

<div class="wp_syntax"><table><tr><td class="line_numbers"><pre>1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
</pre></td><td class="code"><pre class="language" style="font-family:monospace;">package javabeat.net.jms;
&nbsp;
import java.util.Properties;
&nbsp;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import javax.jms.Topic;
import javax.jms.TopicConnection;
import javax.jms.TopicConnectionFactory;
import javax.jms.TopicPublisher;
import javax.jms.TopicSession;
import javax.jms.TopicSubscriber;
import javax.naming.Context;
import javax.naming.InitialContext;
&nbsp;
public class JMSExample implements MessageListener {
&nbsp;
    public static void main(String argc[]) {
        new JMSExample().testMessage();
    }
&nbsp;
    public void testMessage() {
        TopicConnection conn = null;
        TopicSession session = null;
        Topic topic = null;
        try {
            Properties props = new Properties();
            props.setProperty(&quot;java.naming.factory.initial&quot;,
                    &quot;org.jnp.interfaces.NamingContextFactory&quot;);
            props.setProperty(&quot;java.naming.factory.url.pkgs&quot;,
                    &quot;org.jboss.naming&quot;);
            props.setProperty(&quot;java.naming.provider.url&quot;, &quot;localhost&quot;);
            Context context = new InitialContext(props);
            TopicConnectionFactory tcf = (TopicConnectionFactory) context.lookup(&quot;ConnectionFactory&quot;);
            conn = tcf.createTopicConnection();
            topic = (Topic) context.lookup(&quot;topic/testTopic&quot;);
            session = conn.createTopicSession(false,
                    TopicSession.AUTO_ACKNOWLEDGE);
            conn.start();
            TopicPublisher send = session.createPublisher(topic);
            TextMessage tm = session.createTextMessage(&quot;JavaBeat Test Message&quot;);
            send.publish(tm);
            send.close();
            TopicSubscriber topicSubscriber = session.createSubscriber(
                    topic);
            topicSubscriber.setMessageListener(this);
            while (true) {
                Message message = topicSubscriber.receive(1);
                if (message != null) {
                    if (message instanceof TextMessage) {
                        TextMessage textMessage = (TextMessage) message;
                        System.out.println(message);
                        System.out.println(
                                textMessage.getText());
                    } else {
                        break;
                    }
                }
            }
&nbsp;
        } catch (Exception e) {
            System.out.println(e.toString() + &quot; Does the queue exist?&quot;);
        }
    }
&nbsp;
    public void onMessage(Message message) {
        try {
            TextMessage textMessage = (TextMessage) message;
            String text = textMessage.getText();
            System.out.println(text);
        } catch (Exception jmse) {
            jmse.printStackTrace();
        }
    }
}</pre></td></tr></table></div>

<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2008/07/publish-and-subscribe-messages-using-jms-topic-in-jboss-server/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Java Messaging Service(JMS)</title>
		<link>http://www.javabeat.net/2008/05/java-messaging-servicejms/</link>
		<comments>http://www.javabeat.net/2008/05/java-messaging-servicejms/#comments</comments>
		<pubDate>Thu, 22 May 2008 00:41:39 +0000</pubDate>
		<dc:creator>JavaBeat</dc:creator>
				<category><![CDATA[JMS]]></category>

		<guid isPermaLink="false">http://www.javabeat.net/examples/?p=328</guid>
		<description><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><p>Distributed Object Technologies like RMI, CORBA and DCOM areadvanced variants of RPC(Remote-Procedure-Call).EJB( SessionBeans % Entity Beans)is essentially built on the RMI-IIOP model,( a combination of RMI with CORBA style). All these systems are Synchronous in nature. (ie) the client invokes a method on the remote object and if for some reason , there isdelay in [...]</p>]]></description>
				<content:encoded><![CDATA[<p>Connect to us ( <a href="https://twitter.com/javabeat">@twitter</a> | <a href="https://www.facebook.com/javabeat.net">@facebook )</p><div class="wpInsert wpInsertInPostAd wpInsertLeft" style="float: left; margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Rect */
google_ad_slot = "9976259118";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div><p><span><span></span>Distributed<br />
Object Technologies like RMI, CORBA and DCOM are<span></span>advanced variants of RPC<span></span>(Remote-Procedure-Call).<span></span>EJB<span></span>(<br />
SessionBeans % Entity Beans)<span></span>is<br />
essentially built on the RMI-IIOP model,( a combination of RMI with CORBA<br />
style). All these systems are <b>Synchronous </b>in nature. (ie) the client<br />
invokes a method on the remote object and if for some reason , there is<span></span>delay in response from the server end, the<br />
line gets<span></span><b>blocked</b>.This is<br />
sometimes referred to as &#039;<b>Tight Coupling&#039;</b>.<span></span>In </span><span>Enterprise</span><span> level<br />
computing, especially,<b> B2B</b>(Business to Business) a number of<br />
applications are integrated together<span></span>.If<span></span>either one of the<br />
applications crashes or if we want to add/remove a section from this integrated<br />
scheme,<span></span>it leads to a mess. </span></p>
<p class="MsoNormal"><span><span></span>This is what led<br />
to the development of <b>Messaging </b>systems. Such systems are based on<b><br />
Asynchronous </b>processing. (ie) a<span></span>program<span></span>sends<span></span>a<span></span>message to another program<span></span>but<br />
does not wait for response. This ensures that there is no &#039;blocking&#039;.<br />
Fundamentally, the idea is similar to <b>&#039;email&#039;</b>.Such systems are said to<br />
be <b>&#039;loosely coupled&#039; </b>systems. Wherever there are huge number of players<br />
, loose coupling is beneficial. For this reason, the </span><span>Enterprise</span><span> world<br />
is<span></span>nowadays<span></span>veering round to the Messaging protocol . It<br />
is in response to this shift in requirements, that Sun added<span></span>the<b> JMS ( Java Messaging System) </b>API<br />
and<span></span>then<span></span><b>Message-driven bean </b>as a third type<br />
of EJBean in addition to Session Bean &amp; Entity bean. .</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>A number of<span></span>such Messaging Systems had been developed by<br />
Enterprise-world majors.These are known as &#039;<b>Message-oriented-Middleware&#039;.<br />
(MOM</b>).<span></span>Also known as<b> JMS<br />
-Provider</b>.</span></p>
<p class="MsoNormal"><span><span></span>A list of such<br />
MOM products is given below.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>1)<span></span><b><span></span>WebLogic<span></span>from BEA</b></span></p>
<p class="MsoNormal"><b><span><span></span>2)<span></span></span></b><span><span></span>MQSeries<span></span>from<span></span>IBM</span></p>
<p class="MsoNormal"><span><span></span><span></span>3)<span></span>JBossMQ<span></span>from <b>JBoss</b></span></p>
<p class="MsoNormal"><span><span></span>4)<span></span>SoniqMQ<span></span>from Progress<span></span></span></p>
<p class="MsoNormal"><span><span></span>(<span></span>David Chappel&#039;s company)</span></p>
<p class="MsoNormal"><span><span></span>5)<span></span>FiaranoMQ<span></span><span></span>from Fiarano<span></span></span></p>
<p class="MsoNormal"><span><span></span>6)<span></span>MSMQ<span></span>from Microsoft</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></p>
<p class="MsoNormal"><span><span></span><b><span></span>JMS is not a messaging system by itself</b>. It<br />
is an abstraction of the underlying principles of<span></span>the major Messaging systems in industry. This<br />
enables the programmer to write code as if there is just one generic MOM<br />
system..(<b> Microsoft<span></span>does not follow<br />
JMS</b>).</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></p>
<p class="MsoNormal"><span><span></span>There are two<br />
types of messaging:<span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>a) <b>Publish<span></span>&amp;<span></span>Subscribe</b></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>b) <b><span></span>Point<span></span>to<span></span>Point</b></span></p>
<p class="MsoNormal"><b><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></b><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>In<b> Publish<br />
&amp; Subscribe </b>method, the sender sends the message to<span></span>JMS-Provider.. The JMS-Provider <b>broadcasts</b><br />
the message. The message will be received by any &#039;listener&#039;<span></span>who<span></span>&#039;<br />
tunes&#039;<span></span>himself to the broadcast by<br />
registering himself as a listener. In such a method ,<span></span>the message is known as a <b>&#039;Topic&#039;.</b>The<br />
sender is known as <b>&#039;publisher&#039; </b>and the receiver is known as<b><br />
&#039;subscriber</b>&#039;.This is sometimes referred to as &#039;<b>one to many&#039;</b>.</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>In the<b> Point<br />
to Point </b>method<b>, </b>the &#039;<b>Sender</b>&#039; sends the message as before to<br />
the MOM server. These message are meant for a specific <b>&#039;Receiver</b>&#039;.Such a<br />
message is known as a <b>&#039;Queue&#039;</b>. The listener registers himself with the<br />
JMS-Provider for a particular<span></span>message<br />
and as soon as a message arrives at the provider,it is sent to the listener.<span></span>This method is referred to as <b>&#039;one to one&#039;</b>.</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>For writing<br />
messaging programs, we need to import<b> jms </b>package. ( <b>This is<br />
available in weblogic by default.</b>).</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>The<span></span>coding<span></span>concepts are almost identical for Topics and Queues.</span></p>
<p class="MsoNormal"><span><span></span>So we will<br />
illustrate the steps for<span></span>Topic method<br />
only. </span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>steps:<span></span>for <b>&#039;publishdemo&#039; </b>program.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>1) connect<span></span>to<span></span>the <b><span></span>JMS PROVIDER</b>. </span></p>
<p class="MsoNormal"><span><span></span>2)<b> locate<span></span>TopicConnectionFactory</b></span></p>
<p class="MsoNormal"><span><span></span>3) create a<span></span><b><span></span>TopicConnection<span></span></b></span></p>
<p class="MsoNormal"><span><span></span>4) create a<span></span><b><span></span>TopicSession</b></span></p>
<p class="MsoNormal"><span><span></span>5) <b>locate</b> the<span></span><b><span></span>Topic</b></span></p>
<p class="MsoNormal"><span><span></span>6)<span></span>create a<span></span><b>TopicPublisher </b></span></p>
<p class="MsoNormal"><span><span></span>7) create a<span></span><b><span></span>TextMessage </b>or other types of </span></p>
<p class="MsoNormal"><span><span></span>message.</span></p>
<p class="MsoNormal"><span><span></span>8) start the connection</span></p>
<p class="MsoNormal"><span><span></span>9) <b>publish</b> the message</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span>The &#039;publishdemo&#039;<span></span>program<span></span>thus<span></span>sends the message to<span></span>a<span></span>JMS-Provider<span></span>(ie)<br />
WebLogic.,<span></span>for publication.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-<span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span>A separate <b>&#039;subscribedemo&#039;<br />
</b>program<span></span>connects to the same<span></span>JMS-Provider, and follows a similar<br />
procedure,but this time as a recipient of message.</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span>1)connect to <b><span></span></b><span></span>the<span></span><b>JMS<br />
PROVIDER</b>. </span></p>
<p class="MsoNormal"><span><span></span>2)<b> locate<span></span>TopicConnectionFactory</b></span></p>
<p class="MsoNormal"><span><span></span><span></span>3) create a<span></span><b><span></span>TopicConnection<span></span></b></span></p>
<p class="MsoNormal"><b><span><span></span></span></b><span>from<br />
the<span></span>above factory</span></p>
<p class="MsoNormal"><span><span></span>4) create a<span></span><b><span></span>TopicSession</b></span></p>
<p class="MsoNormal"><span><span></span>5) locate the<span></span><b><span></span>Topic</b></span></p>
<p class="MsoNormal"><span><span></span>6)<span></span>create a<span></span><b>TopicSubscriber </b></span></p>
<p class="MsoNormal"><span><span></span>7) Register the subscriber as a <b>messageListener </b></span></p>
<p class="MsoNormal"><span><span></span>8)Wait to get message from JMS<span></span></span></p>
<p class="MsoNormal"><span><span></span>9) Get the message as and when sent by the sender.<span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;-</span></p>
<p class="MsoNormal"><span><span></span>This time , we will<br />
create our programs as <b>&#039;stand-alone&#039; frames </b>.There are no fancy items in<br />
the GUI (Graphical User Interface). The<span></span>GUI for the &#039;publishdemo&#039;&#039;<span></span>program has just a textfield and a button to &#039;send&#039; the message.Another<br />
button is provided for &#039;exit&#039;.</span></p>
<p class="MsoNormal"><span><span></span>Similarly, the GUI<br />
for the &#039;subscribedemo&#039; program has just<span></span>a<span></span>textarea .</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;</span></p>
<p class="MsoNormal"><span><span></span>We start the<br />
&#039;subscribedemo&#039; program first. ( to start listening!). Then we start the<br />
&#039;publishdemo&#039; program . We type some message in text1<span></span>of<span></span>&#039; <b>publishdemo&#039;</b><br />
window and click the &#039;send&#039; button. The message goes to the JMS-Provider and it<br />
broadcasts the message to all registered listeners. So our <b><span></span>&#039;subscribedemo&#039; </b>program<span></span>gets the message and it is displayed in<br />
textarea. <b>We can close the sender and restart . The client side is not<br />
affected. You will remember that in socket method , if you close the sender,<br />
the client will quit because it was synchronous. </b></span></p>
<p class="MsoNormal"><span><span></span>Just to make it<br />
interesting, we start <b>another receiver program in a separate window</b>. We<br />
will find that<b> this client also gets the message</b>.<span></span>With<span></span>all this description, it should not be difficult to follow the coding.</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><span><span></span>If we want<br />
to make use of QUEUE<span></span>, the steps are<br />
almost identical.</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span>1)connect<br />
to<span></span>JMS-Provider</span></p>
<p class="MsoNormal"><span><span></span>2)<b><br />
locate<span></span></b>QueueConnectionFactory</span></p>
<p class="MsoNormal"><span><span></span>3)<br />
create<span></span>QueueConnection</span></p>
<p class="MsoNormal"><span><span></span>4)<br />
create<span></span>QueueSession</span></p>
<p class="MsoNormal"><span><span></span>5)<b><br />
locate<span></span></b>Queue</span></p>
<p class="MsoNormal"><span><span></span>6)<br />
create<span></span>a<span></span>QueueSender</span></p>
<p class="MsoNormal"><span><span></span><span></span>7) create the message</span></p>
<p class="MsoNormal"><span><span></span>8)<span></span>send the message.</span></p>
<p class="MsoNormal"><span><span></span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><span><span></span>Similar steps for<br />
the QueueReceiver.</span></p>
<p class="MsoNormal"><span>==============================================================<span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>The following demo illustrates a Publish-Subscribe<span></span>model.</span></p>
<p class="MsoNormal"><span><span></span>You will find<br />
reference to <b>&#039;ourfactory&#039;<span></span></b>&amp; <b>&#039;ourtopic&#039;<span></span></b>in the code.</span></p>
<p class="MsoNormal"><span>These are known as <b>&#039;Administered objects&#039;</b>. (ie) we<br />
set up these names in the relevant section of the Weblogic.properties<span></span>file. How it is done has been explained<br />
below.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><span></span>//<span></span>***************<span></span><b><span></span>publishdemo.java<span></span></b>**************************</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>import javax.ejb.*;</span></p>
<p class="MsoNormal"><span>import javax.jms.*;</span></p>
<p class="MsoNormal"><span>import javax.naming.*;</span></p>
<p class="MsoNormal"><span>import java.rmi.*;</span></p>
<p class="MsoNormal"><span>import java.util.*;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>import java.awt.*;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>public class publishdemo<span></span>extends Frame</span></p>
<p class="MsoNormal"><span>{</span></p>
<p class="MsoNormal"><span><span></span>TextField<span></span>text1;</span></p>
<p class="MsoNormal"><span><span></span>Button<span></span>button1;</span></p>
<p class="MsoNormal"><span><span></span>Button<span></span>button2;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b>TopicPublisher<br />
</b><span></span>publisher;</span></p>
<p class="MsoNormal"><span><span></span><b>TextMessage</b><span></span>tm;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>public<br />
static void main(String args[])</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span>publishdemo<span></span>app=<span></span>new publishdemo();</span></p>
<p class="MsoNormal"><span><span></span>app.resize(300,200);</span></p>
<p class="MsoNormal"><span><span></span>app.show();</span></p>
<p class="MsoNormal"><span><span></span>}</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>public<br />
publishdemo()</span></p>
<p class="MsoNormal"><span><span></span>{<span></span></span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span>setLayout(new FlowLayout());</span></p>
<p class="MsoNormal"><span><span></span>setBackground(Color.red);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>text1=new TextField(40);</span></p>
<p class="MsoNormal"><span><span></span>button1=new Button(&quot;send&quot;);</span></p>
<p class="MsoNormal"><span><span></span>button2=new Button(&quot;Exit&quot;);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>add(text1);</span></p>
<p class="MsoNormal"><span><span></span>add(button1);</span></p>
<p class="MsoNormal"><span><span></span>add(button2);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>System.out.println(&quot;Please wait&quot;);// diagnostic<span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span><b>Properties</b><span></span>props=new Properties();</span></p>
<p class="MsoNormal"><span><span></span>props.put(Context.INITIAL_CONTEXT_FACTORY,</span></p>
<p class="MsoNormal"><span><span></span>&quot;weblogic.jndi.WLInitialContextFactory&quot;);</span></p>
<p class="MsoNormal"><span><span></span>props.put(Context.PROVIDER_URL,</span></p>
<p class="MsoNormal"><span><span></span>&quot;t3://127.0.0.1:7001&quot;);<span></span></span></p>
<p class="MsoNormal"><span><span></span><b><span></span>Context<span></span></b>context=new InitialContext(props);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>System.out.println(&quot;context<br />
ok&quot;);</span></p>
<p class="MsoNormal"><span><span></span>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b>TopicConnectionFactory<span></span></b><span></span>factory=</span></p>
<p class="MsoNormal"><span><span></span>(TopicConnectionFactory)context.lookup(<b>&quot;ourfactory&quot;</b>); </span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b>TopicConnection</b><span></span>connection=</span></p>
<p class="MsoNormal"><span><span></span>factory.createTopicConnection();</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span><b>TopicSession<span></span></b>session=</span></p>
<p class="MsoNormal"><span><span></span>connection.createTopicSession</span></p>
<p class="MsoNormal"><span><span></span>(false,Session.AUTO_ACKNOWLEDGE);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b>Topic</b><span></span>topic= </span></p>
<p class="MsoNormal"><span><span></span>(Topic)context.lookup<b>(&quot;ourtopic&quot;);</b><span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>publisher<span></span>=<span></span>session.createPublisher(topic);</span></p><div class="wpInsert wpInsertInPostAd wpInsertMiddle" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* Article-Middle-Med-Rect */
google_ad_slot = "7805667846";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>tm<span></span>=<span></span>session.createTextMessage();</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span>}catch(Exception e1){System.out.println(&quot;&quot;+e1);}</span></p>
<p class="MsoNormal"><span><span></span>}</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>public<br />
boolean action(Event e,Object c)</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span>if(e.target==button1)</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span>try</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span>String text=text1.getText();</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>tm.setText(text);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>publisher.publish(tm);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>System.out.println(&quot;message published&quot;);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>}catch(Exception e1){System.out.println(&quot;&quot;+e1); }<span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>}</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>if(e.target==button2)</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span>System.exit(0);</span></p>
<p class="MsoNormal"><span><span></span>}</span></p>
<p class="MsoNormal"><span><span></span>return<br />
true;</span></p>
<p class="MsoNormal"><span><span></span>}</span></p>
<p class="MsoNormal"><span>}</span></p>
<p class="MsoNormal"><span>============================================================================</span><span></span></p>
<p class="MsoNormal"><span><span></span>//<span></span><b><span></span>subscribedemo.java<span></span></b></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>import javax.ejb.*;</span></p>
<p class="MsoNormal"><span>import javax.jms.*;</span></p>
<p class="MsoNormal"><span>import javax.naming.*;</span></p>
<p class="MsoNormal"><span>import java.rmi.*;</span></p>
<p class="MsoNormal"><span>import java.util.*;</span></p>
<p class="MsoNormal"><span>import java.awt.*;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>public class subscribedemo<span></span>extends Frame<span></span><b>implements<span></span>MessageListener</b></span></p>
<p class="MsoNormal"><span>{</span></p>
<p class="MsoNormal"><span>TextArea<span></span>area1;</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>public<br />
static void main(String args[])</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span>subscribedemo<span></span>app = new<br />
subscribedemo();</span></p>
<p class="MsoNormal"><span><span></span>app.resize(300,300);</span></p>
<p class="MsoNormal"><span><span></span>app.show();</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>}</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>public<span></span>subscribedemo()</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>setBackground(Color.orange);</span></p>
<p class="MsoNormal"><span><span></span>setLayout(new FlowLayout());<span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>area1 =<br />
new TextArea(10,30);</span></p>
<p class="MsoNormal"><span><span></span>add(area1);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>try</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span>area1.append(&quot;please waitn&quot;);</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span>Properties<br />
props=new Properties();</span></p>
<p class="MsoNormal"><span><span></span>props.put(Context.INITIAL_CONTEXT_FACTORY,</span></p>
<p class="MsoNormal"><span><span></span>&quot;weblogic.jndi.WLInitialContextFactory&quot;);</span></p>
<p class="MsoNormal"><span><span></span>props.put(Context.PROVIDER_URL,</span></p>
<p class="MsoNormal"><span><span></span>&quot;t3://127.0.0.1:7001&quot;);</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span>Context<br />
context=new InitialContext(props);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>area1.append(&quot;context<br />
readyn&quot;);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>//&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><span><span></span><b>TopicConnectionFactory<span></span></b><span></span>factory=</span></p>
<p class="MsoNormal"><span><span></span>(TopicConnectionFactory)context.lookup<b>(&quot;ourfactory&quot;);<span></span></b><span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b><span></span>TopicConnection<span></span></b>connection=</span></p>
<p class="MsoNormal"><span><span></span>factory.createTopicConnection();</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b>TopicSession<span></span></b><span></span>session=</span></p>
<p class="MsoNormal"><span><span></span>connection.createTopicSession</span></p>
<p class="MsoNormal"><span><span></span>(false,Session.AUTO_ACKNOWLEDGE);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b>Topic<span></span></b>topic=</span></p>
<p class="MsoNormal"><span><span></span>(Topic)context.lookup<b>(&quot;ourtopic&quot;);</b></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b>TopicSubscriber<span></span></b>subscriber=</span></p>
<p class="MsoNormal"><span><span></span>session.createSubscriber(topic);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span><b>subscriber.setMessageListener(this);</b></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>area1.append(&quot;starting connectionn&quot;);</span></p>
<p class="MsoNormal"><span><span></span><b>connection.start();</b></span></p>
<p class="MsoNormal"><span><span></span>area1.append(&quot;connection startedn&quot;);</span></p>
<p class="MsoNormal"><span><span></span>area1.append(&quot;waiting for messagen&quot;);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>area1.append(&quot;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8211;n&quot;);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>}catch(Exception e){area1.setText(&quot;&quot;+e);}</span></p>
<p class="MsoNormal"><span><span></span>}</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>public<br />
void<b> onMessage</b>(Message msg)</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span>try</span></p>
<p class="MsoNormal"><span><span></span>{</span></p>
<p class="MsoNormal"><span><span></span>TextMessage tm=(TextMessage)msg;<span></span></span></p>
<p class="MsoNormal"><span><span></span>String<br />
s=tm.getText();</span></p>
<p class="MsoNormal"><span><span></span>area1.append(s+&quot;n&quot;);</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>}<span></span>catch(Exception<br />
e){area1.setText(&quot;&quot;+e);}</span></p>
<p class="MsoNormal"><span><span></span>}<span></span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span>}</span></p>
<p class="MsoNormal"><span>============================================================================</span><span></span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>How shall we test<br />
this program?</span></p>
<p class="MsoNormal"><span><span></span>=========================</span></p>
<p class="MsoNormal"><span><span></span><b><span></span>This program is not connected with EJB but is<br />
preliminary to the study of Message-Driven Bean to be takenup shortly.<span></span>So far, all our examples are being run with<br />
Weblogic 5.1. It can be run on Windows-98.</b></span></p>
<p class="MsoNormal"><b><span><span></span></span></b></p>
<p class="MsoNormal"><b><span>Message-Driven bean is based on EJB2.0 specification and<br />
requires Weblogic7.0 . which needs Windows 2000 for proper functioning.</span></b></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><span><span></span><b>We will now<br />
test our JMS program in Weblogic 5.1 installed in Windows- 98.</b></span></p>
<p class="MsoNormal"><b><span>&#8212;&#8212;&#8212;-</span></b></p>
<p class="MsoNormal"><span><span></span>Create a<br />
folder<span></span>as:<span></span><b>c:jmsdemo</b></span></p>
<p class="MsoNormal"><span><span></span>cd to<span></span>c:jmsdemo</span></p>
<p class="MsoNormal"><span><span></span>&gt; SET<span></span>JAVA_HOME=C:JDK1.3</span></p>
<p class="MsoNormal"><span><span></span>&gt;<span></span>SET<span></span>WL_HOME=C:WEBLOGIC</span></p>
<p class="MsoNormal"><span><span></span>&gt; set <b>path</b>=c:windowscommand;<br />
c:jdk1.3bin;c:weblogicbin</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>&gt; set <b>classpath</b>=c:jmsdemo;c:weblogicclasses;c:weblogiclibweblogicaux.jar</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><span><span></span>Edit<span></span>publishdemo.java<span></span>and<span></span>subscribedemo.java<span></span>in<span></span>c:jmsdemo<span></span>folder.</span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><span><span></span>&#8230;..jmsdemo<br />
&gt;javac<span></span>*.java<span></span>//<span></span>compile</span></p>
<p class="MsoNormal"><span><span></span>&#8212;&#8212;</span></p>
<p class="MsoNormal"><span>*****************************************************</span></p>
<p class="MsoNormal"><span><span></span>Edit<span></span>c:weblogicweblogic.properties<span></span>file<span></span>as<span></span>follows:</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>You will find a<br />
section<span></span>named<span></span>&#039;Weblogic JMS DEMO<span></span>PROPERTIES&#039;.</span></p>
<p class="MsoNormal"><span></span></p>
<p class="MsoNormal"><span><span></span>ADD THE FOLLOWING<br />
LINES<span></span></span></p>
<p class="MsoNormal"><span>&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;&#8212;</span></p>
<p class="MsoNormal"><span><span></span><b><span></span>weblogic.jms.connectionFactoryName.ourfactory=ourfactory</b></span></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><b><span><span></span>weblogic.jms.topic.ourtopic=ourtopic</span></b></p>
<p class="MsoNormal"><b><span>***********************************************************</span></b></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><span><span></span>From the &#039;start&#039;<br />
menu,<span></span>remember<span></span>to start the weblogic server as before.</span></p>
<p class="MsoNormal"><span><span></span>Minimize the window.</span></p>
<p class="MsoNormal"><span><span></span>Run the subscriber<br />
program first.</span></p>
<p class="MsoNormal"><span><span></span></span></p>
<p class="MsoNormal"><span><span></span><b><span></span>&#8230;.</b> jmsdemo <b>&gt;java<span></span>subscribedemo<span></span></b></span></p>
<p class="MsoNormal"><b><span></span></b></p>
<p class="MsoNormal"><b><span><span></span></span></b><span><span></span>You will get<span></span>a window with<span></span>just a<br />
textarea.<span></span></span></p>
<p class="MsoNormal"><span><span></span>The area will<br />
display :</span></p>
<p class="MsoNormal"><span><span></span>connection started</span></p>
<p class="MsoNormal"><span><span></span><span></span>waiting for message</span></p>
<p class="MsoNormal"><span><span></span>&#8212;&#8212;&#8212;&#8211;</span></p>
<p class="MsoNormal"><span><span></span>Now go to<br />
another dos prompt and set path, classpath etc as before.</span></p>
<p class="MsoNormal"><span><span></span>Start the<br />
publishdemo program</span></p>
<p class="MsoNormal"><span><span></span>&#8230;.jmsdemo&gt;<b>java<span></span>publishdemo</b></span></p>
<p class="MsoNormal"><b>&lt;span style=&quot;font-family: &quot;Courier New</p>
<div class="wpInsert wpInsertInPostAd wpInsertBelow" style="margin: 5px; padding: 0px;"><script type="text/javascript"><!--
google_ad_client = "ca-pub-1490953723360528";
/* JB-Footer-LU 468x15 */
google_ad_slot = "8789107210";
google_ad_width = 468;
google_ad_height = 15;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script></div>]]></content:encoded>
			<wfw:commentRss>http://www.javabeat.net/2008/05/java-messaging-servicejms/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
