Skip to content

Commit

Permalink
增加 canal 的 spring boot 支持
Browse files Browse the repository at this point in the history
  • Loading branch information
yong.teng committed Feb 1, 2024
1 parent 1c62733 commit a14ae08
Show file tree
Hide file tree
Showing 19 changed files with 104 additions and 94 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,27 @@
* | Author: Yong.Teng <[email protected]> |
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/package com.buession.canal.springboot;/**
*
*/
package com.buession.canal.springboot;

import com.buession.canal.core.Configuration;

import java.time.Duration;

/**
* 实例基本配置
*
* @author Yong.Teng
* @since 1.0.0
*/public class BaseInstanceConfiguration {
*/
public abstract class BaseInstanceConfiguration extends Configuration {

/**
* 构造函数
*/
public BaseInstanceConfiguration() {
setTimeout(Duration.ofSeconds(10));
setBatchSize(10);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,32 @@
* | Author: Yong.Teng <[email protected]> |
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/package com.buession.canal.springboot;/**
*
*/
package com.buession.canal.springboot;

/**
* MQ 实例基本配置
*
* @author Yong.Teng
* @since 1.0.0
*/public class MqBaseInstanceConfiguration {
*/
public abstract class MqBaseInstanceConfiguration extends BaseInstanceConfiguration {

private boolean flatMessage;

/**
* 构造函数
*/
public MqBaseInstanceConfiguration() {
super();
}

public boolean isFlatMessage() {
return flatMessage;
}

public void setFlatMessage(boolean flatMessage) {
this.flatMessage = flatMessage;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal;
package com.buession.canal.springboot;

import com.buession.core.concurrent.ThreadPolicy;

Expand All @@ -32,7 +32,7 @@
* 线程池配置
*
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
public class ThreadConfig {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,20 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.core.Configuration;
import com.buession.canal.springboot.BaseInstanceConfiguration;

import java.time.Duration;
import java.util.HashMap;
import java.util.Map;

/**
* Canal 适配器配置基类
*
* @author Yong.Teng
* @since 0.0.1
* @since 1.0.0
*/
abstract class AbstractAdapterProperties<IC extends AbstractAdapterProperties.BaseInstanceConfiguration>
abstract class AbstractAdapterProperties<IC extends BaseInstanceConfiguration>
implements AdapterProperties<IC> {

/**
Expand Down Expand Up @@ -64,19 +63,4 @@ public void setInstances(Map<String, IC> instances) {
this.instances = instances;
}

/**
* 实例基本配置
*
* @author Yong.Teng
* @since 0.0.1
*/
public static abstract class BaseInstanceConfiguration extends Configuration {

public BaseInstanceConfiguration() {
setTimeout(Duration.ofSeconds(10));
setBatchSize(10);
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,15 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.springboot.MqBaseInstanceConfiguration;

/**
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
abstract class AbstractMqAdapterProperties<IC extends AbstractMqAdapterProperties.MqBaseInstanceConfiguration>
abstract class AbstractMqAdapterProperties<IC extends MqBaseInstanceConfiguration>
extends AbstractAdapterProperties<IC> {

/**
* MQ 实例基本配置
*
* @author Yong.Teng
* @since 0.0.1
*/
public static abstract class MqBaseInstanceConfiguration extends BaseInstanceConfiguration {

private boolean flatMessage;

public MqBaseInstanceConfiguration() {
super();
}

public boolean isFlatMessage() {
return flatMessage;
}

public void setFlatMessage(boolean flatMessage) {
this.flatMessage = flatMessage;
}

}

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.client.adapter.AdapterClient;
import com.buession.canal.client.adapter.KafkaAdapterClient;
Expand All @@ -42,7 +42,7 @@

/**
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(CanalProperties.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,22 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.core.CanalMode;
import com.buession.canal.springboot.BaseInstanceConfiguration;
import com.buession.springboot.boot.autoconfigure.condition.BaseOnPropertyExistCondition;
import org.springframework.boot.context.properties.bind.Bindable;

/**
* @author Yong.Teng
* @since 0.0.1
* @since 1.0.0
*/
interface AdapterClientConfiguredCondition {

abstract class AbstractCanalAdapterClientConfiguredCondition<P extends AdapterProperties<?
extends AbstractAdapterProperties.BaseInstanceConfiguration>>
extends BaseOnPropertyExistCondition<P> implements AdapterClientConfiguredCondition {
extends BaseInstanceConfiguration>> extends BaseOnPropertyExistCondition<P>
implements AdapterClientConfiguredCondition {

public AbstractCanalAdapterClientConfiguredCondition(final Bindable<P> registration, final CanalMode mode) {
super(CanalProperties.PREFIX + '.' + mode.getName(), "registered canal adapter clients", registration,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.core.Configuration;

Expand All @@ -32,7 +32,7 @@
* Canal 适配器配置
*
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
@FunctionalInterface
interface AdapterProperties<C extends Configuration> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.client.CanalContext;
import com.buession.canal.client.DefaultCanalContext;
Expand All @@ -41,7 +41,7 @@

/**
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
@Configuration(proxyBeanMethods = false)
@EnableConfigurationProperties(CanalProperties.class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,16 +22,16 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.springboot.canal.ThreadConfig;
import com.buession.canal.springboot.ThreadConfig;
import org.springframework.boot.context.properties.ConfigurationProperties;

/**
* Canal 配置
*
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
@ConfigurationProperties(CanalProperties.PREFIX)
public class CanalProperties {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.springboot.MqBaseInstanceConfiguration;

/**
* Kafka 适配器配置
*
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
public class KafkaProperties extends AbstractMqAdapterProperties<KafkaProperties.Instance> {

Expand Down Expand Up @@ -56,7 +58,7 @@ public void setServers(String servers) {
this.servers = servers;
}

public final static class Instance extends AbstractMqAdapterProperties.MqBaseInstanceConfiguration {
public final static class Instance extends MqBaseInstanceConfiguration {

/**
* Group Id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,16 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.client.adapter.PulsarMQAdapterClient;
import com.buession.canal.springboot.MqBaseInstanceConfiguration;

/**
* PulsarMQ 适配器配置
*
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
public class PulsarProperties extends AbstractMqAdapterProperties<PulsarProperties.Instance> {

Expand Down Expand Up @@ -184,7 +185,7 @@ public void setMaxRedeliveryCount(Integer maxRedeliveryCount) {
this.maxRedeliveryCount = maxRedeliveryCount;
}

public final static class Instance extends AbstractMqAdapterProperties.MqBaseInstanceConfiguration {
public final static class Instance extends MqBaseInstanceConfiguration {

/**
* 订阅名称
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.springboot.MqBaseInstanceConfiguration;

/**
* RabbitMQ 适配器配置
*
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
public class RabbitProperties extends AbstractMqAdapterProperties<RabbitProperties.Instance> {

Expand Down Expand Up @@ -128,7 +130,7 @@ public void setPassword(String password) {
this.password = password;
}

public final static class Instance extends AbstractMqAdapterProperties.MqBaseInstanceConfiguration {
public final static class Instance extends MqBaseInstanceConfiguration {

public Instance() {
super();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,15 @@
* | Copyright @ 2013-2023 Buession.com Inc. |
* +-------------------------------------------------------------------------------------------------------+
*/
package com.buession.springboot.canal.autoconfigure;
package com.buession.canal.springboot.autoconfigure;

import com.buession.canal.springboot.MqBaseInstanceConfiguration;

/**
* RocketMQ 适配器配置
*
* @author Yong.Teng
* @since 2.3.1
* @since 1.0.0
*/
public class RocketProperties extends AbstractMqAdapterProperties<RocketProperties.Instance> {

Expand Down Expand Up @@ -117,7 +119,7 @@ public void setAccessChannel(String accessChannel) {
this.accessChannel = accessChannel;
}

public final static class Instance extends AbstractMqAdapterProperties.MqBaseInstanceConfiguration {
public final static class Instance extends MqBaseInstanceConfiguration {

/**
* Group ID
Expand Down
Loading

0 comments on commit a14ae08

Please sign in to comment.