正在显示
11 个修改的文件
包含
106 行增加
和
17 行删除
@@ -10,7 +10,7 @@ | @@ -10,7 +10,7 @@ | ||
10 | </parent> | 10 | </parent> |
11 | <groupId>com.sunyo.wlpt.message.bus.service</groupId> | 11 | <groupId>com.sunyo.wlpt.message.bus.service</groupId> |
12 | <artifactId>message_bus_service</artifactId> | 12 | <artifactId>message_bus_service</artifactId> |
13 | - <version>1.1.0-kafka</version> | 13 | + <version>1.1.2-kafka</version> |
14 | <name>message_bus_service</name> | 14 | <name>message_bus_service</name> |
15 | <description>消息总线服务</description> | 15 | <description>消息总线服务</description> |
16 | 16 |
@@ -8,6 +8,7 @@ import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAu | @@ -8,6 +8,7 @@ import org.springframework.boot.autoconfigure.data.elasticsearch.ElasticsearchAu | ||
8 | import org.springframework.cache.annotation.EnableCaching; | 8 | import org.springframework.cache.annotation.EnableCaching; |
9 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; | 9 | import org.springframework.cloud.netflix.eureka.EnableEurekaClient; |
10 | import org.springframework.cloud.openfeign.EnableFeignClients; | 10 | import org.springframework.cloud.openfeign.EnableFeignClients; |
11 | +import org.springframework.context.annotation.ComponentScan; | ||
11 | import org.springframework.scheduling.annotation.EnableAsync; | 12 | import org.springframework.scheduling.annotation.EnableAsync; |
12 | import org.springframework.scheduling.annotation.EnableScheduling; | 13 | import org.springframework.scheduling.annotation.EnableScheduling; |
13 | import org.springframework.transaction.annotation.EnableTransactionManagement; | 14 | import org.springframework.transaction.annotation.EnableTransactionManagement; |
@@ -23,7 +24,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; | @@ -23,7 +24,6 @@ import org.springframework.transaction.annotation.EnableTransactionManagement; | ||
23 | @EnableTransactionManagement | 24 | @EnableTransactionManagement |
24 | @EnableScheduling | 25 | @EnableScheduling |
25 | @EnableAsync | 26 | @EnableAsync |
26 | - | ||
27 | public class MessageBusServiceApplication { | 27 | public class MessageBusServiceApplication { |
28 | 28 | ||
29 | public static void main(String[] args) { | 29 | public static void main(String[] args) { |
@@ -4,10 +4,12 @@ import com.sunyo.wlpt.message.bus.service.domain.BusServer; | @@ -4,10 +4,12 @@ import com.sunyo.wlpt.message.bus.service.domain.BusServer; | ||
4 | import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper; | 4 | import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper; |
5 | import org.apache.kafka.clients.admin.AdminClient; | 5 | import org.apache.kafka.clients.admin.AdminClient; |
6 | import org.apache.kafka.clients.admin.AdminClientConfig; | 6 | import org.apache.kafka.clients.admin.AdminClientConfig; |
7 | +import org.apache.kafka.clients.consumer.ConsumerConfig; | ||
7 | import org.apache.kafka.clients.consumer.KafkaConsumer; | 8 | import org.apache.kafka.clients.consumer.KafkaConsumer; |
8 | import org.springframework.context.annotation.Bean; | 9 | import org.springframework.context.annotation.Bean; |
9 | import org.springframework.context.annotation.Configuration; | 10 | import org.springframework.context.annotation.Configuration; |
10 | import org.springframework.kafka.core.KafkaAdmin; | 11 | import org.springframework.kafka.core.KafkaAdmin; |
12 | +import org.springframework.web.servlet.config.annotation.WebMvcConfigurerAdapter; | ||
11 | 13 | ||
12 | import javax.annotation.Resource; | 14 | import javax.annotation.Resource; |
13 | import java.util.HashMap; | 15 | import java.util.HashMap; |
@@ -17,12 +19,12 @@ import java.util.Properties; | @@ -17,12 +19,12 @@ import java.util.Properties; | ||
17 | import java.util.stream.Collectors; | 19 | import java.util.stream.Collectors; |
18 | 20 | ||
19 | @Configuration | 21 | @Configuration |
20 | -public class KafkaInitialConfiguration { | 22 | +public class KafkaInitialConfiguration extends WebMvcConfigurerAdapter { |
21 | 23 | ||
22 | @Resource | 24 | @Resource |
23 | private BusServerMapper busServerMapper; | 25 | private BusServerMapper busServerMapper; |
24 | 26 | ||
25 | - @Bean | 27 | + @Bean("myAdminclient") |
26 | public AdminClient adminClient() { | 28 | public AdminClient adminClient() { |
27 | Map<String, Object> configs = new HashMap<>(); | 29 | Map<String, Object> configs = new HashMap<>(); |
28 | String serverMap = ServerListForMap(); | 30 | String serverMap = ServerListForMap(); |
@@ -44,8 +46,9 @@ public class KafkaInitialConfiguration { | @@ -44,8 +46,9 @@ public class KafkaInitialConfiguration { | ||
44 | } | 46 | } |
45 | 47 | ||
46 | 48 | ||
47 | - @Bean | 49 | + @Bean("myConsumer") |
48 | public KafkaConsumer<String, String> consumer(){ | 50 | public KafkaConsumer<String, String> consumer(){ |
51 | +// ConsumerConfig.MAX_POLL_RECORDS_CONFIG; | ||
49 | Properties props = new Properties(); | 52 | Properties props = new Properties(); |
50 | props.put("bootstrap.servers", ServerListForMap()); | 53 | props.put("bootstrap.servers", ServerListForMap()); |
51 | props.put("group.id", "systemGroup"); | 54 | props.put("group.id", "systemGroup"); |
@@ -8,9 +8,6 @@ import com.sunyo.wlpt.message.bus.service.service.BusQueueService; | @@ -8,9 +8,6 @@ import com.sunyo.wlpt.message.bus.service.service.BusQueueService; | ||
8 | import com.sunyo.wlpt.message.bus.service.service.KafkaService; | 8 | import com.sunyo.wlpt.message.bus.service.service.KafkaService; |
9 | import com.sunyo.wlpt.message.bus.service.service.UserInfoService; | 9 | import com.sunyo.wlpt.message.bus.service.service.UserInfoService; |
10 | import org.apache.commons.lang.StringUtils; | 10 | import org.apache.commons.lang.StringUtils; |
11 | -import org.apache.kafka.clients.admin.AdminClient; | ||
12 | -import org.springframework.beans.factory.annotation.Autowired; | ||
13 | -import org.springframework.stereotype.Service; | ||
14 | import org.springframework.web.bind.annotation.*; | 11 | import org.springframework.web.bind.annotation.*; |
15 | 12 | ||
16 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
@@ -71,13 +71,21 @@ public class RouterController { | @@ -71,13 +71,21 @@ public class RouterController { | ||
71 | int result=messageRouterService.addRouter(messageRouter); | 71 | int result=messageRouterService.addRouter(messageRouter); |
72 | return result>0?new ResultJson("200","路由消息新增成功"):new ResultJson("500","路由消息新增失败"); | 72 | return result>0?new ResultJson("200","路由消息新增成功"):new ResultJson("500","路由消息新增失败"); |
73 | } | 73 | } |
74 | + | ||
75 | + @PostMapping("/addReciverByRouter") | ||
76 | + public ResultJson addReciverByRouter(@RequestBody MessageRouterReciver reciver) { | ||
77 | + | ||
78 | + int result=messageRouterReciverService.addMessageRouterReciver(reciver); | ||
79 | + return result>0?new ResultJson("200","路由消息新增成功"):new ResultJson("500","路由消息新增失败"); | ||
80 | + } | ||
81 | + | ||
74 | @RequestMapping("/delRouter") | 82 | @RequestMapping("/delRouter") |
75 | public ResultJson delRouter(@RequestParam(value = "id", required = false) String id)throws Exception{ | 83 | public ResultJson delRouter(@RequestParam(value = "id", required = false) String id)throws Exception{ |
76 | int result=messageRouterService.delRouter(id); | 84 | int result=messageRouterService.delRouter(id); |
77 | return result>0?new ResultJson("200","路由消息删除成功"):new ResultJson("500","路由消息删除失败"); | 85 | return result>0?new ResultJson("200","路由消息删除成功"):new ResultJson("500","路由消息删除失败"); |
78 | } | 86 | } |
79 | @PutMapping("/ediRouter") | 87 | @PutMapping("/ediRouter") |
80 | - public ResultJson edi(@RequestBody MessageRouter messageRouter)throws Exception { | 88 | + public ResultJson edi(@RequestBody MessageRouter messageRouter){ |
81 | int result=messageRouterService.ediRouter(messageRouter); | 89 | int result=messageRouterService.ediRouter(messageRouter); |
82 | return result>0?new ResultJson("200","路由消息修改成功"):new ResultJson("500","路由消息修改失败"); | 90 | return result>0?new ResultJson("200","路由消息修改成功"):new ResultJson("500","路由消息修改失败"); |
83 | } | 91 | } |
src/main/java/com/sunyo/wlpt/message/bus/service/controller/RouterReceiverController.java
0 → 100644
1 | +package com.sunyo.wlpt.message.bus.service.controller; | ||
2 | + | ||
3 | + | ||
4 | +import com.github.pagehelper.PageInfo; | ||
5 | +import com.sunyo.wlpt.message.bus.service.model.MessageRouter; | ||
6 | +import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver; | ||
7 | +import com.sunyo.wlpt.message.bus.service.response.ResultJson; | ||
8 | +import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverService; | ||
9 | +import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | ||
10 | +import io.swagger.annotations.ApiOperation; | ||
11 | +import org.apache.commons.lang.StringUtils; | ||
12 | +import org.springframework.beans.factory.annotation.Autowired; | ||
13 | +import org.springframework.transaction.annotation.Propagation; | ||
14 | +import org.springframework.transaction.annotation.Transactional; | ||
15 | +import org.springframework.web.bind.annotation.*; | ||
16 | + | ||
17 | +@RequestMapping("/bus/router") | ||
18 | +@RestController | ||
19 | +public class RouterReceiverController { | ||
20 | + | ||
21 | + @Autowired | ||
22 | + MessageRouterReciverService messageRouterReciverService; | ||
23 | + | ||
24 | + | ||
25 | + @ApiOperation(value = "添加路由接收者", notes = "添加路由接收者数组,参数必须要有:路由ID,接收者数组rcvrs") | ||
26 | + @PostMapping("/receiver") | ||
27 | + public ResultJson batchAddRouter(@RequestBody MessageRouter messageRouter){ | ||
28 | + boolean result = messageRouterReciverService.batchAddMessageRouterReciver(messageRouter); | ||
29 | + return result ? new ResultJson("200","success") :new ResultJson("400","添加失败,没有订阅者或出现异常"); | ||
30 | + } | ||
31 | + | ||
32 | + @ApiOperation(value = "删除路由接收者接口", notes = "接收路由接收者对象,根据接收者ID进行删除") | ||
33 | + @DeleteMapping("/receiver") | ||
34 | + public ResultJson del(@RequestBody MessageRouterReciver reciver){ | ||
35 | + boolean result = messageRouterReciverService.delReciver(reciver); | ||
36 | + return result ? new ResultJson("200","success") :new ResultJson("400","添加失败,没有订阅者或出现异常"); | ||
37 | + } | ||
38 | +} |
1 | package com.sunyo.wlpt.message.bus.service.service; | 1 | package com.sunyo.wlpt.message.bus.service.service; |
2 | 2 | ||
3 | +import com.sunyo.wlpt.message.bus.service.model.MessageRouter; | ||
3 | import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver; | 4 | import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver; |
4 | 5 | ||
5 | public interface MessageRouterReciverService { | 6 | public interface MessageRouterReciverService { |
6 | - int addMessageRouterReciver(MessageRouterReciver messageRouterReciver)throws Exception; | 7 | + int addMessageRouterReciver(MessageRouterReciver messageRouterReciver); |
8 | + boolean delReciver(MessageRouterReciver messageRouterReciver); | ||
9 | + boolean batchAddMessageRouterReciver(MessageRouter messageRouter); | ||
7 | } | 10 | } |
@@ -6,7 +6,7 @@ import com.sunyo.wlpt.message.bus.service.model.MessageRouter; | @@ -6,7 +6,7 @@ import com.sunyo.wlpt.message.bus.service.model.MessageRouter; | ||
6 | public interface MessageRouterService { | 6 | public interface MessageRouterService { |
7 | int addRouter(MessageRouter messageRouter)throws Exception; | 7 | int addRouter(MessageRouter messageRouter)throws Exception; |
8 | int delRouter(String id)throws Exception; | 8 | int delRouter(String id)throws Exception; |
9 | - int ediRouter(MessageRouter messageRouter)throws Exception; | 9 | + int ediRouter(MessageRouter messageRouter); |
10 | int selectCountRouter(MessageRouter messageRouter); | 10 | int selectCountRouter(MessageRouter messageRouter); |
11 | PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize)throws Exception; | 11 | PageInfo<MessageRouter> queRouterList(MessageRouter messageRouter,int pageNum,int pageSize)throws Exception; |
12 | } | 12 | } |
@@ -87,7 +87,7 @@ public class MessageRouterImpl implements MessageRouterService { | @@ -87,7 +87,7 @@ public class MessageRouterImpl implements MessageRouterService { | ||
87 | } | 87 | } |
88 | 88 | ||
89 | @Override | 89 | @Override |
90 | - public int ediRouter(MessageRouter messageRouter) throws Exception { | 90 | + public int ediRouter(MessageRouter messageRouter) { |
91 | return messageRouterMapper.updateByPrimaryKeySelective(messageRouter); | 91 | return messageRouterMapper.updateByPrimaryKeySelective(messageRouter); |
92 | } | 92 | } |
93 | 93 |
1 | package com.sunyo.wlpt.message.bus.service.service.impl; | 1 | package com.sunyo.wlpt.message.bus.service.service.impl; |
2 | 2 | ||
3 | import com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverMapper; | 3 | import com.sunyo.wlpt.message.bus.service.mapper.MessageRouterReciverMapper; |
4 | +import com.sunyo.wlpt.message.bus.service.model.MessageRouter; | ||
4 | import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver; | 5 | import com.sunyo.wlpt.message.bus.service.model.MessageRouterReciver; |
6 | +import com.sunyo.wlpt.message.bus.service.response.ResultJson; | ||
5 | import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverService; | 7 | import com.sunyo.wlpt.message.bus.service.service.MessageRouterReciverService; |
8 | +import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | ||
9 | +import org.apache.commons.lang.StringUtils; | ||
6 | import org.springframework.beans.factory.annotation.Autowired; | 10 | import org.springframework.beans.factory.annotation.Autowired; |
7 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
12 | +import org.springframework.transaction.annotation.Transactional; | ||
13 | + | ||
14 | +import javax.annotation.Resource; | ||
8 | 15 | ||
9 | @Service | 16 | @Service |
10 | public class MessageRouterReciverImpl implements MessageRouterReciverService { | 17 | public class MessageRouterReciverImpl implements MessageRouterReciverService { |
11 | - @Autowired | 18 | + |
19 | + @Resource | ||
12 | MessageRouterReciverMapper messageRouterReciverMapper; | 20 | MessageRouterReciverMapper messageRouterReciverMapper; |
21 | + | ||
22 | + | ||
13 | @Override | 23 | @Override |
14 | - public int addMessageRouterReciver(MessageRouterReciver messageRouterReciver) throws Exception { | 24 | + public int addMessageRouterReciver(MessageRouterReciver messageRouterReciver) { |
15 | return messageRouterReciverMapper.insertSelective(messageRouterReciver); | 25 | return messageRouterReciverMapper.insertSelective(messageRouterReciver); |
16 | } | 26 | } |
27 | + | ||
28 | + @Override | ||
29 | + public boolean delReciver(MessageRouterReciver messageRouterReciver) { | ||
30 | + int i = messageRouterReciverMapper.deleteByPrimaryKey(messageRouterReciver.getId()); | ||
31 | + return i>0; | ||
32 | + } | ||
33 | + | ||
34 | + @Override | ||
35 | + @Transactional(rollbackFor = Exception.class) | ||
36 | + public boolean batchAddMessageRouterReciver(MessageRouter messageRouter) { | ||
37 | + int i =0; | ||
38 | + if (StringUtils.isNotBlank(messageRouter.getId())){ | ||
39 | + if (messageRouter.getRcvrs()!=null && !messageRouter.getRcvrs().isEmpty()){ | ||
40 | + // 获取订阅者列表,循环添加 | ||
41 | + for (String rcvr: messageRouter.getRcvrs() | ||
42 | + ) { | ||
43 | + MessageRouterReciver reciver = new MessageRouterReciver(); | ||
44 | + reciver.setRcvrTopic(rcvr); | ||
45 | + reciver.setMessageRouterId(messageRouter.getId()); | ||
46 | + reciver.setId(IdUtils.generateId()); | ||
47 | + i += messageRouterReciverMapper.insertSelective(reciver); | ||
48 | + } | ||
49 | + } | ||
50 | + return i > 0; | ||
51 | + }else { | ||
52 | + return false; | ||
53 | + } | ||
54 | + } | ||
17 | } | 55 | } |
@@ -16,6 +16,7 @@ import org.apache.kafka.common.KafkaFuture; | @@ -16,6 +16,7 @@ import org.apache.kafka.common.KafkaFuture; | ||
16 | import org.apache.kafka.common.PartitionInfo; | 16 | import org.apache.kafka.common.PartitionInfo; |
17 | import org.apache.kafka.common.TopicPartition; | 17 | import org.apache.kafka.common.TopicPartition; |
18 | import org.springframework.beans.factory.annotation.Autowired; | 18 | import org.springframework.beans.factory.annotation.Autowired; |
19 | +import org.springframework.beans.factory.annotation.Qualifier; | ||
19 | import org.springframework.kafka.core.KafkaAdmin; | 20 | import org.springframework.kafka.core.KafkaAdmin; |
20 | import org.springframework.stereotype.Service; | 21 | import org.springframework.stereotype.Service; |
21 | import javax.annotation.Resource; | 22 | import javax.annotation.Resource; |
@@ -34,10 +35,12 @@ public class KafkaServiceImp implements KafkaService { | @@ -34,10 +35,12 @@ public class KafkaServiceImp implements KafkaService { | ||
34 | private BusServerMapper busServerMapper; | 35 | private BusServerMapper busServerMapper; |
35 | 36 | ||
36 | @Autowired | 37 | @Autowired |
37 | - private AdminClient KAFKA_ADMIN_CLIENT ; | 38 | + @Qualifier("myAdminclient") |
39 | + AdminClient KAFKA_ADMIN_CLIENT ; | ||
38 | 40 | ||
39 | @Autowired | 41 | @Autowired |
40 | - private KafkaConsumer KAFKA_CONSUMER; | 42 | + @Qualifier("myConsumer") |
43 | + KafkaConsumer KAFKA_CONSUMER; | ||
41 | 44 | ||
42 | @Resource | 45 | @Resource |
43 | ConsumerGroupMapper consumerGroupMapper; | 46 | ConsumerGroupMapper consumerGroupMapper; |
@@ -160,7 +163,6 @@ public class KafkaServiceImp implements KafkaService { | @@ -160,7 +163,6 @@ public class KafkaServiceImp implements KafkaService { | ||
160 | props.put("enable.auto.commit", "true"); | 163 | props.put("enable.auto.commit", "true"); |
161 | props.put("auto.offset.reset", "earliest"); | 164 | props.put("auto.offset.reset", "earliest"); |
162 | props.put("auto.commit.interval.ms", "1000"); | 165 | props.put("auto.commit.interval.ms", "1000"); |
163 | - props.put("auto.commit.interval.ms", "1000"); | ||
164 | props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); | 166 | props.put("key.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); |
165 | props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); | 167 | props.put("value.deserializer", "org.apache.kafka.common.serialization.StringDeserializer"); |
166 | KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props); | 168 | KafkaConsumer<String, String> consumer = new KafkaConsumer<>(props); |
-
请 注册 或 登录 后发表评论