Messaging
Resin 2.1

Reference Guide
EJB Reference Guide

EJBServer
JNDI
Entity Config
Relation Config
Session Config
Resin-EJB Config
SQL mapping
Transaction Config
Message Config
EJB-QL
xdoclet
Config Summary
Burlap
JMS
CORBA/IIOP
Index
Burlap Java
EJB Reference Guide
CORBA/IIOP

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
  }
}

JNDI Configuration

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:

ClassDescription
com.caucho.jms.JVMQueueConnectionFactoryThe connection factory for queues.
com.caucho.jms.memory.MemoryQueueA memory-based queue.
com.caucho.jms.JVMTopicConnectionFactoryThe connection factory for topics.
com.caucho.jms.memory.MemoryTopicA memory-based topic.

Clients

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);


Burlap Java
EJB Reference Guide
CORBA/IIOP
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.