JMS, the Java Messaging Service, is a elaborated queueing system.
Clients add messages to the queues and servers remove the messages.
Resin-EJB's EJB message-bean implementation can use any
JMS implementation which conforms to the specifications. Resin-EJB
also includes a basic memory-based JMS
implementation.
| Servers: Message-Driven Beans |
The message-driven bean server processes messages as they become
available. The Resin-EJB server calls the bean's onMessage()
method with each new message.
package test;
import javax.ejb.*;
import javax.jms.*;
public class TestBean implements MessageDrivenBean, MessageListener {
...
public void onMessage(Message msg)
{
// process the message
}
}
|
The server needs to have configure both a ConnectionFactory and a
Destination. Destinations are either Queue or Topic objects and
ConnectionFactories are either
QueueConnectionFactory or TopicConnectionFactory.
Like other JNDI resources, JMS objects are configured
with resource-ref directives. The init-param values configure
bean properties of those objects.
<caucho.com>
<http-server>
<resource-ref res-ref-name="jms/queue-connection-factory"
res-type='com.caucho.jms.JVMQueueConnectionFactory'/>
<resource-ref res-ref-name="jms/queue"
res-type='com.caucho.jms.memory.MemoryQueue'/>
...
</http-server>
</caucho.com>
|
The following are the factories for Resin-EJB's JMS objects:
| Class | Description
|
| com.caucho.jms.JVMQueueConnectionFactory | The connection factory for queues.
|
| com.caucho.jms.memory.MemoryQueue | A memory-based queue.
|
| com.caucho.jms.JVMTopicConnectionFactory | The connection factory for topics.
|
| com.caucho.jms.memory.MemoryTopic | A memory-based topic.
|
The client creates messages and sends them to a destination. A client
needs to:
- Lookup the Destination and ConnectionFactory with JNDI
- Create a Sender (or Publisher for Topics)
- Create a message
- Send the message
import javax.naming.*;
import javax.jms.*;
// look up the objects.
Context env = (Context) new InitialContext().lookup("java:comp/env");
Queue queue = (Queue) env.lookup("jms/queue");
QueueConnectionFactory factory;
factory =
(QueueConnectionFactory) env.lookup("jms/queue-connection-factory");
QueueConnection connection = factory.createQueueConnection();
QueueSession jmsSession = connection.createQueueSession(false, 0);
QueueSender sender = jmsSession.createSender(queue);
// create the message
Message message = jmsSession.createTextMessage("hello, world");
// send the message
sender.send(message);
|
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark,
and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc. | ![]() |
|