瀏覽代碼

Topic Routing

dagarcos 2 年之前
父節點
當前提交
e9ec85b159

+ 15 - 1
src/main/java/es/uv/garcosda/config/RabbitMQConfig.java

@@ -5,6 +5,7 @@ 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.core.TopicExchange;
 import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.beans.factory.annotation.Value;
@@ -19,6 +20,9 @@ public class RabbitMQConfig {
 	
 	@Value("${rabbitmq.queue.name.recover}")
     private String queueRecover;
+	
+	@Value("${rabbitmq.queue.name.system}")
+    private String queueSystem;
 
     @Value("${rabbitmq.exchange.name}")
     private String exchange;
@@ -29,6 +33,9 @@ public class RabbitMQConfig {
     @Value("${rabbitmq.routing.key.recover}")
     private String routingKeyRecover;
     
+    @Value("${rabbitmq.routing.key.system}")
+    private String routingKeySystem;
+    
     @SuppressWarnings("unused")
 	@Autowired 
     private AmqpAdmin amqpAdmin;
@@ -38,10 +45,12 @@ public class RabbitMQConfig {
     public void Configure() {
     	Queue q = new Queue(this.queueUser, true, false, false);
     	Queue q2 = new Queue(this.queueRecover, true, false, false);
+    	Queue q3 = new Queue(this.queueSystem, true, false, false);
     	amqpAdmin.declareQueue(q);
     	amqpAdmin.declareQueue(q2);
+    	amqpAdmin.declareQueue(q3);
     	
-    	DirectExchange e = new DirectExchange(this.exchange);
+    	TopicExchange e = new TopicExchange(this.exchange);
     	amqpAdmin.declareExchange(e);
     	
     	amqpAdmin.declareBinding(BindingBuilder
@@ -53,6 +62,11 @@ public class RabbitMQConfig {
 					                .bind(q2)
 					                .to(e)
 					                .with(routingKeyRecover));
+    	
+    	amqpAdmin.declareBinding(BindingBuilder
+					                .bind(q3)
+					                .to(e)
+					                .with(routingKeySystem));
     } 
 	
 	@Bean

+ 11 - 1
src/main/resources/META-INF/additional-spring-configuration-metadata.json

@@ -9,7 +9,7 @@
     "type": "java.lang.String",
     "description": "A description for 'rabbitmq.queue.name.user'"
   },
-    {
+  {
     "name": "rabbitmq.queue.name.recover",
     "type": "java.lang.String",
     "description": "A description for 'rabbitmq.queue.name.recover'"
@@ -23,5 +23,15 @@
     "name": "rabbitmq.routing.key.recover",
     "type": "java.lang.String",
     "description": "A description for 'rabbitmq.routing.key.recover'"
+  },
+  {
+    "name": "rabbitmq.queue.name.system",
+    "type": "java.lang.String",
+    "description": "A description for 'rabbitmq.queue.name.system'"
+  },
+  {
+    "name": "rabbitmq.routing.key.system",
+    "type": "java.lang.String",
+    "description": "A description for 'rabbitmq.routing.key.system'"
   }
 ]}

+ 4 - 2
src/main/resources/application.properties

@@ -3,8 +3,10 @@ spring.rabbitmq.host=localhost
 spring.rabbitmq.port=5672
 spring.rabbitmq.username=guest
 spring.rabbitmq.password=guest
+rabbitmq.exchange.name=mailer
 rabbitmq.queue.name.user=q.new_user
 rabbitmq.queue.name.recover=q.recover
-rabbitmq.exchange.name=mailer
+rabbitmq.queue.name.system=q.system
 rabbitmq.routing.key.user=k.new_user
-rabbitmq.routing.key.recover=k.recover
+rabbitmq.routing.key.recover=k.recover
+rabbitmq.routing.key.system=k.*