|
@@ -6,7 +6,6 @@ import java.util.Map;
|
|
|
import java.util.Properties;
|
|
|
import java.util.concurrent.TimeoutException;
|
|
|
|
|
|
-import com.rabbitmq.client.*;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
import org.slf4j.Logger;
|
|
|
import org.slf4j.LoggerFactory;
|
|
@@ -27,6 +26,7 @@ import com.alibaba.otter.canal.connector.rabbitmq.config.RabbitMQConstants;
|
|
|
import com.alibaba.otter.canal.connector.rabbitmq.config.RabbitMQProducerConfig;
|
|
|
import com.alibaba.otter.canal.protocol.FlatMessage;
|
|
|
import com.alibaba.otter.canal.protocol.Message;
|
|
|
+import com.rabbitmq.client.*;
|
|
|
|
|
|
/**
|
|
|
* RabbitMQ Producer SPI 实现
|
|
@@ -73,8 +73,11 @@ public class CanalRabbitMQProducer extends AbstractMQProducer implements CanalMQ
|
|
|
connect = factory.newConnection();
|
|
|
channel = connect.createChannel();
|
|
|
channel.queueDeclare(rabbitMQProperties.getQueue(), true, false, false, null);
|
|
|
- channel.exchangeDeclare(rabbitMQProperties.getExchange(), rabbitMQProperties.getDeliveryMode(), true, false, false, null);
|
|
|
- channel.queueBind(rabbitMQProperties.getQueue(), rabbitMQProperties.getExchange(), rabbitMQProperties.getRoutingKey());
|
|
|
+ channel.exchangeDeclare(rabbitMQProperties
|
|
|
+ .getExchange(), rabbitMQProperties.getDeliveryMode(), true, false, false, null);
|
|
|
+ channel.queueBind(rabbitMQProperties.getQueue(),
|
|
|
+ rabbitMQProperties.getExchange(),
|
|
|
+ rabbitMQProperties.getRoutingKey());
|
|
|
|
|
|
} catch (IOException | TimeoutException ex) {
|
|
|
throw new CanalException("Start RabbitMQ producer error", ex);
|
|
@@ -126,9 +129,8 @@ public class CanalRabbitMQProducer extends AbstractMQProducer implements CanalMQ
|
|
|
try {
|
|
|
if (!StringUtils.isEmpty(destination.getDynamicTopic())) {
|
|
|
// 动态topic
|
|
|
- Map<String, Message> messageMap = MQMessageUtils.messageTopics(message,
|
|
|
- destination.getTopic(),
|
|
|
- destination.getDynamicTopic());
|
|
|
+ Map<String, Message> messageMap = MQMessageUtils
|
|
|
+ .messageTopics(message, destination.getTopic(), destination.getDynamicTopic());
|
|
|
|
|
|
for (Map.Entry<String, com.alibaba.otter.canal.protocol.Message> entry : messageMap.entrySet()) {
|
|
|
final String topicName = entry.getKey().replace('.', '_');
|
|
@@ -177,7 +179,10 @@ public class CanalRabbitMQProducer extends AbstractMQProducer implements CanalMQ
|
|
|
// tips: 目前逻辑中暂不处理对exchange处理,请在Console后台绑定 才可使用routekey
|
|
|
try {
|
|
|
RabbitMQProducerConfig rabbitMQProperties = (RabbitMQProducerConfig) this.mqProperties;
|
|
|
- channel.basicPublish(rabbitMQProperties.getExchange(), queueName, MessageProperties.PERSISTENT_TEXT_PLAIN, message);
|
|
|
+ channel.basicPublish(rabbitMQProperties.getExchange(),
|
|
|
+ queueName,
|
|
|
+ MessageProperties.PERSISTENT_TEXT_PLAIN,
|
|
|
+ message);
|
|
|
} catch (Throwable e) {
|
|
|
throw new RuntimeException(e);
|
|
|
}
|