Example of Tomcat binding JMS Application Server

Source: Internet
Author: User
Tags stomp tomcat

JMS as the senior part of the Java EE has been shrouded in a veil of mystery, as the JMS Customizer Sun only prescribes the JMS specification, as many other sun products have been provided by several vendors to implement the specific. But as Tomcat and resin (announced at the beginning of this year all support the Java EE specification). These low-end but widely used servers themselves do not provide JMS support. Thankfully, OPENJMS and ACTIVEMQ two Open-source software provide plug-in support.

If you want to use JMS in a project that uses a few development frameworks like spring, although spring provides some support for JMS, after a while I've discovered that OO encapsulation has become a hindrance in the development process in some places. It's frustrating to implement code snippets such as listening, with callback (callbacks) something that is still not well fetched.

Here are some of the support for the JMS above Tomcat to do the finishing.

1. Naturally you need to download JMS implementations, such as: OPNERJMS or ActiveMQ. Download Address www.jmsopen.com or www.activeMQ.com

2. After the server download the specific configuration in the above two sites have a very detailed description, no longer enumerated.

3. And the integration of the Web server, first to configure the application of the Web.xml this file configuration is as follows:

1 <context-param>
2 <param-name>brokerURI</param-name>
3 <param-value>/WEB-INF/activemq.xml</param-value>
4 </context-param>
5
6 <listener>
7 <listener-class>org.activemq.web.SpringBrokerContextListener</listener-class>
8 </listener>

Put this piece of code in the Web.xml. Note that the Activemq.xml file is the specific configuration of the JMS server:

<?xml version= "1.0" encoding= "UTF-8"
<! DOCTYPE beans Public
"-//activemq//dtd//en"
"Http://activemq.org/dtd/activemq.dtd"
<beans>
<!--=====================
<!--ActiveMQ Broker Configuration
<!--================ =====
<broker>
<connector>
<tcpservertransport
uri= "tcp://localhost:61616" br> useasyncsend= "true"
maxoutstandingmessages=/>
</connector>
<!--to enable Stomp   Support uncomment this
<connector>
<servertransport
uri= "stomp://localhost:61626"/>
</connector>
;
<persistence>
<jdbcpersistence
datasourceref= "Oracle-ds"/
</persistence>
</broker>
<!--=======================
<!--JDBC Datasou RCE configurations
<!--=======================
<!--the DerbyDatasource
That'll be used by the Broker
<bean id= "Derby-ds" class=
"Org.apache.commons.dbcp.Ba Sicdatasource "
destroy-method=" Close "
<property name=" Driverclassname "
<value>
O    Rg.apache.derby.jdbc.EmbeddedDriver
</value>
</property>
<property name= "url"
<!--use a URL like
' jdbc:hsqldb:hsql://localhost:9001 '
If you want to connect to a remote HSQLDB-->
<value>
Jdbc:derby:derbydb;create=true
</value>
</property>
<proper Ty name= "username"
<value></value>
</property>
<property name= "password" > <value></value>
</property>
<property name= "poolpreparedstatements"
< Value>true</value>
</property>
</bean>
</beans>

At this point, you will see that the JMS server is already tied up when you start your tomcat.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.