# multi-source-spring-boot-starter **Repository Path**: ChildrenGreens/multi-source-spring-boot-starter ## Basic Information - **Project Name**: multi-source-spring-boot-starter - **Description**: This project is a multi-datasource auto-configuration project based on Spring Boot Starter. - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: main - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2024-12-24 - **Last Updated**: 2025-09-05 ## Categories & Tags **Categories**: Uncategorized **Tags**: Spring, SpringBoot, Redis, RabbitMQ, Multi-Sources ## README image:https://img.shields.io/badge/maven%20central-v3.0.1-blue.svg["Maven Central",link="https://search.maven.org/#search%7Cga%7C1%7Ca%3A%22quickfixj-spring-boot-starter%22"] image:https://img.shields.io/hexpm/l/plug.svg["Apache 2",link="http://www.apache.org/licenses/LICENSE-2.0"] = Spring Boot Starter for Multi Data Source (Spring Boot 3) This project is a multi-datasource auto-configuration project based on https://spring.io/projects/spring-boot/[Spring Boot Starter]. It simplifies the complex process of creating multiple data sources, requiring only configuration of properties, just like in a typical Spring Boot project. == Getting started === Redis Multi Data Sources To use Redis multi-data sources, you need to add the Redis Multi Sources Spring Boot Starter dependency to your project. [source,xml] ---- com.childrengreens redis-multi-source-spring-boot-starter 2.3 ---- To use Jedis instead of Lettuce as the client, you need to add the following dependencies: [source, xml] ---- redis.clients jedis ---- Add the following configuration to your properties file. [source,properties] ---- # set the primary-key data source (must) spring.multi-sources.redis.primary-key=cn # cn data source spring.multi-sources.redis.source.cn.host=127.0.0.1 spring.multi-sources.redis.source.cn.port=6379 spring.multi-sources.redis.source.cn.password=Asd12345!. # hk data source spring.multi-sources.redis.sources.hk.sentinel.master=hk-redis-master spring.multi-sources.redis.sources.hk.database=0 # jedis client spring.multi-sources.redis.sources.hk.client-type=jedis spring.multi-sources.redis.sources.hk.password=Asd12345!. spring.multi-sources.redis.sources.hk.lettuce.pool.enabled=true spring.multi-sources.redis.sources.hk.sentinel.nodes[0]=192.168.1.1:26379 spring.multi-sources.redis.sources.hk.sentinel.nodes[1]=192.168.1.2:26379 spring.multi-sources.redis.sources.hk.sentinel.nodes[2]=192.168.1.2:26379 # us data source spring.multi-sources.redis.sources.us.cluster.nodes[0]=127.0.0.1:6379 spring.multi-sources.redis.sources.us.cluster.nodes[1]=127.0.0.1:6380 spring.multi-sources.redis.sources.us.cluster.nodes[2]=127.0.0.1:6381 spring.multi-sources.redis.sources.us.cluster.max-redirects=3 spring.multi-sources.redis.sources.us.password=Asd12345!. ---- [source,yml] ---- spring: multi-sources: redis: # set the primary-key data source (must) primary-key: cn # cn data source source: cn: host: 127.0.0.1 port: 6379 password: Asd12345!. # hk data source sources: hk: sentinel: master: hk-redis-master # Sentinel nodes nodes: - 192.168.1.1:26379 - 192.168.1.2:26379 - 192.168.1.2:26379 database: 0 # jedis client client-type: jedis password: Asd12345!. lettuce: pool: enabled: true # us data source us: cluster: # Cluster nodes nodes: - 127.0.0.1:6379 - 127.0.0.1:6380 - 127.0.0.1:6381 max-redirects: 3 password: Asd12345!. ---- === Redis Multi Source Runtime Redis Multi Sources Spring Boot Starter will create multiple sets of `LettuceConnectionFactory` or `JedisConnectionFactory`, `RedisTemplate`, and `StringRedisTemplate` beans based on the configuration and register them in the Spring container. The naming convention for the bean names is: `sourceName` + `className`. Therefore, the usage is as follows: [source,java] ---- @Autowired @Qualifier("cnStringRedisTemplate") private StringRedisTemplate stringRedisTemplate; @Autowired @Qualifier("hkRedisTemplate") private RedisTemplate redisTemplate; @Autowired @Qualifier("usLettuceConnectionFactory") private RedisConnectionFactory redisConnectionFactory; @Autowired @Qualifier("hkJedisConnectionFactory") private RedisConnectionFactory redisConnectionFactory; ---- === RabbitMQ Multi Data Sources To use RabbitMQ multi-data sources, you need to add the AMQP Multi Sources Spring Boot Starter dependency to your project. [source,xml] ---- com.childrengreens amqp-multi-source-spring-boot-starter 2.3 ---- Add the following configuration to your properties file. [source,properties] ---- # set the primary-key data source (must) spring.multi-sources.rabbitmq.primary-key=cn # cn data source spring.multi-sources.rabbitmq.sources.cn.port=5672 spring.multi-sources.rabbitmq.sources.cn.host=192.168.1.1 spring.multi-sources.rabbitmq.sources.cn.username=guest spring.multi-sources.rabbitmq.sources.cn.password=guest spring.multi-sources.rabbitmq.sources.cn.virtual-host=/ # hk data source spring.multi-sources.rabbitmq.sources.hk.port=5672 spring.multi-sources.rabbitmq.sources.hk.host=192.168.1.2 spring.multi-sources.rabbitmq.sources.hk.username=guest spring.multi-sources.rabbitmq.sources.hk.password=guest spring.multi-sources.rabbitmq.sources.hk.virtual-host=/ ---- [source,yml] ---- # set the primary-key data source (must) spring: multi-sources: rabbitmq: primary-key: cn # cn data source sources: cn: port: 5672 host: 192.168.1.1 username: guest password: guest virtual-host: / # hk data source hk: port: 5672 host: 192.168.1.2 username: guest password: guest virtual-host: / ---- === RabbitMQ Multi Source Runtime AMQP Multi Sources Spring Boot Starter will create multiple sets of `CachingConnectionFactory`, `SimpleRabbitListenerContainerFactory`, `RabbitTemplate`, and `RabbitMessagingTemplate` beans based on the configuration and register them in the Spring container. The naming convention for the bean names is: `sourceName` + `className`. Therefore, the usage is as follows: [source,java] ---- @Autowired @Qualifier("cnCachingConnectionFactory") private CachingConnectionFactory cachingConnectionFactory; @Autowired @Qualifier("hkRabbitTemplate") private RabbitTemplate rabbitTemplate; @Autowired @Qualifier("hkSimpleRabbitListenerContainerFactory") private SimpleRabbitListenerContainerFactory simpleRabbitListenerContainerFactory; ---- === InfluxDB2 Multi Data Sources To use InfluxDB2 multi-data sources, you need to add the Influx2 Multi Sources Spring Boot Starter dependency to your project. [source,xml] ---- com.childrengreens influx2-multi-source-spring-boot-starter 2.3 ---- Add the following configuration to your properties file. [source,properties] ---- # set the primary-key data source (must) spring.multi-sources.influx.primary-key=cn # cn data source spring.multi-sources.influx.sources.cn.url=http://127.0.0.1:8086/ spring.multi-sources.influx.sources.cn.token=wkOEKEVJ4jJBUhTwzKLsFVTpqR_JsGR3w6ybS3xTDy67WSaY14W4HQf59r69pX0YDaboNDRo_SrMa_T3clNMPA== spring.multi-sources.influx.sources.cn.org=cn-market-data spring.multi-sources.influx.sources.cn.bucket=cn-data # hk data source spring.multi-sources.influx.sources.hk.url=http://127.0.0.2:8086/ spring.multi-sources.influx.sources.hk.token=wkOEKEVJ4jJBUhTwzKLsFVTpqR_JsGR3w6ybS3xTDy67WSaY14W4HQf59r69pX0YDaboNDRo_FkMa_T3clNMPA== spring.multi-sources.influx.sources.hk.org=hk-market-data spring.multi-sources.influx.sources.hk.bucket=hk-data ---- [source,yml] ---- # set the primary-key data source (must) spring: multi-sources: influx: primary-key: cn # cn data source sources: cn: url: http://127.0.0.1:8086/ token: wkOEKEVJ4jJBUhTwzKLsFVTpqR_JsGR3w6ybS3xTDy67WSaY14W4HQf59r69pX0YDaboNDRo_SrMa_T3clNMPA== org: cn-market-data bucket: cn-data # hk data source hk: url: http://127.0.0.2:8086/ token: wkOEKEVJ4jJBUhTwzKLsFVTpqR_JsGR3w6ybS3xTDy67WSaY14W4HQf59r69pX0YDaboNDRo_FkMa_T3clNMPA== org: hk-market-data bucket: hk-data ---- === InfluxDB2 Multi Source Runtime Influx2 Multi Sources Spring Boot Starter will create multiple `InfluxDBClient` bean based on the configuration and register them in the Spring container. The naming convention for the bean names is: `sourceName` + `className`. Therefore, the usage is as follows: [source,java] ---- @Autowired @Qualifier("cnInfluxDBClient") private InfluxDBClient influxDBClient; ---- == License Spring Boot is Open Source software released under the https://www.apache.org/licenses/LICENSE-2.0.html[Apache 2.0 license].