【问题标题】:ActiveMQ configuration with Spring Boot使用 Spring Boot 配置 ActiveMQ
【发布时间】:2015-07-27 05:11:29
【问题描述】:

我使用 ActiveMQ 作为嵌入 Spring Boot。 似乎代理是通过 ActiveMQConnectionFactory 创建的。 我了解配置代理的方法是在使用代理的查询中设置参数。如此处所述:http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html

我想设置一些关于DLQ的功能,所以在destinationPolicy属性中,但是属性类型不是简单类型而是复杂类型,请问如何编写查询参数来禁用DLQ?

【问题讨论】:

    标签: java spring-boot activemq


    【解决方案1】:

    好问题。用于自动代理创建的 vm-transport 上的属性很棒,但只能达到我认为您已经达到的程度。

    我的建议是您像通常在 XML 中所做的那样定义代理配置,然后只需在 URI 中引用此 xml。目的地政策确实是一个复杂的结构,即使可以,我也不认为用简单的查询参数来定义它们是个好主意。

    vm://localhost?brokerConfig=xbean:activemq.xml 
    

    【讨论】:

      【解决方案2】:

      我遇到了这个问题,并通过使用 spring 配置文件解决了它。就我而言,我想将我的代理配置为持久化。

      我在我的 pom 中添加了所需的库:包括 activemq-broker、activemq-spring、spring-jms(在我的例子中是 activemq-leveldb-store)。

      我的 spring xml 文件如下所示:

      <beans
        xmlns="http://www.springframework.org/schema/beans"
        xmlns:amq="http://activemq.apache.org/schema/core"
        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.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd">
      
       <broker xmlns="http://activemq.apache.org/schema/core" brokerName="xyz">
            <persistenceAdapter>
              <levelDB directory="activemq-data"/>
            </persistenceAdapter>
      
          <transportConnectors>
            <transportConnector uri="vm:localhost?persistent=true" />
          </transportConnectors>
      
        </broker>
      </beans>
      

      我在我的一个配置类中注册了 spring 文件:

      @ImportResource("activemq-spring.xml")
      

      这样就完成了。

      我首先尝试了 xbeans 解决方案,但由于缺少一些 xbeans 类而卡住了,而且我不知道这是版本问题还是什么。我正在使用 activemq 5.12.1

      【讨论】:

        【解决方案3】:

        补充@Petter 和@April 的答案,使用相同的解决方案,但样本更完整:

        1. Petter solution, import activemq.xml at connnection factory url

        build.gradle

        ext {
            springBootVersion = "1.5.3.RELEASE"
            activeMQVersion = "5.14.5"
        }
        
        dependencies {
        
            compile("org.springframework.boot:spring-boot-starter-activemq:${springBootVersion}")
            compile("org.apache.activemq:activemq-broker:${activeMQVersion}")
        
            testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
            testCompile group: 'org.apache.activemq', name: 'activemq-spring', version: "${activeMQVersion}"
            testCompile("junit:junit:4.12")
        
        }
        

        src/main/resources/activemq.xml

        <beans xmlns="http://www.springframework.org/schema/beans"
                     xmlns:amq="http://activemq.apache.org/schema/core"
                     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.xsd
                        http://activemq.apache.org/schema/core
                        http://activemq.apache.org/schema/core/activemq-core-5.4.0.xsd
                ">
            <broker xmlns="http://activemq.apache.org/schema/core" brokerName="broker1" persistent="false" >
                <transportConnectors>
                    <transportConnector name="vm" uri="vm://broker1"/>
                </transportConnectors>
            </broker>
        </beans>
        

        Config.java

        @EnableJms
        @SpringBootApplication
        @EnableAutoConfiguration
        @Configuration
        public class Config {}
        

        application.properties

        spring.activemq.broker-url=vm://broker1?brokerConfig=xbean:activemq.xml
        

        2. April solution, import activemq.xml at Spring Configuration

        只需删除application.properties,然后将@ImportResource("classpath:activemq.xml") 条目添加到Config.java

        Config.java

        @EnableJms
        @SpringBootApplication
        @EnableAutoConfiguration
        @Configuration
        @ImportResource("classpath:activemq.xml")
        public class Config {}
        

        【讨论】:

          猜你喜欢
          • 2018-01-31
          • 1970-01-01
          • 2023-03-13
          • 2016-12-09
          • 2019-05-04
          • 1970-01-01
          • 2013-11-01
          • 2021-10-30
          • 1970-01-01
          相关资源
          最近更新 更多