OpenJMS
Resin 3.0

Features
Installation
Configuration
Web Applications
IOC/AOP
Resources
JSP
Quercus
Servlets and Filters
Databases
Admin (JMX)
CMP
EJB
Amber
EJB 3.0
Security
XML and XSLT
XTP
JMS
Performance
Protocols
Third-party
Troubleshooting/FAQ

IDE's
Scottit
Groovy
PHP
Code Libraries
JMS
JCA Resources
JMX
SSL Accelerators

SwiftMQ
OpenJMS
SwiftMQ
JMS
JCA Resources

OpenJMS

The OpenJMS client is configured by adding a jndi-link to the web.xml or resin.conf.

web.xml
<web-app xmlns="http://caucho.com/ns/resin">
  <jndi-link jndi-name="jms"
             factory="org.exolab.jms.jndi.InitialContextFactory">
    <init-param java.naming.provider.url="tcp://localhost:3035"/>
  </jndi-link>
</web-app>

The OpenSSL server will need to be started as a separate process.

OpenJMS can also be embedded in Resin. Because OpenJMS does not yet support JCA, it does not understand server restarts. Therefore, it needs to be placed in the resin.conf, not the web.xml.

resin.conf
<resin xmlns="http://caucho.com/ns/resin">
  <server>
    <system-property openjms.home="/usr/local/src/openjms-0.7.6-rc3"/>
    <resource type="org.exolab.jms.server.EmbeddedJmsServer">
      <arg>/usr/local/resin/jms/openjms.xml</arg>
    </resource>

    <jndi-link jndi-name="jms"
               factory="org.exolab.jms.jndi.InitialContextFactory">
      <init-param java.naming.provider.url="embedded"/>
    </jndi-link>

    ...
</resin>

A sample servlet using the above OpenSSL configuration sends a text message to the queue.

SendServlet.java
package qa;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.naming.*;
import javax.jms.*;

public class SendServlet extends HttpServlet {
  private QueueConnectionFactory _queueFactory;
  private Queue _queue;

  public void init()
    throws ServletException
  {
    try {
      Context ic = new InitialContext();
      Context jms = (Context) ic.lookup("java:comp/env/jms");

      _queueFactory = (QueueConnectionFactory)
        jms.lookup("JmsQueueConnectionFactory");

      _queue = (Queue) jms.lookup("queue1");
    } catch (Exception e) {
      throw new ServletException(e);
    }
  }

  public void service(HttpServletRequest req,
                      HttpServletResponse res)
    throws IOException, ServletException
  {
    PrintWriter out = res.getWriter();

    QueueConnection conn = null;

    try {
      conn = queueFactory.createQueueConnection();
      QueueSession queueSession =
         conn.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
      QueueSender queueSender = queueSession.createSender(queue);
      TextMessage message = queueSession.createTextMessage();

      message.setText("Test message");

      out.println("Sending message: " + message.getText());
      queueSender.send(message);
    } catch (Exception e) {
      throw new ServletException(e);
    } finally {
      try {
        conn.close();
      } catch (Exception e) {
      }
    }
  }
}


SwiftMQ
JMS
JCA Resources
Copyright © 1998-2006 Caucho Technology, Inc. All rights reserved.
Resin® is a registered trademark, and HardCoretm and Quercustm are trademarks of Caucho Technology, Inc.