I'm currently working on a rabbit-amqp implementation project and use spring-rabbit to programmatically setup all my queues, bindings and exchanges. (spring-rabbit-1.3.4 and spring-framework versions 3.2.0)
The declaration in a javaconfiguration class or xml-based configuration are both quite static in my opinion declared. I know how to set a more dynamic value (ex. a name) for a queue, exchange or binding like this:
@Configuration
public class serverConfiguration {
private String queueName;
...
@Bean
public Queue buildQueue() {
Queue queue = new Queue(this.queueName, false, false, true, getQueueArguments());
buildRabbitAdmin().declareQueue(queue);
return queue;
}
...
}
But I was wondering if it was possible to create a undefined amount instances of Queue and register them as beans like a factory registering all its instances.
I'm not really familiar with the Spring @Bean annotation and its limitations, but I tried
@Configuration
public class serverConfiguration {
private String queueName;
...
@Bean
@Scope("prototype")
public Queue buildQueue() {
Queue queue = new Queue(this.queueName, false, false, true, getQueueArguments());
buildRabbitAdmin().declareQueue(queue);
return queue;
}
...
}
And to see if the multiple beans instances of Queue are registered I call:
Map<String, Queue> queueBeans = ((ListableBeanFactory) applicationContext).getBeansOfType(Queue.class);
But this will only return 1 mapping:
name of the method := the last created instance.
Is it possible to dynamically add beans during runtime to the SpringApplicationContext?