正在显示
11 个修改的文件
包含
173 行增加
和
18 行删除
| @@ -8,7 +8,9 @@ import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | @@ -8,7 +8,9 @@ import com.sunyo.wlpt.message.bus.service.utils.IdUtils; | ||
| 8 | import org.springframework.web.bind.annotation.*; | 8 | import org.springframework.web.bind.annotation.*; |
| 9 | 9 | ||
| 10 | import javax.annotation.Resource; | 10 | import javax.annotation.Resource; |
| 11 | +import java.io.IOException; | ||
| 11 | import java.util.List; | 12 | import java.util.List; |
| 13 | +import java.util.concurrent.TimeoutException; | ||
| 12 | 14 | ||
| 13 | import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_ROUTINGKEY_INFO; | 15 | import static com.sunyo.wlpt.message.bus.service.common.Constant.EXIST_ROUTINGKEY_INFO; |
| 14 | 16 | ||
| @@ -39,7 +41,8 @@ public class RoutingKeyController { | @@ -39,7 +41,8 @@ public class RoutingKeyController { | ||
| 39 | @RequestParam(value = "routingKeyName", required = false) String routingKeyName, | 41 | @RequestParam(value = "routingKeyName", required = false) String routingKeyName, |
| 40 | @RequestParam(value = "exchangeId", required = false) String exchangeId, | 42 | @RequestParam(value = "exchangeId", required = false) String exchangeId, |
| 41 | @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, | 43 | @RequestParam(value = "pageNum", defaultValue = "1") Integer pageNum, |
| 42 | - @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) { | 44 | + @RequestParam(value = "pageSize", defaultValue = "10") Integer pageSize) |
| 45 | + { | ||
| 43 | // 获取查询参数 | 46 | // 获取查询参数 |
| 44 | RoutingKey routingKey = RoutingKey.builder().routingKeyName(routingKeyName).exchangeId(exchangeId).build(); | 47 | RoutingKey routingKey = RoutingKey.builder().routingKeyName(routingKeyName).exchangeId(exchangeId).build(); |
| 45 | // 分页查询 | 48 | // 分页查询 |
| @@ -56,8 +59,8 @@ public class RoutingKeyController { | @@ -56,8 +59,8 @@ public class RoutingKeyController { | ||
| 56 | * @return {@link ResultJson} | 59 | * @return {@link ResultJson} |
| 57 | */ | 60 | */ |
| 58 | @DeleteMapping("/delete") | 61 | @DeleteMapping("/delete") |
| 59 | - public ResultJson deleteRoutingKey(@RequestBody RoutingKey routingKey) { | ||
| 60 | - | 62 | + public ResultJson deleteRoutingKey(@RequestBody RoutingKey routingKey) throws IOException, TimeoutException |
| 63 | + { | ||
| 61 | return routingKeyService.deleteByPrimaryKey(routingKey.getId()) > 0 | 64 | return routingKeyService.deleteByPrimaryKey(routingKey.getId()) > 0 |
| 62 | ? new ResultJson<>("200", "删除路由键,成功") | 65 | ? new ResultJson<>("200", "删除路由键,成功") |
| 63 | : new ResultJson<>("500", "删除路由键,失败"); | 66 | : new ResultJson<>("500", "删除路由键,失败"); |
| @@ -70,8 +73,8 @@ public class RoutingKeyController { | @@ -70,8 +73,8 @@ public class RoutingKeyController { | ||
| 70 | * @return {@link ResultJson} | 73 | * @return {@link ResultJson} |
| 71 | */ | 74 | */ |
| 72 | @GetMapping("/batchRemove") | 75 | @GetMapping("/batchRemove") |
| 73 | - public ResultJson batchRemoveRoutingKey(String ids) { | ||
| 74 | - | 76 | + public ResultJson batchRemoveRoutingKey(String ids) throws IOException, TimeoutException |
| 77 | + { | ||
| 75 | return routingKeyService.deleteByPrimaryKey(ids) > 0 | 78 | return routingKeyService.deleteByPrimaryKey(ids) > 0 |
| 76 | ? new ResultJson<>("200", "删除路由键,成功") | 79 | ? new ResultJson<>("200", "删除路由键,成功") |
| 77 | : new ResultJson<>("500", "删除路由键,失败"); | 80 | : new ResultJson<>("500", "删除路由键,失败"); |
| @@ -84,7 +87,8 @@ public class RoutingKeyController { | @@ -84,7 +87,8 @@ public class RoutingKeyController { | ||
| 84 | * @return {@link ResultJson} | 87 | * @return {@link ResultJson} |
| 85 | */ | 88 | */ |
| 86 | @PutMapping("/update") | 89 | @PutMapping("/update") |
| 87 | - public ResultJson updateRoutingKey(@RequestBody RoutingKey routingKey) { | 90 | + public ResultJson updateRoutingKey(@RequestBody RoutingKey routingKey) |
| 91 | + { | ||
| 88 | 92 | ||
| 89 | //先验证,修改好的核心信息(路由键名称)是否已存在 | 93 | //先验证,修改好的核心信息(路由键名称)是否已存在 |
| 90 | String message = validateRoutingKey(routingKey); | 94 | String message = validateRoutingKey(routingKey); |
| @@ -102,7 +106,8 @@ public class RoutingKeyController { | @@ -102,7 +106,8 @@ public class RoutingKeyController { | ||
| 102 | * @return {@link ResultJson} | 106 | * @return {@link ResultJson} |
| 103 | */ | 107 | */ |
| 104 | @PostMapping("/insert") | 108 | @PostMapping("/insert") |
| 105 | - public ResultJson insertRoutingKey(@RequestBody RoutingKey routingKey) { | 109 | + public ResultJson insertRoutingKey(@RequestBody RoutingKey routingKey) |
| 110 | + { | ||
| 106 | 111 | ||
| 107 | //先验证,增加的服务器的核心信息(ip和port,同时存在)是否已存在 | 112 | //先验证,增加的服务器的核心信息(ip和port,同时存在)是否已存在 |
| 108 | String message = validateRoutingKey(routingKey); | 113 | String message = validateRoutingKey(routingKey); |
| @@ -122,7 +127,8 @@ public class RoutingKeyController { | @@ -122,7 +127,8 @@ public class RoutingKeyController { | ||
| 122 | * @param routingKey {@link RoutingKey} | 127 | * @param routingKey {@link RoutingKey} |
| 123 | * @return 通过,无返回消息 | 128 | * @return 通过,无返回消息 |
| 124 | */ | 129 | */ |
| 125 | - private String validateRoutingKey(RoutingKey routingKey) { | 130 | + private String validateRoutingKey(RoutingKey routingKey) |
| 131 | + { | ||
| 126 | if ("".equals(routingKey.getRoutingKeyName()) || routingKey.getRoutingKeyName() == null) { | 132 | if ("".equals(routingKey.getRoutingKeyName()) || routingKey.getRoutingKeyName() == null) { |
| 127 | return "该路由键信息中,没有路由键名称"; | 133 | return "该路由键信息中,没有路由键名称"; |
| 128 | } | 134 | } |
| @@ -2,6 +2,7 @@ package com.sunyo.wlpt.message.bus.service.mapper; | @@ -2,6 +2,7 @@ package com.sunyo.wlpt.message.bus.service.mapper; | ||
| 2 | 2 | ||
| 3 | import com.sunyo.wlpt.message.bus.service.domain.RoutingKey; | 3 | import com.sunyo.wlpt.message.bus.service.domain.RoutingKey; |
| 4 | import org.apache.ibatis.annotations.Mapper; | 4 | import org.apache.ibatis.annotations.Mapper; |
| 5 | +import org.apache.ibatis.annotations.Param; | ||
| 5 | 6 | ||
| 6 | import java.util.List; | 7 | import java.util.List; |
| 7 | 8 | ||
| @@ -86,6 +87,14 @@ public interface RoutingKeyMapper { | @@ -86,6 +87,14 @@ public interface RoutingKeyMapper { | ||
| 86 | List<RoutingKey> getRoutingKeyList(RoutingKey routingKey); | 87 | List<RoutingKey> getRoutingKeyList(RoutingKey routingKey); |
| 87 | 88 | ||
| 88 | /** | 89 | /** |
| 90 | + * 根据exchangeID查询路由键 | ||
| 91 | + * | ||
| 92 | + * @param exchangeId 交换机id | ||
| 93 | + * @return | ||
| 94 | + */ | ||
| 95 | + List<RoutingKey> selectByExchangeId(@Param("exchangeId") String exchangeId); | ||
| 96 | + | ||
| 97 | + /** | ||
| 89 | * 检验路由键是否存在,根据交换机id和路由键名称 | 98 | * 检验路由键是否存在,根据交换机id和路由键名称 |
| 90 | * | 99 | * |
| 91 | * @param routingKey 路由键 | 100 | * @param routingKey 路由键 |
| @@ -39,6 +39,14 @@ public interface UserMessageBindingMapper { | @@ -39,6 +39,14 @@ public interface UserMessageBindingMapper { | ||
| 39 | int deleteByQueueId(String queueId); | 39 | int deleteByQueueId(String queueId); |
| 40 | 40 | ||
| 41 | /** | 41 | /** |
| 42 | + * 根据路由键id删除配置关系 | ||
| 43 | + * | ||
| 44 | + * @param routingKeyId 路由键id | ||
| 45 | + * @return 删除成功 | ||
| 46 | + */ | ||
| 47 | + int deleteByRoutingKeyId(String routingKeyId); | ||
| 48 | + | ||
| 49 | + /** | ||
| 42 | * insert record to table | 50 | * insert record to table |
| 43 | * | 51 | * |
| 44 | * @param record the record | 52 | * @param record the record |
| @@ -63,6 +71,14 @@ public interface UserMessageBindingMapper { | @@ -63,6 +71,14 @@ public interface UserMessageBindingMapper { | ||
| 63 | UserMessageBinding selectByPrimaryKey(String id); | 71 | UserMessageBinding selectByPrimaryKey(String id); |
| 64 | 72 | ||
| 65 | /** | 73 | /** |
| 74 | + * 根据路由键id | ||
| 75 | + * | ||
| 76 | + * @param routingKeyId 路由键id | ||
| 77 | + * @return | ||
| 78 | + */ | ||
| 79 | + List<UserMessageBinding> selectByRoutingKeyId(String routingKeyId); | ||
| 80 | + | ||
| 81 | + /** | ||
| 66 | * update record selective | 82 | * update record selective |
| 67 | * | 83 | * |
| 68 | * @param record the updated record | 84 | * @param record the updated record |
| @@ -2,8 +2,11 @@ package com.sunyo.wlpt.message.bus.service.service; | @@ -2,8 +2,11 @@ package com.sunyo.wlpt.message.bus.service.service; | ||
| 2 | 2 | ||
| 3 | import com.github.pagehelper.PageInfo; | 3 | import com.github.pagehelper.PageInfo; |
| 4 | import com.sunyo.wlpt.message.bus.service.domain.RoutingKey; | 4 | import com.sunyo.wlpt.message.bus.service.domain.RoutingKey; |
| 5 | +import org.apache.ibatis.annotations.Param; | ||
| 5 | 6 | ||
| 7 | +import java.io.IOException; | ||
| 6 | import java.util.List; | 8 | import java.util.List; |
| 9 | +import java.util.concurrent.TimeoutException; | ||
| 7 | 10 | ||
| 8 | /** | 11 | /** |
| 9 | * @author 子诚 | 12 | * @author 子诚 |
| @@ -18,7 +21,7 @@ public interface RoutingKeyService { | @@ -18,7 +21,7 @@ public interface RoutingKeyService { | ||
| 18 | * @param id primaryKey | 21 | * @param id primaryKey |
| 19 | * @return deleteCount | 22 | * @return deleteCount |
| 20 | */ | 23 | */ |
| 21 | - int deleteByPrimaryKey(String id); | 24 | + int deleteByPrimaryKey(String id) throws IOException, TimeoutException; |
| 22 | 25 | ||
| 23 | /** | 26 | /** |
| 24 | * 根据交换机id,删除路由键信息 | 27 | * 根据交换机id,删除路由键信息 |
| @@ -53,6 +56,14 @@ public interface RoutingKeyService { | @@ -53,6 +56,14 @@ public interface RoutingKeyService { | ||
| 53 | RoutingKey selectByPrimaryKey(String id); | 56 | RoutingKey selectByPrimaryKey(String id); |
| 54 | 57 | ||
| 55 | /** | 58 | /** |
| 59 | + * 根据exchangeID查询路由键 | ||
| 60 | + * | ||
| 61 | + * @param exchangeId 交换机id | ||
| 62 | + * @return | ||
| 63 | + */ | ||
| 64 | + List<RoutingKey> selectByExchangeId(@Param("exchangeId") String exchangeId); | ||
| 65 | + | ||
| 66 | + /** | ||
| 56 | * 更新,选择性,根据主键 | 67 | * 更新,选择性,根据主键 |
| 57 | * | 68 | * |
| 58 | * @param record the updated record | 69 | * @param record the updated record |
| @@ -5,6 +5,7 @@ import com.sunyo.wlpt.message.bus.service.domain.UserMessageBinding; | @@ -5,6 +5,7 @@ import com.sunyo.wlpt.message.bus.service.domain.UserMessageBinding; | ||
| 5 | import com.sunyo.wlpt.message.bus.service.domain.XmlData; | 5 | import com.sunyo.wlpt.message.bus.service.domain.XmlData; |
| 6 | 6 | ||
| 7 | import java.io.IOException; | 7 | import java.io.IOException; |
| 8 | +import java.util.List; | ||
| 8 | import java.util.concurrent.TimeoutException; | 9 | import java.util.concurrent.TimeoutException; |
| 9 | 10 | ||
| 10 | /** | 11 | /** |
| @@ -30,6 +31,14 @@ public interface UserMessageBindingService { | @@ -30,6 +31,14 @@ public interface UserMessageBindingService { | ||
| 30 | int deleteByExchangeId(String exchangeId); | 31 | int deleteByExchangeId(String exchangeId); |
| 31 | 32 | ||
| 32 | /** | 33 | /** |
| 34 | + * 根据路由键id删除配置关系 | ||
| 35 | + * | ||
| 36 | + * @param routingKeyId 路由键id | ||
| 37 | + * @return 删除成功 | ||
| 38 | + */ | ||
| 39 | + int deleteByRoutingKeyId(String routingKeyId); | ||
| 40 | + | ||
| 41 | + /** | ||
| 33 | * 根据队列Id,删除绑定关系 | 42 | * 根据队列Id,删除绑定关系 |
| 34 | * | 43 | * |
| 35 | * @param queueId 队列id | 44 | * @param queueId 队列id |
| @@ -94,6 +103,14 @@ public interface UserMessageBindingService { | @@ -94,6 +103,14 @@ public interface UserMessageBindingService { | ||
| 94 | * @return true or false | 103 | * @return true or false |
| 95 | */ | 104 | */ |
| 96 | Boolean validateXmlBinding(XmlData xmlData); | 105 | Boolean validateXmlBinding(XmlData xmlData); |
| 106 | + | ||
| 107 | + /** | ||
| 108 | + * 根据路由键id | ||
| 109 | + * | ||
| 110 | + * @param routingKeyId 路由键id | ||
| 111 | + * @return | ||
| 112 | + */ | ||
| 113 | + List<UserMessageBinding> selectByRoutingKeyId(String routingKeyId); | ||
| 97 | } | 114 | } |
| 98 | 115 | ||
| 99 | 116 |
| 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.domain.BusExchange; | ||
| 4 | -import com.sunyo.wlpt.message.bus.service.domain.BusQueue; | ||
| 5 | -import com.sunyo.wlpt.message.bus.service.domain.XmlData; | 3 | +import com.sunyo.wlpt.message.bus.service.domain.*; |
| 4 | +import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; | ||
| 6 | import com.sunyo.wlpt.message.bus.service.service.MessageNoteService; | 5 | import com.sunyo.wlpt.message.bus.service.service.MessageNoteService; |
| 7 | import com.sunyo.wlpt.message.bus.service.service.RoutingKeyService; | 6 | import com.sunyo.wlpt.message.bus.service.service.RoutingKeyService; |
| 8 | import com.sunyo.wlpt.message.bus.service.service.UserMessageBindingService; | 7 | import com.sunyo.wlpt.message.bus.service.service.UserMessageBindingService; |
| 9 | import org.springframework.scheduling.annotation.Async; | 8 | import org.springframework.scheduling.annotation.Async; |
| 10 | -import org.springframework.stereotype.Component; | 9 | +import org.springframework.stereotype.Service; |
| 10 | +import org.springframework.transaction.annotation.Propagation; | ||
| 11 | +import org.springframework.transaction.annotation.Transactional; | ||
| 11 | 12 | ||
| 12 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
| 14 | +import java.io.IOException; | ||
| 15 | +import java.util.List; | ||
| 16 | +import java.util.concurrent.TimeoutException; | ||
| 13 | 17 | ||
| 14 | /** | 18 | /** |
| 15 | * @author 子诚 | 19 | * @author 子诚 |
| @@ -17,10 +21,13 @@ import javax.annotation.Resource; | @@ -17,10 +21,13 @@ import javax.annotation.Resource; | ||
| 17 | * 注意点:异步任务需要单独放在一个类中 | 21 | * 注意点:异步任务需要单独放在一个类中 |
| 18 | * 时间:2020/7/30 15:59 | 22 | * 时间:2020/7/30 15:59 |
| 19 | */ | 23 | */ |
| 20 | -@Component | 24 | +@Service |
| 21 | public class AsyncTaskService { | 25 | public class AsyncTaskService { |
| 22 | 26 | ||
| 23 | @Resource | 27 | @Resource |
| 28 | + private RabbitUtils rabbitUtils; | ||
| 29 | + | ||
| 30 | + @Resource | ||
| 24 | private MessageNoteService messageNoteService; | 31 | private MessageNoteService messageNoteService; |
| 25 | 32 | ||
| 26 | @Resource | 33 | @Resource |
| @@ -53,15 +60,42 @@ public class AsyncTaskService { | @@ -53,15 +60,42 @@ public class AsyncTaskService { | ||
| 53 | 60 | ||
| 54 | /** | 61 | /** |
| 55 | * 当删除交换机的时候, | 62 | * 当删除交换机的时候, |
| 63 | + * <p> | ||
| 56 | * 同时,删除对应的路由键,删除包含交换机的绑定关系 | 64 | * 同时,删除对应的路由键,删除包含交换机的绑定关系 |
| 65 | + * <p> | ||
| 66 | + * 同时,删除包含该路由键的绑定关系 | ||
| 57 | */ | 67 | */ |
| 58 | @Async | 68 | @Async |
| 69 | + @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) | ||
| 59 | void exchangeCascadeDelete(BusExchange busExchange) | 70 | void exchangeCascadeDelete(BusExchange busExchange) |
| 60 | { | 71 | { |
| 72 | + String exchangeId = busExchange.getId(); | ||
| 73 | + List<RoutingKey> routingKeyList = routingKeyService.selectByExchangeId(exchangeId); | ||
| 61 | // 删除相关路由键 | 74 | // 删除相关路由键 |
| 62 | - routingKeyService.deleteByExchangeId(busExchange.getId()); | ||
| 63 | - // 删除相关配置关系 | ||
| 64 | - userMessageBindingService.deleteByExchangeId(busExchange.getId()); | 75 | + routingKeyService.deleteByExchangeId(exchangeId); |
| 76 | + // 删除交换机相关配置关系 | ||
| 77 | + userMessageBindingService.deleteByExchangeId(exchangeId); | ||
| 78 | + // 删除路由键相关配置关系 | ||
| 79 | + for (int i = 0; i < routingKeyList.size(); i++) { | ||
| 80 | + userMessageBindingService.deleteByRoutingKeyId(routingKeyList.get(0).getId()); | ||
| 81 | + } | ||
| 82 | + } | ||
| 83 | + | ||
| 84 | + /** | ||
| 85 | + * 当删除路由键的时候,删除包含该路由键的配置关系 | ||
| 86 | + */ | ||
| 87 | + @Async | ||
| 88 | + void routingKeyCascadeDelete(RoutingKey routingKey) throws IOException, TimeoutException | ||
| 89 | + { | ||
| 90 | + String routingKeyId = routingKey.getId(); | ||
| 91 | + // 根据路由键id查询出所有的包含该路由键的配置关系 | ||
| 92 | + List<UserMessageBinding> bindings = userMessageBindingService.selectByRoutingKeyId(routingKeyId); | ||
| 93 | + for (UserMessageBinding userMessageBinding : bindings) { | ||
| 94 | + // 解除MQ服务器上的配置关系 | ||
| 95 | + rabbitUtils.toRemoveBinding(userMessageBinding); | ||
| 96 | + } | ||
| 97 | + // 删除数据库中的包含该路由键相关配置关系 | ||
| 98 | + userMessageBindingService.deleteByRoutingKeyId(routingKey.getId()); | ||
| 65 | } | 99 | } |
| 66 | 100 | ||
| 67 | /** | 101 | /** |
| @@ -7,6 +7,7 @@ import com.sunyo.wlpt.message.bus.service.mapper.BusQueueMapper; | @@ -7,6 +7,7 @@ import com.sunyo.wlpt.message.bus.service.mapper.BusQueueMapper; | ||
| 7 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; | 7 | import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils; |
| 8 | import com.sunyo.wlpt.message.bus.service.service.BusQueueService; | 8 | import com.sunyo.wlpt.message.bus.service.service.BusQueueService; |
| 9 | import io.netty.util.internal.StringUtil; | 9 | import io.netty.util.internal.StringUtil; |
| 10 | +import org.springframework.context.annotation.Lazy; | ||
| 10 | import org.springframework.stereotype.Service; | 11 | import org.springframework.stereotype.Service; |
| 11 | import org.springframework.transaction.annotation.Propagation; | 12 | import org.springframework.transaction.annotation.Propagation; |
| 12 | import org.springframework.transaction.annotation.Transactional; | 13 | import org.springframework.transaction.annotation.Transactional; |
| @@ -31,6 +32,7 @@ public class BusQueueServiceImpl implements BusQueueService { | @@ -31,6 +32,7 @@ public class BusQueueServiceImpl implements BusQueueService { | ||
| 31 | @Resource | 32 | @Resource |
| 32 | private RabbitUtils rabbitUtils; | 33 | private RabbitUtils rabbitUtils; |
| 33 | 34 | ||
| 35 | + @Lazy | ||
| 34 | @Resource | 36 | @Resource |
| 35 | private AsyncTaskService asyncTaskService; | 37 | private AsyncTaskService asyncTaskService; |
| 36 | 38 |
| @@ -5,13 +5,16 @@ import com.github.pagehelper.PageInfo; | @@ -5,13 +5,16 @@ import com.github.pagehelper.PageInfo; | ||
| 5 | import com.sunyo.wlpt.message.bus.service.domain.RoutingKey; | 5 | import com.sunyo.wlpt.message.bus.service.domain.RoutingKey; |
| 6 | import com.sunyo.wlpt.message.bus.service.mapper.RoutingKeyMapper; | 6 | import com.sunyo.wlpt.message.bus.service.mapper.RoutingKeyMapper; |
| 7 | import com.sunyo.wlpt.message.bus.service.service.RoutingKeyService; | 7 | import com.sunyo.wlpt.message.bus.service.service.RoutingKeyService; |
| 8 | +import org.springframework.context.annotation.Lazy; | ||
| 8 | import org.springframework.stereotype.Service; | 9 | import org.springframework.stereotype.Service; |
| 9 | import org.springframework.transaction.annotation.Propagation; | 10 | import org.springframework.transaction.annotation.Propagation; |
| 10 | import org.springframework.transaction.annotation.Transactional; | 11 | import org.springframework.transaction.annotation.Transactional; |
| 11 | 12 | ||
| 12 | import javax.annotation.Resource; | 13 | import javax.annotation.Resource; |
| 14 | +import java.io.IOException; | ||
| 13 | import java.util.ArrayList; | 15 | import java.util.ArrayList; |
| 14 | import java.util.List; | 16 | import java.util.List; |
| 17 | +import java.util.concurrent.TimeoutException; | ||
| 15 | 18 | ||
| 16 | /** | 19 | /** |
| 17 | * @author 子诚 | 20 | * @author 子诚 |
| @@ -21,12 +24,16 @@ import java.util.List; | @@ -21,12 +24,16 @@ import java.util.List; | ||
| 21 | @Service | 24 | @Service |
| 22 | public class RoutingKeyServiceImpl implements RoutingKeyService { | 25 | public class RoutingKeyServiceImpl implements RoutingKeyService { |
| 23 | 26 | ||
| 27 | + @Lazy | ||
| 28 | + @Resource | ||
| 29 | + private AsyncTaskService asyncTaskService; | ||
| 30 | + | ||
| 24 | @Resource | 31 | @Resource |
| 25 | private RoutingKeyMapper routingKeyMapper; | 32 | private RoutingKeyMapper routingKeyMapper; |
| 26 | 33 | ||
| 27 | @Override | 34 | @Override |
| 28 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) | 35 | @Transactional(rollbackFor = Exception.class, propagation = Propagation.REQUIRED) |
| 29 | - public int deleteByPrimaryKey(String id) | 36 | + public int deleteByPrimaryKey(String id) throws IOException, TimeoutException |
| 30 | { | 37 | { |
| 31 | // 判断删除的个数,需被删除的个数是否一致 | 38 | // 判断删除的个数,需被删除的个数是否一致 |
| 32 | int index = 0; | 39 | int index = 0; |
| @@ -35,6 +42,9 @@ public class RoutingKeyServiceImpl implements RoutingKeyService { | @@ -35,6 +42,9 @@ public class RoutingKeyServiceImpl implements RoutingKeyService { | ||
| 35 | if (id.contains(splitItem)) { | 42 | if (id.contains(splitItem)) { |
| 36 | String[] split = id.split(splitItem); | 43 | String[] split = id.split(splitItem); |
| 37 | for (int i = 0; i < split.length; i++) { | 44 | for (int i = 0; i < split.length; i++) { |
| 45 | + RoutingKey routingKey = routingKeyMapper.selectByPrimaryKey(split[i]); | ||
| 46 | + // 异步,级联删除包含该路由键的配置关系 | ||
| 47 | + asyncTaskService.routingKeyCascadeDelete(routingKey); | ||
| 38 | int num = routingKeyMapper.deleteByPrimaryKey(split[i]); | 48 | int num = routingKeyMapper.deleteByPrimaryKey(split[i]); |
| 39 | if (num > 0) { | 49 | if (num > 0) { |
| 40 | index = index + num; | 50 | index = index + num; |
| @@ -46,6 +56,9 @@ public class RoutingKeyServiceImpl implements RoutingKeyService { | @@ -46,6 +56,9 @@ public class RoutingKeyServiceImpl implements RoutingKeyService { | ||
| 46 | return 0; | 56 | return 0; |
| 47 | } | 57 | } |
| 48 | } else { | 58 | } else { |
| 59 | + RoutingKey routingKey = routingKeyMapper.selectByPrimaryKey(id); | ||
| 60 | + // 异步,级联删除包含该路由键的配置关系 | ||
| 61 | + asyncTaskService.routingKeyCascadeDelete(routingKey); | ||
| 49 | return routingKeyMapper.deleteByPrimaryKey(id); | 62 | return routingKeyMapper.deleteByPrimaryKey(id); |
| 50 | } | 63 | } |
| 51 | } | 64 | } |
| @@ -75,6 +88,12 @@ public class RoutingKeyServiceImpl implements RoutingKeyService { | @@ -75,6 +88,12 @@ public class RoutingKeyServiceImpl implements RoutingKeyService { | ||
| 75 | } | 88 | } |
| 76 | 89 | ||
| 77 | @Override | 90 | @Override |
| 91 | + public List<RoutingKey> selectByExchangeId(String exchangeId) | ||
| 92 | + { | ||
| 93 | + return routingKeyMapper.selectByExchangeId(exchangeId); | ||
| 94 | + } | ||
| 95 | + | ||
| 96 | + @Override | ||
| 78 | public int updateByPrimaryKeySelective(RoutingKey record) | 97 | public int updateByPrimaryKeySelective(RoutingKey record) |
| 79 | { | 98 | { |
| 80 | return routingKeyMapper.updateByPrimaryKeySelective(record); | 99 | return routingKeyMapper.updateByPrimaryKeySelective(record); |
| @@ -435,6 +435,18 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | @@ -435,6 +435,18 @@ public class UserMessageBindingServiceImpl implements UserMessageBindingService | ||
| 435 | { | 435 | { |
| 436 | return userMessageBindingMapper.deleteByQueueId(queueId); | 436 | return userMessageBindingMapper.deleteByQueueId(queueId); |
| 437 | } | 437 | } |
| 438 | + | ||
| 439 | + @Override | ||
| 440 | + public int deleteByRoutingKeyId(String routingKeyId) | ||
| 441 | + { | ||
| 442 | + return userMessageBindingMapper.deleteByRoutingKeyId(routingKeyId); | ||
| 443 | + } | ||
| 444 | + | ||
| 445 | + @Override | ||
| 446 | + public List<UserMessageBinding> selectByRoutingKeyId(String routingKeyId) | ||
| 447 | + { | ||
| 448 | + return userMessageBindingMapper.selectByRoutingKeyId(routingKeyId); | ||
| 449 | + } | ||
| 438 | } | 450 | } |
| 439 | 451 | ||
| 440 | 452 |
| @@ -85,6 +85,18 @@ | @@ -85,6 +85,18 @@ | ||
| 85 | </where> | 85 | </where> |
| 86 | </select> | 86 | </select> |
| 87 | 87 | ||
| 88 | + <select id="selectByExchangeId" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
| 89 | + select | ||
| 90 | + <include refid="Base_Column_List"/> | ||
| 91 | + from routing_key | ||
| 92 | + <where> | ||
| 93 | + <!-- 所属交换机ID --> | ||
| 94 | + <if test="exchangeId != null and exchangeId != ''"> | ||
| 95 | + exchange_id = #{exchangeId,jdbcType=VARCHAR} | ||
| 96 | + </if> | ||
| 97 | + </where> | ||
| 98 | + </select> | ||
| 99 | + | ||
| 88 | <select id="selectRoutingKeyExist" parameterType="com.sunyo.wlpt.message.bus.service.domain.RoutingKey" | 100 | <select id="selectRoutingKeyExist" parameterType="com.sunyo.wlpt.message.bus.service.domain.RoutingKey" |
| 89 | resultMap="BaseResultMap"> | 101 | resultMap="BaseResultMap"> |
| 90 | select | 102 | select |
| @@ -34,6 +34,14 @@ | @@ -34,6 +34,14 @@ | ||
| 34 | where id = #{id,jdbcType=VARCHAR} | 34 | where id = #{id,jdbcType=VARCHAR} |
| 35 | </select> | 35 | </select> |
| 36 | 36 | ||
| 37 | + <select id="selectByRoutingKeyId" parameterType="java.lang.String" resultMap="BaseResultMap"> | ||
| 38 | + <!--@mbg.generated--> | ||
| 39 | + select | ||
| 40 | + <include refid="Base_Column_List"/> | ||
| 41 | + from user_message_binding | ||
| 42 | + where routing_key_id = #{routingKeyId,jdbcType=VARCHAR} | ||
| 43 | + </select> | ||
| 44 | + | ||
| 37 | <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> | 45 | <delete id="deleteByPrimaryKey" parameterType="java.lang.String"> |
| 38 | <!--@mbg.generated--> | 46 | <!--@mbg.generated--> |
| 39 | delete | 47 | delete |
| @@ -56,6 +64,15 @@ | @@ -56,6 +64,15 @@ | ||
| 56 | from user_message_binding | 64 | from user_message_binding |
| 57 | where queue_id = #{queueId,jdbcType=VARCHAR} | 65 | where queue_id = #{queueId,jdbcType=VARCHAR} |
| 58 | </delete> | 66 | </delete> |
| 67 | + | ||
| 68 | + <!-- 根据路由键id,删除配置关系--> | ||
| 69 | + <delete id="deleteByRoutingKeyId" parameterType="java.lang.String"> | ||
| 70 | + <!--@mbg.generated--> | ||
| 71 | + delete | ||
| 72 | + from user_message_binding | ||
| 73 | + where routing_key_id = #{routingKeyId,jdbcType=VARCHAR} | ||
| 74 | + </delete> | ||
| 75 | + | ||
| 59 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserMessageBinding"> | 76 | <insert id="insert" parameterType="com.sunyo.wlpt.message.bus.service.domain.UserMessageBinding"> |
| 60 | <!--@mbg.generated--> | 77 | <!--@mbg.generated--> |
| 61 | insert into user_message_binding (id, user_id, username, | 78 | insert into user_message_binding (id, user_id, username, |
-
请 注册 或 登录 后发表评论