...
|
...
|
@@ -2,10 +2,10 @@ package com.sunyo.wlpt.message.bus.service.service.impl; |
|
|
|
|
|
import com.github.pagehelper.PageHelper;
|
|
|
import com.github.pagehelper.PageInfo;
|
|
|
import com.sunyo.wlpt.message.bus.service.domain.BusServer;
|
|
|
import com.sunyo.wlpt.message.bus.service.domain.*;
|
|
|
import com.sunyo.wlpt.message.bus.service.mapper.BusServerMapper;
|
|
|
import com.sunyo.wlpt.message.bus.service.service.BusServerService;
|
|
|
import org.springframework.context.annotation.Lazy;
|
|
|
import com.sunyo.wlpt.message.bus.service.rabbit.utils.RabbitUtils;
|
|
|
import com.sunyo.wlpt.message.bus.service.service.*;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.transaction.annotation.Propagation;
|
|
|
import org.springframework.transaction.annotation.Transactional;
|
...
|
...
|
@@ -24,11 +24,26 @@ import java.util.concurrent.TimeoutException; |
|
|
public class BusServerServiceImpl implements BusServerService {
|
|
|
|
|
|
@Resource
|
|
|
private BusServerMapper busServerMapper;
|
|
|
private RabbitUtils rabbitUtils;
|
|
|
|
|
|
@Resource
|
|
|
private RoutingKeyService routingKeyService;
|
|
|
|
|
|
@Resource
|
|
|
private UserMessageBindingService userMessageBindingService;
|
|
|
|
|
|
@Resource
|
|
|
private BusQueueService busQueueService;
|
|
|
|
|
|
@Resource
|
|
|
private BusExchangeService busExchangeService;
|
|
|
|
|
|
@Resource
|
|
|
private VirtualHostService virtualHostService;
|
|
|
|
|
|
@Lazy
|
|
|
@Resource
|
|
|
private AsyncTaskService asyncTaskService;
|
|
|
private BusServerMapper busServerMapper;
|
|
|
|
|
|
|
|
|
@Override
|
|
|
public PageInfo selectBusServerList(BusServer busServer, Integer pageNum, Integer pageSize)
|
...
|
...
|
@@ -58,9 +73,9 @@ public class BusServerServiceImpl implements BusServerService { |
|
|
String[] split = id.split(splitItem);
|
|
|
for (int i = 0; i < split.length; i++) {
|
|
|
BusServer busServer = busServerMapper.selectByPrimaryKey(split[i]);
|
|
|
// 级联删除与该服务器相关的:虚拟主机,配置关系,队列,交换机,路由键
|
|
|
serverCascadeDelete(busServer);
|
|
|
int num = busServerMapper.deleteByPrimaryKey(split[i]);
|
|
|
// 异步删除与该服务器相关的:虚拟主机,配置关系,队列,交换机,路由键
|
|
|
asyncTaskService.serverCascadeDelete(busServer);
|
|
|
if (num > 0) {
|
|
|
index = index + num;
|
|
|
}
|
...
|
...
|
@@ -72,10 +87,9 @@ public class BusServerServiceImpl implements BusServerService { |
|
|
}
|
|
|
} else {
|
|
|
BusServer busServer = busServerMapper.selectByPrimaryKey(id);
|
|
|
int num = busServerMapper.deleteByPrimaryKey(id);
|
|
|
// 异步删除与该服务器相关的:虚拟主机,配置关系,队列,交换机,路由键
|
|
|
asyncTaskService.serverCascadeDelete(busServer);
|
|
|
return num;
|
|
|
// 级联删除与该服务器相关的:虚拟主机,配置关系,队列,交换机,路由键
|
|
|
serverCascadeDelete(busServer);
|
|
|
return busServerMapper.deleteByPrimaryKey(id);
|
|
|
}
|
|
|
}
|
|
|
|
...
|
...
|
@@ -138,4 +152,39 @@ public class BusServerServiceImpl implements BusServerService { |
|
|
{
|
|
|
return busServerMapper.selectServerExist(serverName);
|
|
|
}
|
|
|
|
|
|
public void serverCascadeDelete(BusServer busServer) throws IOException, TimeoutException
|
|
|
{
|
|
|
String serverId = busServer.getId();
|
|
|
List<UserMessageBinding> bindings = userMessageBindingService.selectByServerId(serverId);
|
|
|
// 1.1 删除数据库中的绑定关系
|
|
|
userMessageBindingService.deleteByServerId(serverId);
|
|
|
for (UserMessageBinding userMessageBinding : bindings) {
|
|
|
// 1.2、解除MQ服务器上的绑定关系
|
|
|
rabbitUtils.toRemoveBinding(userMessageBinding);
|
|
|
}
|
|
|
List<VirtualHost> virtualHostList = virtualHostService.selectByServerId(serverId);
|
|
|
for (VirtualHost virtualHost : virtualHostList) {
|
|
|
String virtualHostId = virtualHost.getId();
|
|
|
List<BusQueue> queues = busQueueService.selectByVirtualHostId(virtualHostId);
|
|
|
// 3.1、删除数据库中对应的队列
|
|
|
busQueueService.deleteByVirtualHostId(virtualHostId);
|
|
|
for (BusQueue queue : queues) {
|
|
|
// 3.2、删除MQ服务器上的队列
|
|
|
rabbitUtils.toRemoveQueue(queue);
|
|
|
}
|
|
|
List<BusExchange> exchanges = busExchangeService.selectByVirtualHostId(virtualHostId);
|
|
|
for (BusExchange busExchange : exchanges) {
|
|
|
String exchangeId = busExchange.getId();
|
|
|
// 5.1、删除数据库中对应的路由键
|
|
|
routingKeyService.deleteByExchangeId(exchangeId);
|
|
|
// 4.1 根据虚拟主机id,删除交换机
|
|
|
busExchangeService.deleteByVirtualHostId(virtualHostId);
|
|
|
// 4.2 在MQ服务器上删除该交换机
|
|
|
rabbitUtils.toRemoveExchange(busExchange);
|
|
|
}
|
|
|
// 2.1、删除数据库中的虚拟主机列表
|
|
|
virtualHostService.deleteByServerId(serverId);
|
|
|
}
|
|
|
}
|
|
|
} |
...
|
...
|
|