连接多个系统
默认情况下,绑定程序共享应用程序的 Spring Boot 自动配置,因此每个类路径上找到的绑定程序都会创建一个实例。 如果您的应用程序应该连接到同一类型的多个代理服务器,您可以指定多个绑定器配置,每个配置都有不同的环境设置。
启用显式的绑定器配置将完全禁用默认的绑定器配置过程。 如果这样做,使用中的所有绑定器都必须包含在配置中。 打算透明地使用 Spring Cloud Stream 的框架可以创建可按名称引用的绑定器配置,但它们不会影响默认的绑定器配置。 为此,绑定器配置可以将其 defaultCandidate 标志设置为 false(例如,spring.cloud.stream.binders.<configurationName>.defaultCandidate=false)。 这表示一个独立于默认绑定器配置过程的配置。 |
The following example shows a typical configuration for a processor application that connects to two RabbitMQ broker instances:
spring:
cloud:
stream:
bindings:
input:
destination: thing1
binder: rabbit1
output:
destination: thing2
binder: rabbit2
binders:
rabbit1:
type: rabbit
environment:
spring:
rabbitmq:
host: <host1>
rabbit2:
type: rabbit
environment:
spring:
rabbitmq:
host: <host2>
特定绑定器的 environment 属性也可用于任何 Spring Boot 属性, 包括这个 spring.main.sources,它对于为特定绑定器添加额外配置非常有用, 例如覆盖自动配置的 bean。 |
例如;
environment:
spring:
main:
sources: com.acme.config.MyCustomBinderConfiguration
要为特定的绑定器环境激活特定的配置文件,您应该使用spring.profiles.active属性:
environment:
spring:
profiles:
active: myBinderProfile