Here's a sample spring cfg file that I've used to start an 'embedded'
ActiveMQ broker. Note how the connectionFactory bean points the embedded
broker to an external ActiveMQ broker cfg file, which I have also included
below. Within the broker cfg file you can define your transport and network
connector elements. In this example, the broker's cfg file should be in the
classpath. I am using the latest 5.1 SNAPSHOT. Hope this helps - Joe

<beans
  xmlns="http://www.springframework.org/schema/beans";
  xmlns:amq="http://activemq.org/config/1.0";
  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-2.0.xsd
  http://activemq.org/config/1.0
http://activemq.apache.org/schema/activemq-core.xsd
  http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd"; > 
 
  
  <!-- An AMQ connection factory bean that starts an embedded broker and
points the 
        broker to a broker cfg file. -->
  <bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory">
     <property name="brokerURL"
value="vm://embeddedbroker?brokerConfig=xbean:activemq_clt.xml"/>            
  </bean>
  
  <!-- Specify a destination -->
  <bean id="myDestination"
class="org.apache.activemq.command.ActiveMQQueue">
    <constructor-arg index="0" value="Q.TEST"/>        
  </bean>
  
  <!-- Wire this JMS template to the appropriate connection factory and
destination -->
  <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">    
    <property name="connectionFactory" ref="connectionFactory"/>    
    <property name="defaultDestination" ref="myDestination"/>
  </bean>
   
  <!-- This is the send bean, which we wire to the JMS template --> 
  <bean id="sendBean" class="spring.SendBean">
    <property name="jmsTemplate" ref="jmsTemplate"/>  
    <property name="destination" ref="myDestination"/>  
  </bean> 

</beans>


**** The broker's cfg file (activemq_clt.xml) ****

<beans
  xmlns="http://www.springframework.org/schema/beans";
  xmlns:amq="http://activemq.org/config/1.0";
  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-2.0.xsd
  http://activemq.org/config/1.0
http://activemq.apache.org/schema/activemq-core.xsd
  http://activemq.apache.org/camel/schema/spring
http://activemq.apache.org/camel/schema/spring/camel-spring.xsd";>

  <!-- Allows us to use system properties as variables in this configuration
file -->
  <bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer"/>
  
  <broker xmlns="http://activemq.org/config/1.0"; brokerName="embeddedbroker"
useJmx="true">
  
    <transportConnectors>
       <transportConnector name="tcp" uri="tcp://localhost:61616"/>       
    </transportConnectors>

    <networkConnectors>      
       <networkConnector name="pool" uri="static:(tcp://localhost:61617)" />
    </networkConnectors>
   
    <managementContext>
       <managementContext connectorPort="1100"
jmxDomainName="org.apache.activemq"/>
    </managementContext>
    
  </broker>  
</beans>



Michal Singer wrote:
> 
> Hi. I am trying to raise an embedded Active MQ broker using spring
> configuration file. I work with spring 2.0.6 & Active MQ 5.0.0. The only
> way that works is this:
>  <amq:broker brokerName="brokerFactory" useJmx="true" persistent="true">
>    <amq:managementContext>
>         <amq:managementContext connectorPort="1099"
> jmxDomainName="org.apache.activemq"/>
>     </amq:managementContext>
>     <amq:transportConnectors>
>       <amq:transportConnector name="openwire" uri="tcp://localhost:61616"
> />
>     </amq:transportConnectors>
>   </amq:broker>
> 
> With this way i have a few problems:
> 1. how do i define the active mq configuration file. i can't see any way?
> 2. I am trying to define: amq:networkConnectors but I get the following
> error - 
> org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was
> found starting with element 'amq:networkConnectors'. One of
> '{WC[##other:"http://activemq.org/config/1.0"]}' is expected.
> 
> I use the following namespace and according to the documentation this
> element should work:
> http://www.springframework.org/schema/beans 
> http://www.springframework.org/schema/beans/spring-beans-2.0.xsd
> http://activemq.org/config/1.0 
> http://activemq.apache.org/snapshot-schema/activemq-core-5.0-SNAPSHOT.xsd
> 
> Any help would be highly appreciated.
> Thanks
> 
> 

-- 
View this message in context: 
http://www.nabble.com/Active-MQ-broker-embedded-with-spring-configuration-problems-tp15253117s2354p15269038.html
Sent from the ActiveMQ - User mailing list archive at Nabble.com.

Reply via email to