Jetty has moved!
Jetty is a project at the Eclipse Foundation.
Homepage:http://www.eclipse.org/jetty
Downloads: http://download.eclipse.org/jetty/
Documentation:http://www.eclipse.org/jetty/documentation/current/
About:http://www.eclipse.org/jetty/about.php
Jetty Powered:http://www.eclipse.org/jetty/powered/
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Integrating with ActiveMQ

For using ActiveMQ queues and topics with Jetty, you have two choices:

  1. Use queues and topics directly from javascript on the client browser (Ajax)
  2. Traditional server-side jms api calls

ActiveMQ with Ajax and Jetty

Due to some clever integration, you can use queues and topics directly in your client side javascript very easily and simply.

Here's an example of sending a message to a queue:

Here's an example of setting up to receive messages from a queue. All you need do is to add a listener with a unique id, the name of the queue or topic from which you want to receive messages, and the name of a function which will be called back when a message is available.

Here's the plumbing you need to take advantage of this very convenient feature:

  1. Include these lines in your html:
    <script type="text/javascript" src="amq/amq.js"></script>
    <script type="text/javascript">amq.uri='amq';</script>
  1. Include thse lines in your web.xml, changing the url of the broker as appropriate for your installation:
    <context-param>
        <param-name>org.apache.activemq.brokerURL</param-name>
        <param-value>vm://localhost</param-value>
        <description>The URL of the Message Broker to connect to</description>
    </context-param>

    <context-param>
        <param-name>org.apache.activemq.embeddedBroker</param-name>
        <param-value>true</param-value>
        <description>Whether we should include an embedded broker or not</description>
    </context-param>

    <servlet>
      <servlet-name>AjaxServlet</servlet-name>
      <servlet-class>org.apache.activemq.web.AjaxServlet</servlet-class>
      <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>AjaxServlet</servlet-name>
        <url-pattern>/amq/*</url-pattern>
    </servlet-mapping>

    <filter>
      <filter-name>session</filter-name>
      <filter-class>org.apache.activemq.web.SessionFilter</filter-class>
    </filter>

    <filter-mapping>
      <filter-name>session</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>

  1. Include the activemq-web.jar and all of its dependencies in your webapp, or alternatively, copy them to the $JETTY-HOME/lib/ext directory if you want them to be available for all of your webapps. Here's a maven2 dependency clause that you might find useful:
    <dependency>
      <groupId>incubator-activemq</groupId>
      <artifactId>activemq-web</artifactId>
      <exclusions>
        <exclusion>
          <artifactId>commons-logging</artifactId>
          <groupId>commons-logging</groupId>
        </exclusion>
        <exclusion>
          <artifactId>org.mortbay.jetty</artifactId>
          <groupId>jetty-util</groupId>
        </exclusion>
        <exclusion>
          <artifactId>mx4j</artifactId>
          <groupId>mx4j</groupId>
        </exclusion>
      </exclusions>
    </dependency>

You will also need to make sure that jcl104-over-slf4j-1.0.1.jar and an slf4j log implementation jar are available at runtime, as ActiveMQ uses commons logging. You can move these jars out of $JETTY-HOME/lib/jsp-2.0 and into $JETTY-HOME/lib to make them generally available on the classpath.

This ActiveMQ Ajax mechanism is based on Jetty's Continuations mechanism and thus in fact works most efficiently when deployed on Jetty, however the same webapp will also run unaltered on other containers.

There is more information on available on ActiveMQ in general and the Ajax mechanism in particular.

  • No labels
Contact the core Jetty developers at www.webtide.com
private support for your internal/customer projects ... custom extensions and distributions ... versioned snapshots for indefinite support ... scalability guidance for your apps and Ajax/Comet projects ... development services from 1 day to full product delivery