我正在尝试设置具有Spring Cloud Stream支持的RabbitMQ
我有几个消费者和生产者。生产者之一应将消息产生到同一RabbitMQ实例(以后可能是不同的物理实例)上的单独虚拟主机。
application.yaml
spring:
cloud:
stream:
binders:
binder1:
type: rabbit
defaultCandidate: false
inheritEnvironment: false
environment:
spring:
rabbitmq:
host: localhost
port: 5672
virtual-host: virtual-host-1
username: guest
password: guest
binder2:
type: rabbit
defaultCandidate: false
inheritEnvironment: false
environment:
spring:
rabbitmq:
host: localhost
port: 5672
virtual-host: virtual-host-2
username: guest
password: guest
bindings:
test:
binder: binder1
coordinates:
destination: coordinates
binder: binder1
events:
destination: events
binder: binder1
events_output:
destination: events
binder: binder1
tasks:
destination: tasks
binder: binder2
目标是绑定tasks
应该使用虚拟主机virtual-host-2
。其他绑定应使用虚拟主机virtual-host-1
。
但是似乎忽略了binder
值,并且在应用程序启动时使用默认设置考虑了默认rabbit
活页夹。
我在调试运行时注意到它:
每个绑定上的binder
值为NULL。尽管该值在属性中明确提供。
如果我将defaultCandidate
中的任何活页夹设置为true
,则该活页夹设置将替代默认设置。
配置不正确吗?
答案 0 :(得分:0)
这是我不喜欢Yaml的原因之一。很难跟踪可能配置错误的内容。无论如何,这是我刚刚尝试的工作示例。
spring:
cloud:
stream:
bindings:
input:
binder: rabbit1
group: vhost1-group
destination: vhost1-queue
output:
binder: rabbit2
destination: vhost2-queue
binders:
rabbit1:
type: rabbit
environment:
spring:
rabbitmq:
host: localhost
virtual-host: vhost1
rabbit2:
type: rabbit
environment:
spring:
rabbitmq:
host: localhost
virtual-host: vhost2
答案 1 :(得分:0)
我刚刚复制/粘贴了您的配置;修复了一些缩进,对我来说效果很好...
spring:
cloud:
stream:
binders:
binder1:
type: rabbit
defaultCandidate: false
inheritEnvironment: false
environment:
spring:
rabbitmq:
host: localhost
port: 5672
virtual-host: virtual-host-1
username: guest
password: guest
binder2:
type: rabbit
defaultCandidate: false
inheritEnvironment: false
environment:
spring:
rabbitmq:
host: localhost
port: 5672
virtual-host: virtual-host-2
username: guest
password: guest
bindings:
test:
binder: binder1
tasks:
destination: tasks
binder: binder2
@SpringBootApplication
@EnableBinding(Foo.class)
public class So56462671Application {
public static void main(String[] args) {
SpringApplication.run(So56462671Application.class, args);
}
}
interface Foo {
@Input
MessageChannel test();
@Input
MessageChannel tasks();
}
和
defaultCandidate: false
inheritEnvironment: false
缩进不正确,但出现YAML解析错误。