renxue
2022-10-24 0b055a3f554da3a934e79e88c4781705cbab5a21
提交 | 用户 | age
0b055a 1 package com.hz.canal.starter.configuration;
R 2
3 import org.springframework.boot.context.properties.ConfigurationProperties;
4 import org.springframework.core.Ordered;
5 import org.springframework.core.annotation.Order;
6
7 import java.util.LinkedHashMap;
8 import java.util.Map;
9
10 /**
11  * Canal连接的配置类
12  *
13  * @author wuqiong 2022/4/11
14  */
15 @Order(Ordered.HIGHEST_PRECEDENCE)
16 @ConfigurationProperties(prefix = "spring.canal")
17 public class CanalAutoConfigurationProperties {
18
19     private Map<String, EndpointInstance> instances = new LinkedHashMap<>();
20
21     public static class EndpointInstance {
22
23         /**
24          * 是否开启 cluster
25          */
26         private boolean clusterEnabled;
27
28         /**
29          * zookeeper 地址, 例: 192.168.0.1:2181,192.168.0.2:2181,192.168.0.3:2181
30          */
31         private String zookeeperAddress;
32
33         /**
34          * 默认 127.0.0.1
35          */
36         private String host = "127.0.0.1";
37
38         /**
39          * 端口 , 默认: 11111
40          */
41         private int port = 11111;
42
43         /**
44          * 用户名
45          */
46         private String userName = "";
47
48         /**
49          * 密码
50          */
51         private String password = "";
52
53         /**
54          * 每次获取数据条数 , 默认: 200
55          */
56         private int batchSize = 200;
57
58         /**
59          * 发生错误时重试次数 , 默认: 5
60          */
61         private int retryCount = 5;
62
63         /**
64          * mysql 数据解析关注的表,Perl正则表达式.
65          * <p>
66          * <p>
67          * 多个正则之间以逗号(,)分隔,转义符需要双斜杠(\\)
68          * <p>
69          * <p>
70          * 常见例子: <p>
71          * 1.  所有库表:.*   or  .*\\..* <p>
72          * 2.  canal_db 下所有表:    canal_db\\..* <p>
73          * 3.  canal_db 下的以canal打头的表:   canal_db\\.canal.* <p>
74          * 4.  canal_db 下的一张表:  canal_db\\.test1 <p>
75          * 5.  多个规则组合使用:canal_db\\..*,mysql_db.test1,mysql.test2 (逗号分隔) <p>
76          * <p>
77          * 默认: 全库全表(.*\\..*)
78          */
79         private String subscribe = ".*\\..*";
80
81         /**
82          * 未拉取到消息情况下,获取消息的时间间隔毫秒值 , 默认: 1000
83          */
84         private long acquireInterval = 1000;
85
86         public EndpointInstance() {
87         }
88
89         public boolean isClusterEnabled() {
90             return clusterEnabled;
91         }
92
93         public void setClusterEnabled(boolean clusterEnabled) {
94             this.clusterEnabled = clusterEnabled;
95         }
96
97         public String getZookeeperAddress() {
98             return zookeeperAddress;
99         }
100
101         public void setZookeeperAddress(String zookeeperAddress) {
102             this.zookeeperAddress = zookeeperAddress;
103         }
104
105         public String getHost() {
106             return host;
107         }
108
109         public void setHost(String host) {
110             this.host = host;
111         }
112
113         public int getPort() {
114             return port;
115         }
116
117         public void setPort(int port) {
118             this.port = port;
119         }
120
121         public String getUserName() {
122             return userName;
123         }
124
125         public void setUserName(String userName) {
126             this.userName = userName;
127         }
128
129         public String getPassword() {
130             return password;
131         }
132
133         public void setPassword(String password) {
134             this.password = password;
135         }
136
137         public int getBatchSize() {
138             return batchSize;
139         }
140
141         public void setBatchSize(int batchSize) {
142             this.batchSize = batchSize;
143         }
144
145         public int getRetryCount() {
146             return retryCount;
147         }
148
149         public void setRetryCount(int retryCount) {
150             this.retryCount = retryCount;
151         }
152
153         public long getAcquireInterval() {
154             return acquireInterval;
155         }
156
157         public void setAcquireInterval(long acquireInterval) {
158             this.acquireInterval = acquireInterval;
159         }
160
161         public String getSubscribe() {
162             return subscribe;
163         }
164
165         public void setSubscribe(String subscribe) {
166             this.subscribe = subscribe;
167         }
168     }
169
170     public Map<String, EndpointInstance> getInstances() {
171         return instances;
172     }
173
174     public void setInstances(Map<String, EndpointInstance> instances) {
175         this.instances = instances;
176     }
177 }