I have multiple routing keys that connect with the same exchange. I have configure the routing keys separated by semicolon in my application.properties like this:
events.routingkey=ONLINE.UPDATE.ADDRESS.RES; ONLINE.UPDATE.ADDRESS.PHN; ONLINE.UPDATE.ADDRESS.MOB; etc....
After that, if i go to the monitor I see the routing keys like this, but I'm not quite sure if I should have one routing key per bind with the same exchange or if this is OK.
UPDATE: So I have changed the config class as follows:
@Value("#{'${peopleevents.routingkey}'.split(',')}")
public List<String> routingKey;
And then when declaring the biding how can I add every routing key to a new biding coming from the same exchage? Is there a way to do it with a for or something?
@Bean
public Binding binding(Queue queue, TopicExchange exchange) {
return BindingBuilder
.bind(queue)
.to(exchange)
.with(routingKey.foreach(what should I put here?););
}
CodePudding user response:
You need a separate binding for each routing key.
EDIT
If you use a comma-delimited list, you don't need SpEL, Spring will automatically split and trim the values:
@Bean
Declarables bindings(@Value("${keys}") List<String> keys, DirectExchange exchange, Queue queue) {
return new Declarables(keys.stream()
.map(key -> BindingBuilder.bind(queue)
.to(exchange)
.with(key))
.collect(Collectors.toList()));
}