|
@@ -1,17 +1,44 @@
|
|
|
package es.uv.garcosda.config;
|
|
|
|
|
|
+import org.springframework.amqp.core.AmqpAdmin;
|
|
|
+import org.springframework.amqp.core.Binding;
|
|
|
+import org.springframework.amqp.core.BindingBuilder;
|
|
|
+import org.springframework.amqp.core.DirectExchange;
|
|
|
import org.springframework.amqp.core.Queue;
|
|
|
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.context.annotation.Bean;
|
|
|
import org.springframework.context.annotation.Configuration;
|
|
|
|
|
|
@Configuration
|
|
|
public class RabbitMQConfig {
|
|
|
|
|
|
- @Bean
|
|
|
- public Queue createUserRegistrationQueue() {
|
|
|
- return new Queue("q.new_user");
|
|
|
- }
|
|
|
+ @Value("${rabbitmq.queue.name}")
|
|
|
+ private String queue;
|
|
|
+
|
|
|
+ @Value("${rabbitmq.exchange.name}")
|
|
|
+ private String exchange;
|
|
|
+
|
|
|
+ @Value("${rabbitmq.routing.key}")
|
|
|
+ private String routingKey;
|
|
|
+
|
|
|
+ @SuppressWarnings("unused")
|
|
|
+ @Autowired
|
|
|
+ private AmqpAdmin amqpAdmin;
|
|
|
+
|
|
|
+
|
|
|
+ @Bean
|
|
|
+ public void Configure() {
|
|
|
+ Queue q = new Queue(this.queue, true, false, false);
|
|
|
+ DirectExchange e = new DirectExchange(this.exchange);
|
|
|
+ amqpAdmin.declareQueue(q);
|
|
|
+ amqpAdmin.declareExchange(e);
|
|
|
+ amqpAdmin.declareBinding(BindingBuilder
|
|
|
+ .bind(q)
|
|
|
+ .to(e)
|
|
|
+ .with(routingKey));
|
|
|
+ }
|
|
|
|
|
|
@Bean
|
|
|
public Jackson2JsonMessageConverter converter() {
|