activemq-artemis/docs/user-manual/en/spring-integration.xml

93 lines
5.0 KiB
XML

<?xml version="1.0" encoding="UTF-8"?>
<!-- <!DOCTYPE book PUBLIC "-//OASIS//DTD DocBook XML V4.3CR3//EN"
"../../../lib/docbook-support/support/docbook-dtd/docbookx.dtd"> -->
<!-- ============================================================================= -->
<!-- Licensed to the Apache Software Foundation (ASF) under one or more -->
<!-- contributor license agreements. See the NOTICE file distributed with -->
<!-- this work for additional information regarding copyright ownership. -->
<!-- The ASF licenses this file to You under the Apache License, Version 2.0 -->
<!-- (the "License"); you may not use this file except in compliance with -->
<!-- the License. You may obtain a copy of the License at -->
<!-- -->
<!-- http://www.apache.org/licenses/LICENSE-2.0 -->
<!-- -->
<!-- Unless required by applicable law or agreed to in writing, software -->
<!-- distributed under the License is distributed on an "AS IS" BASIS, -->
<!-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -->
<!-- See the License for the specific language governing permissions and -->
<!-- limitations under the License. -->
<!-- ============================================================================= -->
<!DOCTYPE chapter PUBLIC "-//OASIS//DTD DocBook XML V4.5//EN" "http://www.oasis-open.org/docbook/xml/4.5/docbookx.dtd" [
<!ENTITY % BOOK_ENTITIES SYSTEM "ActiveMQ_User_Manual.ent">
%BOOK_ENTITIES;
]>
<chapter id="spring.integration">
<title>Spring Integration</title>
<para>ActiveMQ provides a simple bootstrap class,
<literal>org.apache.activemq.integration.spring.SpringJmsBootstrap</literal>, for
integration with Spring. To use it, you configure ActiveMQ as you always
would, through its various configuration files like
<literal>activemq-configuration.xml</literal>,
<literal>activemq-jms.xml</literal>, and
<literal>activemq-users.xml</literal>. The Spring helper class starts the
ActiveMQ server and adds any factories or destinations configured within
<literal>activemq-jms.xml</literal> directly into the namespace of the Spring
context. Let's take this <literal>activemq-jms.xml</literal> file for
instance: </para>
<programlisting>
&lt;configuration xmlns="urn:activemq"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="urn:activemq /schema/activemq-jms.xsd">
&lt;!--the connection factory used by the example-->
&lt;connection-factory name="ConnectionFactory">
&lt;connectors>
&lt;connector-ref connector-name="in-vm"/>
&lt;/connectors>
&lt;entries>
&lt;entry name="ConnectionFactory"/>
&lt;/entries>
&lt;/connection-factory>
&lt;!--the queue used by the example-->
&lt;queue name="exampleQueue">
&lt;entry name="/queue/exampleQueue"/>
&lt;/queue>
&lt;/configuration></programlisting>
<para>Here we've specified a
<literal>javax.jms.ConnectionFactory</literal> we want bound to a
<literal>ConnectionFactory</literal> entry as well as a queue destination
bound to a <literal>/queue/exampleQueue</literal> entry. Using the
<literal>SpringJmsBootStrap</literal> bean will automatically populate the
Spring context with references to those beans so that you can use them.
Below is an example Spring JMS bean file taking advantage of this
feature:</para>
<programlisting>
&lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
&lt;bean id="EmbeddedJms" class="org.apache.activemq.integration.spring.SpringJmsBootstrap" init-method="start"/>
&lt;bean id="listener" class="org.apache.activemq.tests.integration.spring.ExampleListener"/>
&lt;bean id="listenerContainer" class="org.springframework.jms.listener.DefaultMessageListenerContainer">
&lt;property name="connectionFactory" ref="ConnectionFactory"/>
&lt;property name="destination" ref="/queue/exampleQueue"/>
&lt;property name="messageListener" ref="listener"/>
&lt;/bean>
&lt;/beans></programlisting>
<para>As you can see, the
<literal>listenerContainer</literal> bean references the components defined
in the <literal>activemq-jms.xml</literal> file. The
<literal>SpringJmsBootstrap</literal> class extends the EmbeddedJMS class
talked about in <xref
linkend="simple.embedded.jms" /> and the same defaults and
configuration options apply. Also notice that an
<literal>init-method</literal> must be declared with a start value so that
the bean's lifecycle is executed. See the javadocs for more details on other
properties of the bean class.</para>
</chapter>