Java 使用Spring引导的ActiveMQ配置
我使用ActiveMQ作为Spring Boot的嵌入式组件。 代理似乎是通过ActiveMQConnectionFactory创建的。 我知道配置代理的方法是使用代理在查询中设置参数。如下所述:Java 使用Spring引导的ActiveMQ配置,java,spring-boot,activemq,Java,Spring Boot,Activemq,我使用ActiveMQ作为Spring Boot的嵌入式组件。 代理似乎是通过ActiveMQConnectionFactory创建的。 我知道配置代理的方法是使用代理在查询中设置参数。如下所述: 我想设置一些有关DLQ的功能,因此它位于destinationPolicy属性中,但属性类型不是简单类型而是复杂类型,我如何编写查询参数以禁用DLQ,请?好问题。用于自动代理创建的vm传输上的属性非常好,但我认为您已经达到了一定程度 我的建议是,像通常在XML中那样定义代理配置,然后在URI中引用此X
我想设置一些有关DLQ的功能,因此它位于destinationPolicy属性中,但属性类型不是简单类型而是复杂类型,我如何编写查询参数以禁用DLQ,请?好问题。用于自动代理创建的vm传输上的属性非常好,但我认为您已经达到了一定程度 我的建议是,像通常在XML中那样定义代理配置,然后在URI中引用此XML。目标策略确实是一个复杂的结构,即使可能,我也不认为用简单的查询参数来定义它们是一个好主意
vm://localhost?brokerConfig=xbean:activemq.xml
我遇到了这个问题,并通过使用spring配置文件解决了它。在我的例子中,我想将我的代理配置为持久化 我在pom中添加了所需的lib:包括activemq代理、activemq-spring、springjms(在我的例子中还有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>
成功了
我首先尝试了xbeans解决方案,但我被卡住了,因为我错过了一些xbeans类,我不知道这是版本问题还是什么。我正在使用activemq 5.12.1补充@Petter和@April answers,下面是相同的解决方案,但有更完整的示例: 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>
应用程序属性
spring.activemq.broker-url=vm://broker1?brokerConfig=xbean:activemq.xml
只需删除application.properties
,然后将@ImportResource(“classpath:activemq.xml”)
条目添加到Config.java
@EnableJms
@SpringBootApplication
@EnableAutoConfiguration
@Configuration
public class Config {}
@EnableJms
@SpringBootApplication
@EnableAutoConfiguration
@Configuration
@ImportResource("classpath:activemq.xml")
public class Config {}
Config.java
@EnableJms
@SpringBootApplication
@EnableAutoConfiguration
@Configuration
public class Config {}
@EnableJms
@SpringBootApplication
@EnableAutoConfiguration
@Configuration
@ImportResource("classpath:activemq.xml")
public class Config {}