mirror of
https://github.com/alibaba/canal.git
synced 2026-11-04 00:30:15 +08:00
example 增加获取当前gtid相关信息示例
This commit is contained in:
@@ -5,6 +5,7 @@ import java.text.SimpleDateFormat;
|
|||||||
import java.util.Date;
|
import java.util.Date;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import com.alibaba.otter.canal.protocol.CanalEntry;
|
||||||
import org.apache.commons.lang.StringUtils;
|
import org.apache.commons.lang.StringUtils;
|
||||||
import org.apache.commons.lang.SystemUtils;
|
import org.apache.commons.lang.SystemUtils;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
@@ -299,4 +300,55 @@ public class AbstractCanalClientTest {
|
|||||||
this.connector = connector;
|
this.connector = connector;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前Entry的 GTID信息示例
|
||||||
|
* @param header
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getCurrentGtid(CanalEntry.Header header) {
|
||||||
|
List<CanalEntry.Pair> props = header.getPropsList();
|
||||||
|
if (props != null && props.size() > 0) {
|
||||||
|
for (CanalEntry.Pair pair : props) {
|
||||||
|
if ("curtGtid".equals(pair.getKey())) {
|
||||||
|
return pair.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前Entry的 GTID Sequence No信息示例
|
||||||
|
* @param header
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getCurrentGtidSn(CanalEntry.Header header) {
|
||||||
|
List<CanalEntry.Pair> props = header.getPropsList();
|
||||||
|
if (props != null && props.size() > 0) {
|
||||||
|
for (CanalEntry.Pair pair : props) {
|
||||||
|
if ("curtGtidSn".equals(pair.getKey())) {
|
||||||
|
return pair.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 获取当前Entry的 GTID Last Committed信息示例
|
||||||
|
* @param header
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String getCurrentGtidLct(CanalEntry.Header header) {
|
||||||
|
List<CanalEntry.Pair> props = header.getPropsList();
|
||||||
|
if (props != null && props.size() > 0) {
|
||||||
|
for (CanalEntry.Pair pair : props) {
|
||||||
|
if ("curtGtidLct".equals(pair.getKey())) {
|
||||||
|
return pair.getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return "";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user