We are trying to use a single spring consumer function to connect to 2 different queues in 2 different rabbitmq instances.
This doesn't seem to work. The consumer function is bound to the first binder declared in the application yaml.
Config in application.yml
{
function:
definition: processMessage
stream:
binders:
rabbit1:
type: rabbit
environment:
spring:
rabbitmq:
host: ${host}
port: ${port}
username: ${username}
password: ${password}
virtual-host: ${virtual-host}
rabbit2:
type: rabbit
environment:
spring:
rabbitmq:
host: ${host}
port: ${port}
username: ${username}
password: ${password}
virtual-host: ${virtual-host}
bindings:
processMessage-in-0:
destination: exchange1
group: queue1
binder: rabbit1
processMessage-in-1:
destination: exchange1
group: queue1
binder: rabbit2
}
Consumer function code :
@Bean
public Consumer<Long> processMessage() {
return (message) -> System.out.println(" Read from processMessage {} " + message.longValue());
}
I want the same function to read from 2 different queues on 2 different instances, which are denoted by the 2 different binders.
But it reads from just 1 instance, either rabbit1 or rabbit2, whichever is bound to processMessage-in-0 and it ignores processMessage-in-1. The issue is solved if we use to different consumer functions, like processMessage1 and processMessage2, but we want to avoid this.
Is there anyway to get this to work ie to use different binders for the same spring cloud function ie, both processMessage-in-0 and processMessage-in-1 bound to both processMessage function at the same time so we can have messages published on both exchanges on both the rabbitmq instances to be consumed by the same spring cloud function code.