RabbitMqConfig.java
1.38 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package com.topdraw.mq.config;
import org.apache.commons.lang3.StringUtils;
import org.springframework.amqp.core.*;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@Configuration
public class RabbitMqConfig {
public static final String UCE_EXCHANGE = "uce.exchange";
public static final String UCE_QUEUE = "uce.queue";
@Value("${service.mq.exchange}")
private String exchange;
@Value("${service.mq.queue}")
private String queue;
public String getExchange(){
if (StringUtils.isEmpty(this.exchange)) {
this.exchange = UCE_EXCHANGE;
}
return this.exchange;
}
public String getQueue() {
if (StringUtils.isEmpty(this.queue)) {
this.queue = UCE_QUEUE;
}
return this.queue;
}
@Bean
DirectExchange directExchange(){
return ExchangeBuilder.directExchange(getExchange()).build();
}
@Bean
Queue queue(){ return new Queue(getQueue()); }
@Bean
Binding binding(DirectExchange directExchange , Queue queue) {
BindingBuilder.DirectExchangeRoutingKeyConfigurer directExchangeRoutingKeyConfigurer =
BindingBuilder.bind(queue).to(directExchange);
return directExchangeRoutingKeyConfigurer.with(this.getQueue());
}
}