<?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>Kandy Software, Inc. &#187; onMessage()</title>
	<atom:link href="http://www.kandysoftwareinc.com/tech-articles/tag/onmessage/feed" rel="self" type="application/rss+xml" />
	<link>http://www.kandysoftwareinc.com</link>
	<description></description>
	<lastBuildDate>Thu, 20 Jan 2011 04:03:54 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.1.3</generator>
		<item>
		<title>JMS Internals</title>
		<link>http://www.kandysoftwareinc.com/tech-articles/jms-internals</link>
		<comments>http://www.kandysoftwareinc.com/tech-articles/jms-internals#comments</comments>
		<pubDate>Thu, 14 Feb 2008 02:35:26 +0000</pubDate>
		<dc:creator>admin</dc:creator>
				<category><![CDATA[JEE]]></category>
		<category><![CDATA[JMS]]></category>
		<category><![CDATA[asynchronous]]></category>
		<category><![CDATA[delivery]]></category>
		<category><![CDATA[JBoss]]></category>
		<category><![CDATA[MDB]]></category>
		<category><![CDATA[message]]></category>
		<category><![CDATA[onMessage()]]></category>
		<category><![CDATA[queue]]></category>
		<category><![CDATA[topic]]></category>
		<category><![CDATA[Websphere]]></category>

		<guid isPermaLink="false">http://www.kandysoftwareinc.com/?p=101</guid>
		<description><![CDATA[This article explains JMS architecture, message models, messaging domains and various components in a JMS system. It begins with the basics and explains some powerful yet not well known techniques and concepts. Techniques like pausing message delivery, selecting messages etc explained.]]></description>
			<content:encoded><![CDATA[<p>[print_link]</p>
<h3><strong>Introduction</strong></h3>
<p><a href="http://www.kandysoftwareinc.com/wp-content/uploads/2008/11/jms-internals.png"><img src="http://www.kandysoftwareinc.com/wp-content/uploads/2008/11/jms-internals.png" alt="" title="jms-internals" width="190" height="131" class="alignleft size-medium wp-image-111" /></a>This article discusses JMS architecture and various components within a JMS system. Message models and messaging styles are explained. The article also discuses synchronous and asynchronous message consumption. </p>
<h3><strong>JMS Architecture</strong></h3>
<p>JMS (as defined in JMS specification version 1.1) is a set of interfaces and associated semantics that provides a common way for Java programs to create, send, receive and read an enterprise messaging system’s <i>messages</i>. In this context <i>messages</i> are asynchronous requests, reports or events that are consumed by enterprise applications, not humans. They contain precisely formatted data that describe specific business actions.<br />
A JMS application is composed of the following parts:</p>
<ul>
<li>JMS Clients: These are Java programs that send and receive messages. For example, Message Driven Beans.</li>
<li>Messages: The information transferred between the clients.</li>
<li>JMS Provider: The messaging system that implements JMS specification. JBossMQ is an example.</li>
<li>Administered Objects: These are pre-configured JMS objects used by the clients. There are two types of administered objects:
<ol>
<li>Connection Factory: Client uses this object to create a connection with a provider.</li>
<li>Destination: Client uses this object to specify the destination of messages it is sending or the source of messages it receives.</li>
</ol>
</li>
</ul>
<h3><strong>Message Model</strong></h3>
<p>Messages are lightweight entities that consist of a header and a body. The header contains fields used for message routing and identification. The body is the payload which clients exchange.</p>
<table>
<tr>
<td>
Header used in JBossMQ
</td>
</tr>
<tr>
<td valign="top">

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">Header <span style="color: #009900;">&#123;</span> 
   jmsDestination  <span style="color: #339933;">:</span> QUEUE.<span style="color: #006633;">KSIDemoQueue</span>
   jmsDeliveryMode <span style="color: #339933;">:</span> <span style="color: #cc66cc;">2</span>
   jmsExpiration   <span style="color: #339933;">:</span> <span style="color: #cc66cc;">0</span>
   jmsPriority     <span style="color: #339933;">:</span> <span style="color: #cc66cc;">4</span>
   jmsMessageID    <span style="color: #339933;">:</span> ID<span style="color: #339933;">:</span><span style="color: #cc66cc;">29</span><span style="color: #339933;">-</span><span style="color: #cc66cc;">12015475384804</span>
   jmsTimeStamp    <span style="color: #339933;">:</span> <span style="color: #cc66cc;">1201547538480</span>
   jmsCorrelationID<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">null</span>
   jmsReplyTo      <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">null</span>
   jmsType         <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">null</span>
   jmsRedelivered  <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
   jmsProperties   <span style="color: #339933;">:</span> <span style="color: #009900;">&#123;</span>JMS_JBOSS_REDELIVERY_COUNT<span style="color: #339933;">=</span><span style="color: #cc66cc;">2</span><span style="color: #009900;">&#125;</span>
   jmsPropReadWrite<span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">false</span>
   msgReadOnly     <span style="color: #339933;">:</span> <span style="color: #000066; font-weight: bold;">true</span>
   producerClientId<span style="color: #339933;">:</span> ID<span style="color: #339933;">:</span><span style="color: #cc66cc;">29</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

</td>
</tr>
<tr>
<td>
Header used in WebSphere 5.1
</td>
</tr>
<tr>
<td valign="top">

<div class="wp_syntax"><div class="code"><pre class="java" style="font-family:monospace;">  JMSType<span style="color: #339933;">:</span>         <span style="color: #000066; font-weight: bold;">null</span>
  JMSDeliveryMode<span style="color: #339933;">:</span> <span style="color: #cc66cc;">2</span>
  JMSExpiration<span style="color: #339933;">:</span>   <span style="color: #cc66cc;">0</span>
  JMSPriority<span style="color: #339933;">:</span>     <span style="color: #cc66cc;">4</span>
  JMSMessageID<span style="color: #339933;">:</span>    ID<span style="color: #339933;">:</span>414d5120445149434d5320202020202046f2d24b2001c001
  JMSTimestamp<span style="color: #339933;">:</span>    <span style="color: #cc66cc;">1201106363820</span>
  JMSCorrelationID<span style="color: #339933;">:</span><span style="color: #000066; font-weight: bold;">null</span>
  JMSDestination<span style="color: #339933;">:</span>  queue<span style="color: #339933;">:</span><span style="color: #666666; font-style: italic;">///QUEUE.KSIDemoQueue</span>
  JMSReplyTo<span style="color: #339933;">:</span>      <span style="color: #000066; font-weight: bold;">null</span>
  JMSRedelivered<span style="color: #339933;">:</span>  <span style="color: #000066; font-weight: bold;">false</span>
  JMS_IBM_PutDate<span style="color: #339933;">:</span> <span style="color: #cc66cc;">20080123</span>
  JMSXAppID<span style="color: #339933;">:</span>       Websphere MQ Client <span style="color: #000000; font-weight: bold;">for</span> Java
  JMS_IBM_Format<span style="color: #339933;">:</span>  MQSTR   
  JMS_IBM_PutApplType<span style="color: #339933;">:</span><span style="color: #cc66cc;">28</span>
  JMS_IBM_MsgType<span style="color: #339933;">:</span> <span style="color: #cc66cc;">8</span>
  JMSXUserID<span style="color: #339933;">:</span>      mqm         
  JMS_IBM_PutTime<span style="color: #339933;">:</span> <span style="color: #cc66cc;">16392943</span>
  JMSXDeliveryCount<span style="color: #339933;">:</span><span style="color: #cc66cc;">1</span></pre></div></div>

</td>
</tr>
</table>
<p>Header fields are discussed below.</p>
<table class="default">
<tr>
<td>
<pre>Header field</pre>
</td>
<td>
Description
</td>
<td>Set by</td>
</tr>
<tr>
<td>
<pre>JMSDestination</pre>
</td>
<td>
This field contains the destination to where the message is being sent.
</td>
<td>Send Method</td>
</tr>
<tr>
<td>
<pre>JMSDeliveryMode</pre>
</td>
<td>
JMS supports two message delivery modes.</p>
<ol>
<li>NON_PERSISTENT mode</li>
<p> In this mode, the JMS container does not persist the message. A JMS provider failure can cause a NON_PERSISTENT message to be lost. A JMS provider will deliver these types of messages <i>at most once</i>. The provider may lose the message but it must not deliver it twice.</p>
<li>PERSISTENT mode</li>
<p> In this mode, the JMS container insures that a message will be delivered to the client. A failure within JMS container will not cause the message to be lost. In this mode the messages will be delivered <i>once and only once</i>.
</ol>
</td>
<td>Send Method</td>
</tr>
<tr>
<td>
<pre>JMSMessageID</pre>
</td>
<td>
Each message in a JMS container is assigned a unique ID. This field is used to identify a specific message. All IDs begin with <b>ID:</b>.
</td>
<td>Send Method</td>
</tr>
<tr>
<td>
<pre>JMSTimestamp</pre>
</td>
<td>
This field contains the time a message was handed off to a provider to be sent. It is in the format of a normal Java millis time value.
</td>
<td>Send Method</td>
</tr>
<tr>
<td>
<pre>JMSCorrelationID</pre>
</td>
<td>
This field can use to link one message with another. As an example, a response message can be linked with a request message by populating this field with request message&#8217;s <i>JMSMessageID</i>. ID can be a provider specific message ID or spplication specific string or an array of bytes (<code>byte[]</code>).
</td>
<td>Client</td>
</tr>
<tr>
<td>
<pre>JMSReplyTo</pre>
</td>
<td>
The client populates this field to denote where a reply message has to be sent.Messages sent with a <i>JMSReplyTo</i> value are typically expecting a response although a response is not madatory.
</td>
<td>Client</td>
</tr>
<tr>
<td>
<pre>JMSRedelivered</pre>
</td>
<td>
If the field is set to true, it is an indication to the consuming application that the message may have been delivered in the past and that the application should take extra precautions to prevent duplicate processing.
</td>
<td>Provider</td>
</tr>
<tr>
<td>
<pre>JMSType</pre>
</td>
<td>
Clients can classify messages and set this field to denote that this message belongs to a specific category. For e.g., a call center system can label messages as &#8216;Tech Support&#8217; or &#8216;Sales&#8217; etc. This field can be used with selectors described later.
</td>
<td>Client</td>
</tr>
<tr>
<td>
<pre>JMSExpiration</pre>
</td>
<td>
This denotes the expiration time of a message. The expiration time is calculated as sum of this value and the current GMT value. Expired messages are destroyed. If this is set to 0, the message never expires.
</td>
<td>Send Method</td>
</tr>
<tr>
<td>
<pre>JMSPriority</pre>
</td>
<td>
JMS defines ten priority levels. Levels 0-4 are considered <i>normal</i> and levels 5-9 are <i>expedited</i>. Generally high priority messages are delivered ahead of lower priority messages but this behavior is vendor specific.
</td>
<td>Send Method</td>
</tr>
</table>
<p>In addition to these properties, a client can set and get additional properties via <code>setXXXProperty()</code> and <code>getXXXProperty()</code> methods. JMS reserves <b>JMSX</b> property name prefix for JMS defined properties. Most of these JMSX properties are dependant on a JMS provider. </p>
<p>JMS provides five forms of message body. All messages extend <a href="http://java.sun.com/products/jms/javadoc-102a/javax/jms/Message.html" target="_blank">Message</a> interface.</p>
<ol>
<li><b>StreamMessage</b> This message is composed of Java primitive values. It is written and read sequentially</li>
<li><b>MapMessage</b> This message contains a set of key-value pairs where keys are Strings and values are Java primitive types</li>
<li><b>TextMessage</b> This is the commonly used message form. This message body contains a <i>java.lang.String</i>. For e.g., clients and exchange XML data using this type.</li>
<li><b>ObjectMessage</b> This message allows for transfer of a Serializable Java object.</li>
<li><b>BytesMessage</b> This message is composed of bytes.</li>
</ol>
<p>The difference between StreamMessage and BytesMessage is that StreamMessage preserves the type information of Java primitive types whereas BytesMessage does not. </p>
]]></content:encoded>
			<wfw:commentRss>http://www.kandysoftwareinc.com/tech-articles/jms-internals/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

