<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
   <title>Brett Lomas&apos; Blog</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/BrettLomas/" />
   <link rel="self" type="application/atom+xml" href="http://blogs.oracle.com/BrettLomas/xml/rss.xml" />
   <id>tag:blogs.oracle.com,2009:/BrettLomas//737</id>
   <updated>2009-02-12T13:44:23Z</updated>
   
   <generator uri="http://www.sixapart.com/movabletype/">Movable Type Enterprise 1.52-en-voltron-r47459-20070213</generator>

<entry>
   <title>Clustered Clients and JMS Distributed Destinations</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/BrettLomas/2009/02/clustered_clients_and_jms_dist_1.html" />
   <id>tag:blogs.oracle.com,2009:/BrettLomas//737.10121</id>
   
   <published>2009-02-12T13:36:39Z</published>
   <updated>2009-02-12T13:44:23Z</updated>
   
   <summary>Recently a customer asked me about a JMS problem they&apos;ve been experiencing when using Uniform Distributed Topics (UDT). I explain the problem below but essentially the application consuming the JMS messages was itself a clustered client, and thus getting a...</summary>
   <author>
      <name>brett.lomas</name>
      
   </author>
         <category term="JMS" scheme="http://www.sixapart.com/ns/types#category" />
         <category term="WebLogic Server" scheme="http://www.sixapart.com/ns/types#category" />
   
   <category term="jms" label="JMS" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="weblogicserver" label="WebLogic Server" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/BrettLomas/">
      <![CDATA[<p>Recently a customer asked me about a JMS problem they've been experiencing when using Uniform Distributed Topics (UDT). I explain the problem below but essentially the application consuming the JMS messages was itself a clustered client, and thus getting a message per instance of the application across the cluster.</p>

<p><strong>The Problem</strong><br />
The problem was they have a number of applications deployed to a cluster as clients consuming from the distributed topic. <em>Each </em> instance of the application is treated as a consumer and thus getting multiple message instead of the desired one per application across the cluster. Now don't get me wrong, the customer was not complaining that JMS or distributed queues needed to be changed, but how could they get the functionality they wanted while still enjoying the higher availability and scalability a UDT afforded them. One thing to note is if the operations being performed on the messages were idempotent this wouldn't have been as serious even though it was processed multiple times, the result would have been the same (albeit a little ugly!).</p>

<p>The image below describes the situation the customer was trying to solve.<br />
<img alt="JMSArchitecture%20-%20current.jpg" src="http://blogs.oracle.com/BrettLomas/JMSArchitecture%20-%20current.jpg" width="360" height="211" /></p>

<p><strong>The Target</strong><br />
The goal was to have a messaging system to the guarantee delivery while also being resilient. Each application, whilst deployed across the cluster should only get one message.</p>

<p><img alt="JMSArchitecture-desired.jpg" src="http://blogs.oracle.com/BrettLomas/JMSArchitecture-desired.jpg" width="360" height="211" /><br />
This diagram shows the proposed messaging architecture.<br />
A message coming into the Uniform Distributed Destination (UDD) is sent, in some load balancing fashion, to only one instance of the application. The load balancing might be multiplexed across application or across cluster nodes and then across the instances of the application on that node.</p>

<p><br />
<strong>Proposed Solution</strong></p>

<p>The main problem with the current architecture is the UDT which is directly handling the incoming the messages and from which the applications are directly subscribing to. This naturally broadcasts the messages across all members indiscriminately, irrespective of application.</p>

<p>The UDT can be replaced with a UDQ to which external messages are published. The UDQ will load balance these incoming messages to one and only one of the managed servers. A local Message-driven Bean deployed to the cluster can listen on the UDQ (an instance of which will be deployed to each of the managed servers). Its sole job is to publish to a local-only JMS Topic to which the applications are listening. This is shown logically below.<br />
<img alt="JMSArchitecture%20-%20proposed.jpg" src="http://blogs.oracle.com/BrettLomas/JMSArchitecture%20-%20proposed.jpg" width="360" height="349" /></p>

<p>It is important the MDB is transactional, to ensure it succeeds in putting the message into the local topic, or on failure the transaction is rolled back and thus the message is ready for another attempt. The local Topic must have a unique name and no global JNDI name. Instead a local JNDI name is provided which is the same across the cluster (and thus the MDB publishes the messages to a Topic with the same same name irrespective of its location in the cluster).</p>

<p>I have prototype this solution in WebLogic Server 10gR3 using EJB 3.0 on a two node cluster, and am happy to share the project should someone be interested enough.</p>]]>
      
   </content>
</entry>
<entry>
   <title>WebLogic Server, JMS, Store-and-Forward and the C API</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/BrettLomas/2008/12/weblogic_server_jms_storeandfo.html" />
   <id>tag:blogs.oracle.com,2008:/BrettLomas//737.8950</id>
   
   <published>2008-12-04T03:41:03Z</published>
   <updated>2008-12-04T12:52:52Z</updated>
   
   <summary>I had to do some work around Store-and-Forward (SAF) using the WebLogic JMS C API for a customer recently. I found some of the C API documentation and examples have disappeared during the migration of BEA to Oracle (or perhaps...</summary>
   <author>
      <name>brett.lomas</name>
      
   </author>
   
   <category term="c" label="C" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="jms" label="JMS" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="storeandforward" label="Store-and-Forward" scheme="http://www.sixapart.com/ns/types#tag" />
   <category term="weblogicserver" label="WebLogic Server" scheme="http://www.sixapart.com/ns/types#tag" />
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/BrettLomas/">
      <![CDATA[<p>I had to do some work around Store-and-Forward (SAF) using the WebLogic JMS C API for a customer recently. I found some of the C API documentation and examples have disappeared during the migration of BEA to Oracle (or perhaps this is a reflection of my lacking search skills, or indeed my persistence with search results) so this blog details my results in the hope it might be useful to someone else.</p>

<p><strong>Assumptions</strong><br />
This blog entry assumes the following<br />
1. You have a proficiency in WebLogic Server and JMS<br />
2. You know about Java and C coding</p>

<p><strong>Notes</strong><br />
While this blog reflects work done using WebLogic Server 10gR3, it should work with all WebLogic Server version 9 and above (for SAF).</p>

<p><strong>Introduction</strong><br />
The JMS C API uses JNI to access the standard WebLogic JMS Libraries. The API follows the same flow as the Java equivalent (funnily enough) where a context is used to look up the connection factory and destination and the connection factory creates the connection etc etc.</p>

<p><strong>Setting up your Environment</strong><br />
To use the C JMS API you need to set up your environment, this blog assumes Unix/Linux but the same principles apply for Windows users.<br />
1. Set up the CLASSPATH to include, the <em>weblogic.jar</em> file (found in <WEBLOGIC-HOME>/wlserver_10.3/server/lib - the path will change depending on the version you're using) or you can use the <em>wlsjmsclient.jar</em> instead of the full jar file if you wish.<br />
2. Set up the library path so your executable knows where to find the <em>jvm</em> and <em>jni</em> shared libraries. This equates to setting the LD_LIBRARY_PATH to something like <WEBLOGIC-HOME>/wlserver_10.3/server/native/linux/i686:<WEBLOGIC-HOME>/jdk160_05/jre/lib/i386/server/.</p>

<p><strong>The C Code</strong><br />
Once you have done this you're ready to work on the code. The follow code 'skeleton' shows how to publish a message to a JMS Queue.<br />
1. Get the context using <em>JmsContextCreate</em><br />
2. Use the context to get the connection factory using <em>JmsContextCreateConnectionFactory</em> and the destination (the queue) using <em>JmsDestinationCreate</em><br />
3. Get the connection to the JMS Server using <em>JmsConnectionFactoryCreateConnection</em><br />
4. Create the session using <em>JmsConnectionCreateSession</em><br />
5. Create the producer (or consumer) using <em>JmsSessionCreateProducer</em> (or <em>check me</em>)<br />
6.Create the message (in this case a Text Message) using <em>JmsSessionTestMessageCreate</em><br />
7. Send the message using <em>JmsProducerSend</em></p>

<p>When using the C API it is critical all handles returned from the API functions are closed or destroyed correctly using the appropriate -Destroy or -Close functions, failing to do so could cause memory leaks (don't depend on GC, especially when using the C API).</p>

<p><strong>Compiling</strong><br />
When compiling you need to make sure you<br />
1. Include the WebLogic C API header files (located in <WEBLOGIC_HOME>/wlserver_10.3/server/include)<br />
2. Link the libjmsc.so, libjvm.so, and libpthread.so with your code.</p>

<p>Here is an example command (using gcc):<br />
gcc -I/usr/local/bea/WLS103/wlserver_10.3/server/include -L/usr/local/bea/WLS103/wlserver_10.3/server/native/linux/i686/ -L/usr/local/bea/WLS103/jdk160_05/jre/lib/i386/server -ljmsc -ljvm -lpthread -o JMSClient JMSClient.c</p>

<p>You could use <em>make</em> to automate a lot of this.</p>

<p><strong>Running the Binary</strong><br />
Run the binary as you would any other linux/unix binary, while making sure the library path and classpath is set correctly</p>

<p><strong>Configuring the Store-and-Forward</strong><br />
Once you have the simple producer working and publishing messages to a queue or topic you are ready to setup the SAF.</p>

<p>You need to export the SAF Context file as per the SAF documentation. Once you have done this you need to make sure you use <em>weblogic.jms.safclient.jndi.InitialContextFactoryImpl</em> as the JNDI provider (passed as a parameter to the <em>JmsContextCreate</em> function and the URI (or connection string) needs to be the location of the SAF Context you exported. Make sure you have either <em>weblogic.jar</em> or <em>wlssafclient.jar</em> in the classpath.</p>

<p>Because the SAF Sending Agent runs in a separate thread to your main thread there can be some latency between your producing the first message and it getting to the destination. This thread also means you need to make sure you don't exit the program too quickly, otherwise nothing will be sent (you keep exiting before the SAF Sending Agent can initialise)!</p>

<p><strong>Download Example</strong></p>

<p>You can download an example I have created <a href="http://blogs.oracle.com/BrettLomas/2008/12/04/JMSClient.tgz">here</a>,  this is only meant as an example and there is no warranty, use it at your own risk.</p>

<p><strong>References</strong><br />
1. WebLogic JMS C Documentation<br />
&nbsp;&nbsp;a) <a href="http://download.oracle.com/docs/cd/E12840_01/wls/docs103/jms/C_api.html">JMS C Documentation</a><br />
&nbsp;&nbsp;b) <a href="http://download.oracle.com/docs/cd/E12840_01/wls/docs103/javadocs/JmsCApi/index.html">The WebLogic Server 10gR3 JMS C API</a><br />
2. <a href="http://download.oracle.com/docs/cd/E12840_01/wls/docs103/client/saf_client.html">WebLogic Store-and-Forward Client Documentation</a></p>]]>
      
   </content>
</entry>
<entry>
   <title>Welcome!</title>
   <link rel="alternate" type="text/html" href="http://blogs.oracle.com/BrettLomas/2008/12/welcome.html" />
   <id>tag:blogs.oracle.com,2008:/BrettLomas//737.8948</id>
   
   <published>2008-12-03T09:16:08Z</published>
   <updated>2008-12-03T09:18:56Z</updated>
   
   <summary>I now have a blog! I have wandered through IT for the past 8 years and not blogged as yet. I have used Wikis, but no blogging as yet... so here goes!...</summary>
   <author>
      <name>brett.lomas</name>
      
   </author>
   
   
   <content type="html" xml:lang="en" xml:base="http://blogs.oracle.com/BrettLomas/">
      <![CDATA[<p>I now have a blog! I have wandered through IT for the past 8 years and not blogged as yet. I have used Wikis, but no blogging as yet... so here goes!</p>]]>
      
   </content>
</entry>

</feed>
