使用Spring Boot配置ActiveMQ

12
我在Spring Boot中使用ActiveMQ作为嵌入式, ActiveMQConnectionFactory 创建 Broker。我理解配置 Broker 的方法是在查询中设置参数,如此处所述: http://activemq.apache.org/how-do-i-embed-a-broker-inside-a-connection.html 我想设置有关DLQ的一些功能,因此它在destinationPolicy属性中,但该属性类型不是简单类型而是复杂类型,我该如何编写查询参数来禁用DLQ?
3个回答

4

补充@Petter和@April的回答,以下是同样的解决方案,但提供了更完整的示例:

1. Petter的解决方案,将activemq.xml导入到连接工厂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

4月份解决方案,将activemq.xml导入Spring配置文件中

只需删除application.properties,然后在Config.java中添加@ImportResource("classpath:activemq.xml")即可。

Config.java

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

3
很好的问题。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。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接