1.优化
Showing
6 changed files
with
88 additions
and
6 deletions
... | @@ -9,7 +9,9 @@ import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory; | ... | @@ -9,7 +9,9 @@ import org.springframework.amqp.rabbit.listener.RabbitListenerContainerFactory; |
9 | import org.springframework.beans.factory.annotation.Qualifier; | 9 | import org.springframework.beans.factory.annotation.Qualifier; |
10 | import org.springframework.beans.factory.annotation.Value; | 10 | import org.springframework.beans.factory.annotation.Value; |
11 | import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; | 11 | import org.springframework.boot.autoconfigure.amqp.SimpleRabbitListenerContainerFactoryConfigurer; |
12 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | ||
12 | import org.springframework.context.annotation.Bean; | 13 | import org.springframework.context.annotation.Bean; |
14 | import org.springframework.context.annotation.Conditional; | ||
13 | import org.springframework.context.annotation.Configuration; | 15 | import org.springframework.context.annotation.Configuration; |
14 | import org.springframework.context.annotation.Primary; | 16 | import org.springframework.context.annotation.Primary; |
15 | 17 | ||
... | @@ -73,11 +75,13 @@ public class RabbitMqConfig { | ... | @@ -73,11 +75,13 @@ public class RabbitMqConfig { |
73 | return connectionFactory; | 75 | return connectionFactory; |
74 | } | 76 | } |
75 | 77 | ||
78 | // @ConditionalOnProperty(prefix = "mutil-mq", name = "service.startup", havingValue = "on") | ||
76 | @Bean(name = "serviceRabbitListenerContainerFactory") | 79 | @Bean(name = "serviceRabbitListenerContainerFactory") |
77 | @Primary | 80 | @Primary |
78 | public RabbitListenerContainerFactory userCenterRabbitListenerContainerFactory( | 81 | public RabbitListenerContainerFactory userCenterRabbitListenerContainerFactory( |
79 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, | 82 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, |
80 | @Qualifier("serviceConnectionFactory") ConnectionFactory connectionFactory) { | 83 | @Qualifier("serviceConnectionFactory") ConnectionFactory connectionFactory) { |
84 | System.out.println("userCenterRabbitListenerContainerFactory ====>> start "); | ||
81 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | 85 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); |
82 | containerFactoryConfigurer.configure(factory,connectionFactory); | 86 | containerFactoryConfigurer.configure(factory,connectionFactory); |
83 | return factory; | 87 | return factory; |
... | @@ -113,10 +117,12 @@ public class RabbitMqConfig { | ... | @@ -113,10 +117,12 @@ public class RabbitMqConfig { |
113 | return connectionFactory; | 117 | return connectionFactory; |
114 | } | 118 | } |
115 | 119 | ||
120 | // @ConditionalOnProperty(prefix = "mutil-mq", name = "management.startup", havingValue = "on") | ||
116 | @Bean(name = "managementRabbitListenerContainerFactory") | 121 | @Bean(name = "managementRabbitListenerContainerFactory") |
117 | public RabbitListenerContainerFactory memberServiceRabbitListenerContainerFactory( | 122 | public RabbitListenerContainerFactory memberServiceRabbitListenerContainerFactory( |
118 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, | 123 | SimpleRabbitListenerContainerFactoryConfigurer containerFactoryConfigurer, |
119 | @Qualifier("managementConnectionFactory") ConnectionFactory connectionFactory) { | 124 | @Qualifier("managementConnectionFactory") ConnectionFactory connectionFactory) { |
125 | System.out.println("memberServiceRabbitListenerContainerFactory ====>> start "); | ||
120 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); | 126 | SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory(); |
121 | containerFactoryConfigurer.configure(factory,connectionFactory); | 127 | containerFactoryConfigurer.configure(factory,connectionFactory); |
122 | return factory; | 128 | return factory; | ... | ... |
1 | package com.topdraw.config; | ||
2 | |||
3 | import org.springframework.context.annotation.Condition; | ||
4 | import org.springframework.context.annotation.ConditionContext; | ||
5 | import org.springframework.core.type.AnnotatedTypeMetadata; | ||
6 | |||
7 | /** | ||
8 | * @author : | ||
9 | * @description: | ||
10 | * @function : | ||
11 | * @date :Created in 2022/4/4 17:45 | ||
12 | * @version: : | ||
13 | * @modified By: | ||
14 | * @since : modified in 2022/4/4 17:45 | ||
15 | */ | ||
16 | public class RabbitmqStartupCondition implements Condition { | ||
17 | |||
18 | |||
19 | @Override | ||
20 | public boolean matches(ConditionContext conditionContext, AnnotatedTypeMetadata annotatedTypeMetadata) { | ||
21 | return false; | ||
22 | } | ||
23 | } |
1 | package com.topdraw.mq.consumer; | ||
2 | |||
3 | import com.topdraw.config.RabbitMqConfig; | ||
4 | import com.topdraw.mq.domain.TableOperationMsg; | ||
5 | import com.topdraw.resttemplate.RestTemplateClient; | ||
6 | import com.topdraw.util.JSONUtil; | ||
7 | import lombok.extern.slf4j.Slf4j; | ||
8 | import org.springframework.amqp.core.ExchangeTypes; | ||
9 | import org.springframework.amqp.rabbit.annotation.*; | ||
10 | import org.springframework.beans.factory.annotation.Autowired; | ||
11 | import org.springframework.stereotype.Component; | ||
12 | import org.springframework.util.Assert; | ||
13 | |||
14 | @Component | ||
15 | @Slf4j | ||
16 | public class UcEngineManagementEventConsumer { | ||
17 | |||
18 | @Autowired | ||
19 | AutoRoute autoUser; | ||
20 | |||
21 | @Autowired | ||
22 | RestTemplateClient restTemplateClient; | ||
23 | |||
24 | /** | ||
25 | * 事件 | ||
26 | * @param content | ||
27 | * @description 基础数据同步 | ||
28 | * @author Hongyan Wang | ||
29 | * @date 2021/9/7 11:26 上午 | ||
30 | */ | ||
31 | @RabbitHandler | ||
32 | @RabbitListener(bindings = { | ||
33 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_CCC), | ||
34 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) | ||
35 | }, containerFactory = "serviceRabbitListenerContainerFactory") | ||
36 | public void ucEventConsumer(String content) { | ||
37 | log.info(" receive dataSync msg , content is : {} ", content); | ||
38 | TableOperationMsg tableOperationMsg = this.parseContent(content); | ||
39 | autoUser.route(tableOperationMsg); | ||
40 | log.info("ucEventConsumer ====>>>> end"); | ||
41 | } | ||
42 | |||
43 | /** | ||
44 | * 数据解析 | ||
45 | * @param content | ||
46 | * @return | ||
47 | */ | ||
48 | private TableOperationMsg parseContent(String content) { | ||
49 | TableOperationMsg tableOperationMsg = JSONUtil.parseMsg2Object(content,TableOperationMsg.class); | ||
50 | Assert.notNull(tableOperationMsg,"ERROR -->> operationConsumer -->> parseContent -->> 【dataSyncMsg】 not be null !!"); | ||
51 | return tableOperationMsg; | ||
52 | } | ||
53 | |||
54 | } |
... | @@ -16,7 +16,7 @@ import org.springframework.util.Assert; | ... | @@ -16,7 +16,7 @@ import org.springframework.util.Assert; |
16 | 16 | ||
17 | @Component | 17 | @Component |
18 | @Slf4j | 18 | @Slf4j |
19 | public class UcEngineEventConsumer { | 19 | public class UcEngineServiceIptvEventConsumer { |
20 | 20 | ||
21 | @Autowired | 21 | @Autowired |
22 | AutoRoute autoUser; | 22 | AutoRoute autoUser; |
... | @@ -31,7 +31,7 @@ public class UcEngineEventConsumer { | ... | @@ -31,7 +31,7 @@ public class UcEngineEventConsumer { |
31 | * @author Hongyan Wang | 31 | * @author Hongyan Wang |
32 | * @date 2021/9/7 11:26 上午 | 32 | * @date 2021/9/7 11:26 上午 |
33 | */ | 33 | */ |
34 | /* @RabbitHandler | 34 | /*@RabbitHandler |
35 | @RabbitListener(bindings = { | 35 | @RabbitListener(bindings = { |
36 | @QueueBinding(value = @Queue(value = RabbitMqConfig.ENGINE_TO_IPTV_CONSUMER_MEMBER_DIRECT), | 36 | @QueueBinding(value = @Queue(value = RabbitMqConfig.ENGINE_TO_IPTV_CONSUMER_MEMBER_DIRECT), |
37 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) | 37 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) | ... | ... |
... | @@ -38,7 +38,7 @@ public class UcEventBusConsumer { | ... | @@ -38,7 +38,7 @@ public class UcEventBusConsumer { |
38 | * @author Hongyan Wang | 38 | * @author Hongyan Wang |
39 | * @date 2021/9/7 11:26 上午 | 39 | * @date 2021/9/7 11:26 上午 |
40 | */ | 40 | */ |
41 | @RabbitHandler/* | 41 | /*@RabbitHandler |
42 | @RabbitListener(bindings = { | 42 | @RabbitListener(bindings = { |
43 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_EVENTBUS_TOPIC), | 43 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_EVENTBUS_TOPIC), |
44 | exchange = @Exchange(type = ExchangeTypes.TOPIC, name = RabbitMqConfig.UC_EVENTBUS), | 44 | exchange = @Exchange(type = ExchangeTypes.TOPIC, name = RabbitMqConfig.UC_EVENTBUS), |
... | @@ -101,7 +101,6 @@ public class UcEventBusConsumer { | ... | @@ -101,7 +101,6 @@ public class UcEventBusConsumer { |
101 | msgData1.setMemberCode(memberCode); | 101 | msgData1.setMemberCode(memberCode); |
102 | } | 102 | } |
103 | 103 | ||
104 | |||
105 | msgData1.setEvent(8); | 104 | msgData1.setEvent(8); |
106 | msgData1.setDeviceType(deviceType); | 105 | msgData1.setDeviceType(deviceType); |
107 | msgData1.setMediaId(mediaId); | 106 | msgData1.setMediaId(mediaId); | ... | ... |
... | @@ -28,11 +28,11 @@ public class UcGatewayEventConsumer { | ... | @@ -28,11 +28,11 @@ public class UcGatewayEventConsumer { |
28 | * @author Hongyan Wang | 28 | * @author Hongyan Wang |
29 | * @date 2021/9/7 11:26 上午 | 29 | * @date 2021/9/7 11:26 上午 |
30 | */ | 30 | */ |
31 | @RabbitHandler | 31 | /*@RabbitHandler |
32 | @RabbitListener(bindings = { | 32 | @RabbitListener(bindings = { |
33 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_AAA), | 33 | @QueueBinding(value = @Queue(value = RabbitMqConfig.UC_ROUTE_KEY_DIRECT_EVENT_AAA), |
34 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) | 34 | exchange = @Exchange(value = ExchangeTypes.DIRECT)) |
35 | }, containerFactory = "managementRabbitListenerContainerFactory") | 35 | }, containerFactory = "managementRabbitListenerContainerFactory")*/ |
36 | public void ucEventConsumer(String content) { | 36 | public void ucEventConsumer(String content) { |
37 | log.info(" receive dataSync msg , content is : {} ", content); | 37 | log.info(" receive dataSync msg , content is : {} ", content); |
38 | DataSyncMsg dataSyncMsg = this.parseContent(content); | 38 | DataSyncMsg dataSyncMsg = this.parseContent(content); | ... | ... |
-
Please register or sign in to post a comment