RabbitMqConfig.java
1.7 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
package com.topdraw.mq.config;
import com.topdraw.config.LocalConstants;
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 {
@Value("${engine.platform}")
private String platform;
@Value("${engine.type}")
private String type;
@Value("${engine.mq.exchange}")
private String exchange;
@Value("${engine.mq.routingkey}")
private String routingKey;
public String getExchange(){
if (StringUtils.isEmpty(this.exchange)) {
this.routingKey = "uc.direct";
}
return this.exchange;
}
public String getRoutingKey() {
if (StringUtils.isEmpty(this.routingKey)) {
if (platform.equalsIgnoreCase(LocalConstants.PLATFORM_TYPE_SERVICE)) {
if (StringUtils.isEmpty(this.type)) {
this.type = LocalConstants.ENV_VIS;
}
}
this.routingKey = "uc."+platform+"."+type+".direct";
}
return routingKey;
}
@Bean
DirectExchange directExchange(){
return ExchangeBuilder.directExchange(getExchange()).build();
}
@Bean
Queue queue(){ return new Queue(getRoutingKey()); }
@Bean
Binding binding(DirectExchange directExchange , Queue queue) {
BindingBuilder.DirectExchangeRoutingKeyConfigurer directExchangeRoutingKeyConfigurer =
BindingBuilder.bind(queue).to(directExchange);
return directExchangeRoutingKeyConfigurer.with(getRoutingKey());
}
}