|  | @@ -6,6 +6,7 @@ import com.rabbitmq.client.ConnectionFactory; |  | @@ -6,6 +6,7 @@ import com.rabbitmq.client.ConnectionFactory; | 
| 6 | import com.sunyo.wlpt.message.bus.service.domain.*; | 6 | import com.sunyo.wlpt.message.bus.service.domain.*; | 
| 7 | import com.sunyo.wlpt.message.bus.service.service.BusServerService; | 7 | import com.sunyo.wlpt.message.bus.service.service.BusServerService; | 
| 8 | import com.sunyo.wlpt.message.bus.service.service.VirtualHostService; | 8 | import com.sunyo.wlpt.message.bus.service.service.VirtualHostService; | 
|  |  | 9 | +import com.sunyo.wlpt.message.bus.service.utils.EncryptionUtils; | 
| 9 | import lombok.extern.slf4j.Slf4j; | 10 | import lombok.extern.slf4j.Slf4j; | 
| 10 | import org.springframework.beans.factory.annotation.Value; | 11 | import org.springframework.beans.factory.annotation.Value; | 
| 11 | import org.springframework.stereotype.Component; | 12 | import org.springframework.stereotype.Component; | 
|  | @@ -87,64 +88,28 @@ public class RabbitUtils { |  | @@ -87,64 +88,28 @@ public class RabbitUtils { | 
| 87 | /** | 88 | /** | 
| 88 | * 获取 rabbitMq 的连接,重载 | 89 | * 获取 rabbitMq 的连接,重载 | 
| 89 | */ | 90 | */ | 
| 90 | -    public Connection getConnection(String virtualHostName) throws IOException, TimeoutException |  |  | 
| 91 | -    { |  |  | 
| 92 | -        ConnectionFactory factory = new ConnectionFactory(); |  |  | 
| 93 | -        factory.setHost(host); |  |  | 
| 94 | -        factory.setPort(port); |  |  | 
| 95 | -        factory.setVirtualHost(virtualHostName); |  |  | 
| 96 | -        factory.setUsername(username); |  |  | 
| 97 | -        factory.setPassword(password); |  |  | 
| 98 | -        Connection connection = factory.newConnection(); |  |  | 
| 99 | -        return connection; |  |  | 
| 100 | -    } |  |  | 
| 101 | - |  |  | 
| 102 | -    /** |  |  | 
| 103 | -     * 获取 rabbitMq 的连接,重载 |  |  | 
| 104 | -     */ |  |  | 
| 105 | -    public Connection getConnection(String serverIp, Integer serverPort, String virtualHostName) | 91 | +    public Connection getConnection(String serverIp, Integer serverPort, String virtualHostName, String superUsername, String superPassword) | 
| 106 | throws IOException, TimeoutException | 92 | throws IOException, TimeoutException | 
| 107 | { | 93 | { | 
|  |  | 94 | +        String base = EncryptionUtils.decryptBase64(superPassword); | 
|  |  | 95 | +        String[] split = base.split("\\."); | 
| 108 | ConnectionFactory factory = new ConnectionFactory(); | 96 | ConnectionFactory factory = new ConnectionFactory(); | 
| 109 | factory.setHost(serverIp); | 97 | factory.setHost(serverIp); | 
| 110 | factory.setPort(serverPort); | 98 | factory.setPort(serverPort); | 
| 111 | factory.setVirtualHost(virtualHostName); | 99 | factory.setVirtualHost(virtualHostName); | 
| 112 | -        factory.setUsername(username); |  |  | 
| 113 | -        factory.setPassword(password); | 100 | +        factory.setUsername(superUsername); | 
|  |  | 101 | +        factory.setPassword(split[split.length - 1]); | 
| 114 | Connection connection = factory.newConnection(); | 102 | Connection connection = factory.newConnection(); | 
| 115 | return connection; | 103 | return connection; | 
| 116 | } | 104 | } | 
| 117 |  | 105 |  | 
| 118 | /** | 106 | /** | 
| 119 | -     * 获取 rabbitMq 的连接,重载 |  |  | 
| 120 | -     * |  |  | 
| 121 | -     * @param hostIp    服务器ip |  |  | 
| 122 | -     * @param hostPort  服务器端口号 |  |  | 
| 123 | -     * @param vHostName 虚拟主机名称 |  |  | 
| 124 | -     * @param userName  用户名 |  |  | 
| 125 | -     * @param password  密码 |  |  | 
| 126 | -     * @return |  |  | 
| 127 | -     * @throws Exception |  |  | 
| 128 | -     */ |  |  | 
| 129 | -    public static Connection getConnection(String hostIp, int hostPort, String vHostName, String userName, String password) |  |  | 
| 130 | -            throws Exception |  |  | 
| 131 | -    { |  |  | 
| 132 | -        ConnectionFactory factory = new ConnectionFactory(); |  |  | 
| 133 | -        factory.setHost(hostIp); |  |  | 
| 134 | -        factory.setPort(hostPort); |  |  | 
| 135 | -        factory.setVirtualHost(vHostName); |  |  | 
| 136 | -        factory.setUsername(userName); |  |  | 
| 137 | -        factory.setPassword(password); |  |  | 
| 138 | -        return factory.newConnection(); |  |  | 
| 139 | -    } |  |  | 
| 140 | - |  |  | 
| 141 | -    /** |  |  | 
| 142 | * 添加交换机 | 107 | * 添加交换机 | 
| 143 | */ | 108 | */ | 
| 144 | -    public void createExchange(String serverIp, Integer serverPort, String virtualHostName, BusExchange busExchange) | 109 | +    public void createExchange(BusServer server, String virtualHostName, BusExchange busExchange) | 
| 145 | throws IOException, TimeoutException | 110 | throws IOException, TimeoutException | 
| 146 | { | 111 | { | 
| 147 | -        Connection connection = getConnection(serverIp, serverPort, virtualHostName); | 112 | +        Connection connection = getConnection(server.getServerIp(), server.getServerPort(), virtualHostName, server.getSuperUsername(), server.getSuperPassword()); | 
| 148 | Channel channel = connection.createChannel(); | 113 | Channel channel = connection.createChannel(); | 
| 149 | channel.exchangeDeclare(busExchange.getExchangeName(), | 114 | channel.exchangeDeclare(busExchange.getExchangeName(), | 
| 150 | busExchange.getExchangeType(), | 115 | busExchange.getExchangeType(), | 
|  | @@ -158,10 +123,10 @@ public class RabbitUtils { |  | @@ -158,10 +123,10 @@ public class RabbitUtils { | 
| 158 | /** | 123 | /** | 
| 159 | * 删除交换机 channel.exchangeDelete(exchangeName); | 124 | * 删除交换机 channel.exchangeDelete(exchangeName); | 
| 160 | */ | 125 | */ | 
| 161 | -    public void removeExchange(String serverIp, Integer serverPort, String virtualHostName, BusExchange busExchange) | 126 | +    public void removeExchange(BusServer server, String virtualHostName, BusExchange busExchange) | 
| 162 | throws IOException, TimeoutException | 127 | throws IOException, TimeoutException | 
| 163 | { | 128 | { | 
| 164 | -        Connection connection = getConnection(serverIp, serverPort, virtualHostName); | 129 | +        Connection connection = getConnection(server.getServerIp(), server.getServerPort(), virtualHostName, server.getSuperUsername(), server.getSuperPassword()); | 
| 165 | Channel channel = connection.createChannel(); | 130 | Channel channel = connection.createChannel(); | 
| 166 | channel.exchangeDelete(busExchange.getExchangeName()); | 131 | channel.exchangeDelete(busExchange.getExchangeName()); | 
| 167 | closeConnectionAndChanel(channel, connection); | 132 | closeConnectionAndChanel(channel, connection); | 
|  | @@ -170,10 +135,10 @@ public class RabbitUtils { |  | @@ -170,10 +135,10 @@ public class RabbitUtils { | 
| 170 | /** | 135 | /** | 
| 171 | * 添加队列(默认设置参数为 null) | 136 | * 添加队列(默认设置参数为 null) | 
| 172 | */ | 137 | */ | 
| 173 | -    public void createQueue(String serverIp, Integer serverPort, String virtualHostName, BusQueue busQueue) | 138 | +    public void createQueue(BusServer server, String virtualHostName, BusQueue busQueue) | 
| 174 | throws IOException, TimeoutException | 139 | throws IOException, TimeoutException | 
| 175 | { | 140 | { | 
| 176 | -        Connection connection = getConnection(serverIp, serverPort, virtualHostName); | 141 | +        Connection connection = getConnection(server.getServerIp(), server.getServerPort(), virtualHostName, server.getSuperUsername(), server.getSuperPassword()); | 
| 177 | Channel channel = connection.createChannel(); | 142 | Channel channel = connection.createChannel(); | 
| 178 | channel.queueDeclare(busQueue.getQueueName(), | 143 | channel.queueDeclare(busQueue.getQueueName(), | 
| 179 | busQueue.getDurability(), | 144 | busQueue.getDurability(), | 
|  | @@ -190,10 +155,10 @@ public class RabbitUtils { |  | @@ -190,10 +155,10 @@ public class RabbitUtils { | 
| 190 | /** | 155 | /** | 
| 191 | * 删除队列 channel.queueDelete(queueName); | 156 | * 删除队列 channel.queueDelete(queueName); | 
| 192 | */ | 157 | */ | 
| 193 | -    public void removeQueue(String serverIp, Integer serverPort, String virtualHostName, BusQueue busQueue) | 158 | +    public void removeQueue(BusServer server, String virtualHostName, BusQueue busQueue) | 
| 194 | throws IOException, TimeoutException | 159 | throws IOException, TimeoutException | 
| 195 | { | 160 | { | 
| 196 | -        Connection connection = getConnection(serverIp, serverPort, virtualHostName); | 161 | +        Connection connection = getConnection(server.getServerIp(), server.getServerPort(), virtualHostName, server.getSuperUsername(), server.getSuperPassword()); | 
| 197 | Channel channel = connection.createChannel(); | 162 | Channel channel = connection.createChannel(); | 
| 198 | channel.queueDelete(busQueue.getQueueName()); | 163 | channel.queueDelete(busQueue.getQueueName()); | 
| 199 | closeConnectionAndChanel(channel, connection); | 164 | closeConnectionAndChanel(channel, connection); | 
|  | @@ -202,10 +167,10 @@ public class RabbitUtils { |  | @@ -202,10 +167,10 @@ public class RabbitUtils { | 
| 202 | /** | 167 | /** | 
| 203 | * 创建绑定 | 168 | * 创建绑定 | 
| 204 | */ | 169 | */ | 
| 205 | -    public void createBinding(String serverIp, Integer serverPort, String virtualHostName, UserMessageBinding userMessageBinding) | 170 | +    public void createBinding(BusServer server, String virtualHostName, UserMessageBinding userMessageBinding) | 
| 206 | throws IOException, TimeoutException | 171 | throws IOException, TimeoutException | 
| 207 | { | 172 | { | 
| 208 | -        Connection connection = getConnection(serverIp, serverPort, virtualHostName); | 173 | +        Connection connection = getConnection(server.getServerIp(), server.getServerPort(), virtualHostName, server.getSuperUsername(), server.getSuperPassword()); | 
| 209 | Channel channel = connection.createChannel(); | 174 | Channel channel = connection.createChannel(); | 
| 210 | channel.queueBind(userMessageBinding.getQueueName(), | 175 | channel.queueBind(userMessageBinding.getQueueName(), | 
| 211 | userMessageBinding.getExchangeName(), | 176 | userMessageBinding.getExchangeName(), | 
|  | @@ -216,11 +181,10 @@ public class RabbitUtils { |  | @@ -216,11 +181,10 @@ public class RabbitUtils { | 
| 216 | /** | 181 | /** | 
| 217 | * 解除绑定 channel.queueUnbind("queueName", "exchangeName","routingKey"); | 182 | * 解除绑定 channel.queueUnbind("queueName", "exchangeName","routingKey"); | 
| 218 | */ | 183 | */ | 
| 219 | -    public void removeBinding(String serverIp, Integer serverPort, String virtualHostName, |  |  | 
| 220 | -                              UserMessageBinding userMessageBinding) | 184 | +    public void removeBinding(BusServer server, String virtualHostName, UserMessageBinding userMessageBinding) | 
| 221 | throws IOException, TimeoutException | 185 | throws IOException, TimeoutException | 
| 222 | { | 186 | { | 
| 223 | -        Connection connection = getConnection(serverIp, serverPort, virtualHostName); | 187 | +        Connection connection = getConnection(server.getServerIp(), server.getServerPort(), virtualHostName, server.getSuperUsername(), server.getSuperPassword()); | 
| 224 | Channel channel = connection.createChannel(); | 188 | Channel channel = connection.createChannel(); | 
| 225 | channel.queueUnbind(userMessageBinding.getQueueName(), | 189 | channel.queueUnbind(userMessageBinding.getQueueName(), | 
| 226 | userMessageBinding.getExchangeName(), | 190 | userMessageBinding.getExchangeName(), | 
|  | @@ -231,41 +195,45 @@ public class RabbitUtils { |  | @@ -231,41 +195,45 @@ public class RabbitUtils { | 
| 231 | /** | 195 | /** | 
| 232 | * 前往创建交换机的路上 | 196 | * 前往创建交换机的路上 | 
| 233 | */ | 197 | */ | 
| 234 | -    public void toCreateExchange(BusExchange busExchange) throws IOException, TimeoutException | 198 | +    public void toCreateExchange(BusExchange busExchange) | 
|  |  | 199 | +            throws IOException, TimeoutException | 
| 235 | { | 200 | { | 
| 236 | VirtualHost virtualHost = getVirtualHost(busExchange.getVirtualHostId()); | 201 | VirtualHost virtualHost = getVirtualHost(busExchange.getVirtualHostId()); | 
| 237 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 202 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 
| 238 | -        createExchange(busServer.getServerIp(), busServer.getServerPort(), virtualHost.getVirtualHostName(), busExchange); | 203 | +        createExchange(busServer, virtualHost.getVirtualHostName(), busExchange); | 
| 239 | } | 204 | } | 
| 240 |  | 205 |  | 
| 241 | /** | 206 | /** | 
| 242 | * 前往删除交换机的路上 | 207 | * 前往删除交换机的路上 | 
| 243 | */ | 208 | */ | 
| 244 | -    public void toRemoveExchange(BusExchange busExchange) throws IOException, TimeoutException | 209 | +    public void toRemoveExchange(BusExchange busExchange) | 
|  |  | 210 | +            throws IOException, TimeoutException | 
| 245 | { | 211 | { | 
| 246 | VirtualHost virtualHost = getVirtualHost(busExchange.getVirtualHostId()); | 212 | VirtualHost virtualHost = getVirtualHost(busExchange.getVirtualHostId()); | 
| 247 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 213 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 
| 248 | -        removeExchange(busServer.getServerIp(), busServer.getServerPort(), virtualHost.getVirtualHostName(), busExchange); | 214 | +        removeExchange(busServer, virtualHost.getVirtualHostName(), busExchange); | 
| 249 | } | 215 | } | 
| 250 |  | 216 |  | 
| 251 | /** | 217 | /** | 
| 252 | * 前往创建队列的路上 | 218 | * 前往创建队列的路上 | 
| 253 | */ | 219 | */ | 
| 254 | -    public void toCreateQueue(BusQueue BusQueue) throws IOException, TimeoutException | 220 | +    public void toCreateQueue(BusQueue BusQueue) | 
|  |  | 221 | +            throws IOException, TimeoutException | 
| 255 | { | 222 | { | 
| 256 | VirtualHost virtualHost = getVirtualHost(BusQueue.getVirtualHostId()); | 223 | VirtualHost virtualHost = getVirtualHost(BusQueue.getVirtualHostId()); | 
| 257 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 224 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 
| 258 | -        createQueue(busServer.getServerIp(), busServer.getServerPort(), virtualHost.getVirtualHostName(), BusQueue); | 225 | +        createQueue(busServer, virtualHost.getVirtualHostName(), BusQueue); | 
| 259 | } | 226 | } | 
| 260 |  | 227 |  | 
| 261 | /** | 228 | /** | 
| 262 | * 前往删除队列的路上 | 229 | * 前往删除队列的路上 | 
| 263 | */ | 230 | */ | 
| 264 | -    public void toRemoveQueue(BusQueue BusQueue) throws IOException, TimeoutException | 231 | +    public void toRemoveQueue(BusQueue BusQueue) | 
|  |  | 232 | +            throws IOException, TimeoutException | 
| 265 | { | 233 | { | 
| 266 | VirtualHost virtualHost = getVirtualHost(BusQueue.getVirtualHostId()); | 234 | VirtualHost virtualHost = getVirtualHost(BusQueue.getVirtualHostId()); | 
| 267 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 235 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 
| 268 | -        removeQueue(busServer.getServerIp(), busServer.getServerPort(), virtualHost.getVirtualHostName(), BusQueue); | 236 | +        removeQueue(busServer, virtualHost.getVirtualHostName(), BusQueue); | 
| 269 | } | 237 | } | 
| 270 |  | 238 |  | 
| 271 | /** | 239 | /** | 
|  | @@ -276,7 +244,7 @@ public class RabbitUtils { |  | @@ -276,7 +244,7 @@ public class RabbitUtils { | 
| 276 | { | 244 | { | 
| 277 | VirtualHost virtualHost = getVirtualHost(userMessageBinding.getVirtualHostId()); | 245 | VirtualHost virtualHost = getVirtualHost(userMessageBinding.getVirtualHostId()); | 
| 278 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 246 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 
| 279 | -        createBinding(busServer.getServerIp(), busServer.getServerPort(), virtualHost.getVirtualHostName(), userMessageBinding); | 247 | +        createBinding(busServer, virtualHost.getVirtualHostName(), userMessageBinding); | 
| 280 | } | 248 | } | 
| 281 |  | 249 |  | 
| 282 | /** | 250 | /** | 
|  | @@ -287,7 +255,7 @@ public class RabbitUtils { |  | @@ -287,7 +255,7 @@ public class RabbitUtils { | 
| 287 | { | 255 | { | 
| 288 | VirtualHost virtualHost = getVirtualHost(userMessageBinding.getVirtualHostId()); | 256 | VirtualHost virtualHost = getVirtualHost(userMessageBinding.getVirtualHostId()); | 
| 289 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 257 | BusServer busServer = getBusServer(virtualHost.getServerId()); | 
| 290 | -        removeBinding(busServer.getServerIp(), busServer.getServerPort(), virtualHost.getVirtualHostName(), userMessageBinding); | 258 | +        removeBinding(busServer, virtualHost.getVirtualHostName(), userMessageBinding); | 
| 291 | } | 259 | } | 
| 292 |  | 260 |  | 
| 293 | /** | 261 | /** |