# springboot-plugins **Repository Path**: aiowang/springboot-plugins ## Basic Information - **Project Name**: springboot-plugins - **Description**: 自研springboot插件集 - **Primary Language**: Java - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 2 - **Created**: 2020-03-21 - **Last Updated**: 2021-11-04 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # springboot-plugins ## 介绍 自己开发的一些springboot插件集,学海无涯苦做舟! ## 插件说明 ### 多ActiveMQ链接客户端插件 #### 简介 - dynamic-activemq 可以连接多个activemq;提供DynamicActiveMQTransportListener接口,监听服务链接,断开事件。 - dynamic-activemq-example 插件dynamic-activemq的示例使用说明 #### 使用说明 依赖引入 ```xml com.github.aiowang springboot-plugins-dynamic-activemq 0.0.1-release ``` 配置说明 ```properties # 配置 # 指定主MQ,必填 spring.activemq.dynamic.primary=custom # 需使用failover,才能监听链接断开事件 spring.activemq.dynamic.custom.brokerUrl=failover:(tcp://localhost:61616)?timeout=3000 # 客户端前缀 spring.activemq.dynamic.custom.clientIDPrefix=customActivemq1 # 消息订阅或发送时,需指定消息链接的工厂名 spring.activemq.dynamic.custom.topic-factory=customTopic spring.activemq.dynamic.custom.queue-factory=customQueue # 用户名 #spring.activemq.dynamic.custom.user: user # 密码 #spring.activemq.dynamic.custom.password: password spring.activemq.dynamic.pro.brokerUrl=failover:(tcp://localhost:61616)?timeout=3000 spring.activemq.dynamic.pro.clientIDPrefix=customActivemq2 spring.activemq.dynamic.pro.single=true spring.activemq.dynamic.pro.topic-factory=proTopic spring.activemq.dynamic.pro.queue-factory=proQueue spring.activemq.pool.enabled=true spring.activemq.pool.max-connections=100 spring.activemq.send-timeout=3000 ``` 示例 ```java import com.aiowang.springboot.plugins.dynamic.activemq.utils.DynamicActiveMQUtils; import org.apache.activemq.Message; import org.springframework.jms.annotation.JmsListener; import org.springframework.stereotype.Component; import javax.jms.JMSException; @Component class ActiveMQClient { /** * 订阅消息,containerFactory的值为配置文件中spring.activemq.dynamic.xxx.topic-factory的值 * * @param msg 接收消息内容,需要使用DynamicActiveMQUtils.getTextMessag格式化消息 * @throws JMSException 异常 * @throws Exception 异常 */ @JmsListener(destination = "Test.CustomActiveMq.topic", containerFactory = "customTopic") public void customActiveMqClientTopic1(final Message msg) throws JMSException, Exception{ System.out.println("customActiveMqClientTopic1:customTopic---Test.CustomActiveMq.topic消息:" + DynamicActiveMQUtils.getTextMessage(msg)); DynamicActiveMQUtils.sendQueue("Test.CustomActiveMq.queue", DynamicActiveMQUtils.getTextMessage(msg)); } /** * 订阅消息,containerFactory的值为配置文件中spring.activemq.dynamic.xxx.queue-factory的值 * * @param msg 接收消息内容,需要使用DynamicActiveMQUtils.getTextMessag格式化消息 * @throws JMSException 异常 * @throws Exception 异常 */ @JmsListener(destination = "Test.CustomActiveMq.queue", containerFactory = "customQueue") public void customActiveMqClientQueue1(final Message msg) throws JMSException, Exception{ System.out.printf("customActiveMqClientQueue1: customQueue---Test.CustomActiveMq.queue消息:%s。", DynamicActiveMQUtils.getTextMessage(msg)); } /** * 订阅消息,containerFactory的值为配置文件中spring.activemq.dynamic.xxx.topic-factory的值 * * @param msg 接收消息内容,需要使用DynamicActiveMQUtils.getTextMessag格式化消息 * @throws JMSException 异常 * @throws Exception 异常 */ @JmsListener(destination = "Test.ProActiveMq.topic", containerFactory = "proTopic") public void proActiveMqClientTopic1(final Message msg) throws JMSException, Exception{ System.out.printf("proActiveMqClientTopic1: proTopic---Test.ProActiveMq.topic消息:%s。", DynamicActiveMQUtils.getTextMessage(msg)); } /** * 订阅消息,containerFactory的值为配置文件中spring.activemq.dynamic.xxx.queue-factory的值 * * @param msg 接收消息内容,需要使用DynamicActiveMQUtils.getTextMessag格式化消息 * @throws JMSException 异常 * @throws Exception 异常 */ @JmsListener(destination = "Test.ProActiveMq.queue", containerFactory = "proQueue") public void proActiveMqClientQueue1(final Message msg) throws JMSException, Exception{ System.out.printf("proActiveMqClientQueue1: proQueue---Test.ProActiveMq.queue消息:%s。", DynamicActiveMQUtils.getTextMessage(msg)); } } ``` #### 备注 可参考示例