20 September, 2010

How create message queue using Spring 2.5.x and Oracle Weblogic Server 11g

Last week I spent some time on configuring JMS Message Queue using Spring 2.5.4 and Oracle Weblogic Server 11g R2.

Following are the step by step instructions to create queue.

1) Log into http://localhost:7001/console, supply weblogic/weblogic (default)
2) Create JMS Server using Oracle Weblogic Server. I used JDBC persistent store - MySQL based, to store the messages under db.
3) Name your jms queue and factory and let these refer to your newly created jms server which points to JDBC persistent store.

4) Now configure your spring jms file; which looks something like this:
































5) Create message listener class; which is influenced by traditional mdbs (J2EE 1.3 era..)

package amp;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;

public class MyQueueListener implements MessageListener
{

public void onMessage(Message message)
{
if (message instanceof TextMessage)
{
try
{
String txtMessage = ((TextMessage) message).getText();
System.out.println("" + txtMessage + "");
}
catch (JMSException ex)
{
throw new RuntimeException(ex);
}
}
else
{
throw new IllegalArgumentException(
"Message must be of type TextMessage");
}
}
}

7) Create client class whcih produces huge message payloads; just to test

package amp;

import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;

import org.springframework.context.ApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;

public class QueueClient
{
private ApplicationContext ctx = AppContext.getApplicationContext();
private JmsTemplate jt = (JmsTemplate) ctx.getBean("jmsTemplate");
private Queue q = (Queue) ctx.getBean("jdbcQ");

public void sendMessage(final String m) throws Exception
{
jt.send(q, new MessageCreator()// inner class
{
public Message createMessage(Session session)
throws JMSException
{
TextMessage tm = session.createTextMessage();
tm.setText(m);
return tm;
}
});
//System.out.println("message sent to destination called "+q.getQueueName());
}
}

8) Finally call this class under web environment; to see the message output. I used OEPE pack to conduct these tests.

Hope this helps to configure message queues.

03 September, 2010

Care for simple architecture

We J2EE architects must care for simple architecture; few things might help do develop application which are long lasting and easy to accommodate future requirements.

For example; I tried with followings
1) Care for OO rather than standards/specifications
2) Create architecture against requirements in hand rather than technology specific
3) Do not distribute objects if requirements are not called for
4) Follow good architecture and design principles rather than just following patterns
5) Leverage on lightweight architecture like Spring centric which greatly helps in interface driven programming, container level capabilities, test strategies
6) Follow thought full analysis of business requirements and come up with list of high level components, its responsibilities and associated rationale
7) Follow whiteboard driven architectures to kick start the discussion
Care for executable architecture (RUP), spike resolution (XP) and vertical slicing to get confidence in the architecture
8) Come up with list of development standards, guidelines and implementation classes

One new learning / day - however small it is

Read a blog / or article Watch TED talk  Read a small self-help book (many free eBooks available with less than 100 pages/can be completed i...