This commit is contained in:
jianghang.loujh
2024-04-03 10:45:29 +08:00
parent c0ff058fe1
commit caa46f3672

View File

@@ -82,13 +82,18 @@ public class CanalRabbitMQProducer extends AbstractMQProducer implements CanalMQ
try { try {
connect = factory.newConnection(); connect = factory.newConnection();
channel = connect.createChannel(); channel = connect.createChannel();
channel.queueDeclare(rabbitMQProperties.getQueue(), true, false, false, null); String queue = rabbitMQProperties.getQueue();
channel.exchangeDeclare(rabbitMQProperties String exchange = rabbitMQProperties.getExchange();
.getExchange(), rabbitMQProperties.getDeliveryMode(), true, false, false, null); String deliveryMode = rabbitMQProperties.getDeliveryMode();
channel.queueBind(rabbitMQProperties.getQueue(), String routingKey = rabbitMQProperties.getRoutingKey();
rabbitMQProperties.getExchange(), if (!StringUtils.isEmpty(queue)) {
rabbitMQProperties.getRoutingKey()); channel.queueDeclare(queue, true, false, false, null);
}
if (!StringUtils.isEmpty(queue) && !StringUtils.isEmpty(exchange) && !StringUtils.isEmpty(deliveryMode)
&& !StringUtils.isEmpty(routingKey)) {
channel.exchangeDeclare(exchange, deliveryMode, true, false, false, null);
channel.queueBind(queue, exchange, routingKey);
}
} catch (IOException | TimeoutException ex) { } catch (IOException | TimeoutException ex) {
throw new CanalException("Start RabbitMQ producer error", ex); throw new CanalException("Start RabbitMQ producer error", ex);
} }