【发布时间】:2021-05-30 04:02:35
【问题描述】:
在 Spring Boot 应用程序中,我使用嵌入式 ActiveMQ 代理。
我可以配置它:
但某些属性只能通过activemq.xml configuration file 获得。
如何使用 Spring 嵌入式 ActiveMQ 代理指定自定义 activemq.xml?
【问题讨论】:
标签: spring spring-boot configuration jms activemq
在 Spring Boot 应用程序中,我使用嵌入式 ActiveMQ 代理。
我可以配置它:
但某些属性只能通过activemq.xml configuration file 获得。
如何使用 Spring 嵌入式 ActiveMQ 代理指定自定义 activemq.xml?
【问题讨论】:
标签: spring spring-boot configuration jms activemq
您可以在您的类路径上定义自定义 ActiveMQ 配置并加载它:
@Profile("embedded-activemq")
@ImportResource("classpath:embedded-activemq.xml")
@Configuration
public class EmbeddedActiveMQConfig {
}
ActiveMQ 需要 Spring NamespaceHandler(spring-boot-starter-activemq 中不存在):
<dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
</dependency>
然后,您可以使用与您的 ActiveMQ 版本对应的官方activemq.xml 并使其适应 Spring 嵌入式上下文,例如:
<!--
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.
-->
<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.xsd
http://activemq.apache.org/schema/core
http://activemq.apache.org/schema/core/activemq-core-5.15.13.xsd
">
<!--
The <broker> element is used to configure the ActiveMQ broker.
-->
<broker xmlns="http://activemq.apache.org/schema/core"
brokerName="localhost"
persistent="false"
useJmx="false"
enableStatistics="false">
<destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" >
<!-- The constantPendingMessageLimitStrategy is used to prevent
slow topic consumers to block producers and affect other consumers
by limiting the number of messages that are retained
For more information, see:
http://activemq.apache.org/slow-consumer-handling.html
-->
<pendingMessageLimitStrategy>
<constantPendingMessageLimitStrategy limit="1000"/>
</pendingMessageLimitStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy>
<!--
The systemUsage controls the maximum amount of space the broker will
use before disabling caching and/or slowing down producers. For more information, see:
http://activemq.apache.org/producer-flow-control.html
-->
<systemUsage>
<systemUsage>
<memoryUsage>
<memoryUsage percentOfJvmHeap="70"/>
</memoryUsage>
<storeUsage>
<storeUsage limit="100 gb"/>
</storeUsage>
<tempUsage>
<tempUsage limit="1 gb"/>
</tempUsage>
</systemUsage>
</systemUsage>
<!-- destroy the spring context on shutdown -->
<shutdownHooks>
<bean xmlns="http://www.springframework.org/schema/beans" class="org.apache.activemq.hooks.SpringContextHook" />
</shutdownHooks>
</broker>
</beans>
【讨论】: