From 5300b63647c3290ecbd453556835322c242bbc2f Mon Sep 17 00:00:00 2001 From: WithLin Date: Fri, 7 Sep 2018 10:23:40 +0800 Subject: [PATCH 01/50] Fix add protocol --- Canal4Net.sln => canal-csharp.sln | 18 +- .../Canal.Csharp.Abstract.csproj} | 0 .../Canal.Csharp.Core.csproj | 7 + .../Canal.Csharp.Protocol.csproj | 11 + src/Canal.Csharp.Protocol/CanalProtocol.cs | 607 ++++++++++++++++++ src/Canal.Csharp.Protocol/CanalProtocol.proto | 115 ++++ src/Canal.Csharp.Protocol/EntryProtocol.cs | 545 ++++++++++++++++ src/Canal.Csharp.Protocol/EntryProtocol.proto | 207 ++++++ 8 files changed, 1508 insertions(+), 2 deletions(-) rename Canal4Net.sln => canal-csharp.sln (64%) rename src/{Canal4Net/Canal4Net.csproj => Canal.Csharp.Abstract/Canal.Csharp.Abstract.csproj} (100%) create mode 100644 src/Canal.Csharp.Core/Canal.Csharp.Core.csproj create mode 100644 src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj create mode 100644 src/Canal.Csharp.Protocol/CanalProtocol.cs create mode 100644 src/Canal.Csharp.Protocol/CanalProtocol.proto create mode 100644 src/Canal.Csharp.Protocol/EntryProtocol.cs create mode 100644 src/Canal.Csharp.Protocol/EntryProtocol.proto diff --git a/Canal4Net.sln b/canal-csharp.sln similarity index 64% rename from Canal4Net.sln rename to canal-csharp.sln index c37ca42..da99473 100644 --- a/Canal4Net.sln +++ b/canal-csharp.sln @@ -16,9 +16,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{BD70CDB7-9 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Canal4Net", "src\Canal4Net\Canal4Net.csproj", "{3611D6F6-FFAC-4CFE-A160-22E08AD0F2FA}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net", "src\Canal4Net\Canal4Net.csproj", "{3611D6F6-FFAC-4CFE-A160-22E08AD0F2FA}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Canal4Net.UnitTests", "test\Canal4Net.UnitTests\Canal4Net.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net.UnitTests", "test\Canal4Net.UnitTests\Canal4Net.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net.Core", "src\Canal4Net.Core\Canal4Net.Core.csproj", "{2D53A810-8638-41F3-8DE7-19C47E7BC129}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net.Protocol", "src\Canal4Net.Protocol\Canal4Net.Protocol.csproj", "{D28DD917-DB36-4FBE-9D6A-7E09660563AF}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -34,6 +38,14 @@ Global {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Debug|Any CPU.Build.0 = Debug|Any CPU {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Release|Any CPU.ActiveCfg = Release|Any CPU {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Release|Any CPU.Build.0 = Release|Any CPU + {2D53A810-8638-41F3-8DE7-19C47E7BC129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {2D53A810-8638-41F3-8DE7-19C47E7BC129}.Debug|Any CPU.Build.0 = Debug|Any CPU + {2D53A810-8638-41F3-8DE7-19C47E7BC129}.Release|Any CPU.ActiveCfg = Release|Any CPU + {2D53A810-8638-41F3-8DE7-19C47E7BC129}.Release|Any CPU.Build.0 = Release|Any CPU + {D28DD917-DB36-4FBE-9D6A-7E09660563AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D28DD917-DB36-4FBE-9D6A-7E09660563AF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D28DD917-DB36-4FBE-9D6A-7E09660563AF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D28DD917-DB36-4FBE-9D6A-7E09660563AF}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -41,6 +53,8 @@ Global GlobalSection(NestedProjects) = preSolution {3611D6F6-FFAC-4CFE-A160-22E08AD0F2FA} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} {83F407DD-5810-422F-8AF6-4E9BA75AC678} = {BD70CDB7-94E9-4621-B702-DC04DB9D59EF} + {2D53A810-8638-41F3-8DE7-19C47E7BC129} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} + {D28DD917-DB36-4FBE-9D6A-7E09660563AF} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FD9B9146-8418-4F80-A666-9B47BE4F9C9C} diff --git a/src/Canal4Net/Canal4Net.csproj b/src/Canal.Csharp.Abstract/Canal.Csharp.Abstract.csproj similarity index 100% rename from src/Canal4Net/Canal4Net.csproj rename to src/Canal.Csharp.Abstract/Canal.Csharp.Abstract.csproj diff --git a/src/Canal.Csharp.Core/Canal.Csharp.Core.csproj b/src/Canal.Csharp.Core/Canal.Csharp.Core.csproj new file mode 100644 index 0000000..9f5c4f4 --- /dev/null +++ b/src/Canal.Csharp.Core/Canal.Csharp.Core.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj b/src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj new file mode 100644 index 0000000..049115e --- /dev/null +++ b/src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/src/Canal.Csharp.Protocol/CanalProtocol.cs b/src/Canal.Csharp.Protocol/CanalProtocol.cs new file mode 100644 index 0000000..2f92f22 --- /dev/null +++ b/src/Canal.Csharp.Protocol/CanalProtocol.cs @@ -0,0 +1,607 @@ +// This file was generated by a tool; you should avoid making direct changes. +// Consider using 'partial classes' to extend these types +// Input: CanalProtocol.proto + +#pragma warning disable CS0612, CS1591, CS3021, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 +namespace com.alibaba.otter.canal.protocol +{ + + [global::ProtoBuf.ProtoContract()] + public partial class Packet : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"magic_number")] + [global::System.ComponentModel.DefaultValue(17)] + public int MagicNumber + { + get { return __pbn__MagicNumber ?? 17; } + set { __pbn__MagicNumber = value; } + } + public bool ShouldSerializeMagicNumber() => __pbn__MagicNumber != null; + public void ResetMagicNumber() => __pbn__MagicNumber = null; + private int? __pbn__MagicNumber; + + [global::ProtoBuf.ProtoMember(2, Name = @"version")] + [global::System.ComponentModel.DefaultValue(1)] + public int Version + { + get { return __pbn__Version ?? 1; } + set { __pbn__Version = value; } + } + public bool ShouldSerializeVersion() => __pbn__Version != null; + public void ResetVersion() => __pbn__Version = null; + private int? __pbn__Version; + + [global::ProtoBuf.ProtoMember(3, Name = @"type")] + [global::System.ComponentModel.DefaultValue(PacketType.Handshake)] + public PacketType Type + { + get { return __pbn__Type ?? PacketType.Handshake; } + set { __pbn__Type = value; } + } + public bool ShouldSerializeType() => __pbn__Type != null; + public void ResetType() => __pbn__Type = null; + private PacketType? __pbn__Type; + + [global::ProtoBuf.ProtoMember(4, Name = @"compression")] + [global::System.ComponentModel.DefaultValue(Compression.None)] + public Compression Compression + { + get { return __pbn__Compression ?? Compression.None; } + set { __pbn__Compression = value; } + } + public bool ShouldSerializeCompression() => __pbn__Compression != null; + public void ResetCompression() => __pbn__Compression = null; + private Compression? __pbn__Compression; + + [global::ProtoBuf.ProtoMember(5, Name = @"body")] + public byte[] Body + { + get { return __pbn__Body; } + set { __pbn__Body = value; } + } + public bool ShouldSerializeBody() => __pbn__Body != null; + public void ResetBody() => __pbn__Body = null; + private byte[] __pbn__Body; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class HeartBeat : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"send_timestamp")] + public long SendTimestamp + { + get { return __pbn__SendTimestamp.GetValueOrDefault(); } + set { __pbn__SendTimestamp = value; } + } + public bool ShouldSerializeSendTimestamp() => __pbn__SendTimestamp != null; + public void ResetSendTimestamp() => __pbn__SendTimestamp = null; + private long? __pbn__SendTimestamp; + + [global::ProtoBuf.ProtoMember(2, Name = @"start_timestamp")] + public long StartTimestamp + { + get { return __pbn__StartTimestamp.GetValueOrDefault(); } + set { __pbn__StartTimestamp = value; } + } + public bool ShouldSerializeStartTimestamp() => __pbn__StartTimestamp != null; + public void ResetStartTimestamp() => __pbn__StartTimestamp = null; + private long? __pbn__StartTimestamp; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Handshake : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"communication_encoding")] + [global::System.ComponentModel.DefaultValue(@"utf8")] + public string CommunicationEncoding + { + get { return __pbn__CommunicationEncoding ?? @"utf8"; } + set { __pbn__CommunicationEncoding = value; } + } + public bool ShouldSerializeCommunicationEncoding() => __pbn__CommunicationEncoding != null; + public void ResetCommunicationEncoding() => __pbn__CommunicationEncoding = null; + private string __pbn__CommunicationEncoding; + + [global::ProtoBuf.ProtoMember(2, Name = @"seeds")] + public byte[] Seeds + { + get { return __pbn__Seeds; } + set { __pbn__Seeds = value; } + } + public bool ShouldSerializeSeeds() => __pbn__Seeds != null; + public void ResetSeeds() => __pbn__Seeds = null; + private byte[] __pbn__Seeds; + + [global::ProtoBuf.ProtoMember(3, Name = @"supported_compressions")] + public global::System.Collections.Generic.List SupportedCompressions { get; } = new global::System.Collections.Generic.List(); + + } + + [global::ProtoBuf.ProtoContract()] + public partial class ClientAuth : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"username")] + [global::System.ComponentModel.DefaultValue("")] + public string Username + { + get { return __pbn__Username ?? ""; } + set { __pbn__Username = value; } + } + public bool ShouldSerializeUsername() => __pbn__Username != null; + public void ResetUsername() => __pbn__Username = null; + private string __pbn__Username; + + [global::ProtoBuf.ProtoMember(2, Name = @"password")] + public byte[] Password + { + get { return __pbn__Password; } + set { __pbn__Password = value; } + } + public bool ShouldSerializePassword() => __pbn__Password != null; + public void ResetPassword() => __pbn__Password = null; + private byte[] __pbn__Password; + + [global::ProtoBuf.ProtoMember(3, Name = @"net_read_timeout")] + [global::System.ComponentModel.DefaultValue(0)] + public int NetReadTimeout + { + get { return __pbn__NetReadTimeout ?? 0; } + set { __pbn__NetReadTimeout = value; } + } + public bool ShouldSerializeNetReadTimeout() => __pbn__NetReadTimeout != null; + public void ResetNetReadTimeout() => __pbn__NetReadTimeout = null; + private int? __pbn__NetReadTimeout; + + [global::ProtoBuf.ProtoMember(4, Name = @"net_write_timeout")] + [global::System.ComponentModel.DefaultValue(0)] + public int NetWriteTimeout + { + get { return __pbn__NetWriteTimeout ?? 0; } + set { __pbn__NetWriteTimeout = value; } + } + public bool ShouldSerializeNetWriteTimeout() => __pbn__NetWriteTimeout != null; + public void ResetNetWriteTimeout() => __pbn__NetWriteTimeout = null; + private int? __pbn__NetWriteTimeout; + + [global::ProtoBuf.ProtoMember(5, Name = @"destination")] + [global::System.ComponentModel.DefaultValue("")] + public string Destination + { + get { return __pbn__Destination ?? ""; } + set { __pbn__Destination = value; } + } + public bool ShouldSerializeDestination() => __pbn__Destination != null; + public void ResetDestination() => __pbn__Destination = null; + private string __pbn__Destination; + + [global::ProtoBuf.ProtoMember(6, Name = @"client_id")] + [global::System.ComponentModel.DefaultValue("")] + public string ClientId + { + get { return __pbn__ClientId ?? ""; } + set { __pbn__ClientId = value; } + } + public bool ShouldSerializeClientId() => __pbn__ClientId != null; + public void ResetClientId() => __pbn__ClientId = null; + private string __pbn__ClientId; + + [global::ProtoBuf.ProtoMember(7, Name = @"filter")] + [global::System.ComponentModel.DefaultValue("")] + public string Filter + { + get { return __pbn__Filter ?? ""; } + set { __pbn__Filter = value; } + } + public bool ShouldSerializeFilter() => __pbn__Filter != null; + public void ResetFilter() => __pbn__Filter = null; + private string __pbn__Filter; + + [global::ProtoBuf.ProtoMember(8, Name = @"start_timestamp")] + public long StartTimestamp + { + get { return __pbn__StartTimestamp.GetValueOrDefault(); } + set { __pbn__StartTimestamp = value; } + } + public bool ShouldSerializeStartTimestamp() => __pbn__StartTimestamp != null; + public void ResetStartTimestamp() => __pbn__StartTimestamp = null; + private long? __pbn__StartTimestamp; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Ack : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"error_code")] + [global::System.ComponentModel.DefaultValue(0)] + public int ErrorCode + { + get { return __pbn__ErrorCode ?? 0; } + set { __pbn__ErrorCode = value; } + } + public bool ShouldSerializeErrorCode() => __pbn__ErrorCode != null; + public void ResetErrorCode() => __pbn__ErrorCode = null; + private int? __pbn__ErrorCode; + + [global::ProtoBuf.ProtoMember(2, Name = @"error_message")] + [global::System.ComponentModel.DefaultValue("")] + public string ErrorMessage + { + get { return __pbn__ErrorMessage ?? ""; } + set { __pbn__ErrorMessage = value; } + } + public bool ShouldSerializeErrorMessage() => __pbn__ErrorMessage != null; + public void ResetErrorMessage() => __pbn__ErrorMessage = null; + private string __pbn__ErrorMessage; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class ClientAck : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"destination")] + [global::System.ComponentModel.DefaultValue("")] + public string Destination + { + get { return __pbn__Destination ?? ""; } + set { __pbn__Destination = value; } + } + public bool ShouldSerializeDestination() => __pbn__Destination != null; + public void ResetDestination() => __pbn__Destination = null; + private string __pbn__Destination; + + [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] + [global::System.ComponentModel.DefaultValue("")] + public string ClientId + { + get { return __pbn__ClientId ?? ""; } + set { __pbn__ClientId = value; } + } + public bool ShouldSerializeClientId() => __pbn__ClientId != null; + public void ResetClientId() => __pbn__ClientId = null; + private string __pbn__ClientId; + + [global::ProtoBuf.ProtoMember(3, Name = @"batch_id")] + public long BatchId + { + get { return __pbn__BatchId.GetValueOrDefault(); } + set { __pbn__BatchId = value; } + } + public bool ShouldSerializeBatchId() => __pbn__BatchId != null; + public void ResetBatchId() => __pbn__BatchId = null; + private long? __pbn__BatchId; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Sub : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"destination")] + [global::System.ComponentModel.DefaultValue("")] + public string Destination + { + get { return __pbn__Destination ?? ""; } + set { __pbn__Destination = value; } + } + public bool ShouldSerializeDestination() => __pbn__Destination != null; + public void ResetDestination() => __pbn__Destination = null; + private string __pbn__Destination; + + [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] + [global::System.ComponentModel.DefaultValue("")] + public string ClientId + { + get { return __pbn__ClientId ?? ""; } + set { __pbn__ClientId = value; } + } + public bool ShouldSerializeClientId() => __pbn__ClientId != null; + public void ResetClientId() => __pbn__ClientId = null; + private string __pbn__ClientId; + + [global::ProtoBuf.ProtoMember(7, Name = @"filter")] + [global::System.ComponentModel.DefaultValue("")] + public string Filter + { + get { return __pbn__Filter ?? ""; } + set { __pbn__Filter = value; } + } + public bool ShouldSerializeFilter() => __pbn__Filter != null; + public void ResetFilter() => __pbn__Filter = null; + private string __pbn__Filter; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Unsub : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"destination")] + [global::System.ComponentModel.DefaultValue("")] + public string Destination + { + get { return __pbn__Destination ?? ""; } + set { __pbn__Destination = value; } + } + public bool ShouldSerializeDestination() => __pbn__Destination != null; + public void ResetDestination() => __pbn__Destination = null; + private string __pbn__Destination; + + [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] + [global::System.ComponentModel.DefaultValue("")] + public string ClientId + { + get { return __pbn__ClientId ?? ""; } + set { __pbn__ClientId = value; } + } + public bool ShouldSerializeClientId() => __pbn__ClientId != null; + public void ResetClientId() => __pbn__ClientId = null; + private string __pbn__ClientId; + + [global::ProtoBuf.ProtoMember(7, Name = @"filter")] + [global::System.ComponentModel.DefaultValue("")] + public string Filter + { + get { return __pbn__Filter ?? ""; } + set { __pbn__Filter = value; } + } + public bool ShouldSerializeFilter() => __pbn__Filter != null; + public void ResetFilter() => __pbn__Filter = null; + private string __pbn__Filter; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Get : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"destination")] + [global::System.ComponentModel.DefaultValue("")] + public string Destination + { + get { return __pbn__Destination ?? ""; } + set { __pbn__Destination = value; } + } + public bool ShouldSerializeDestination() => __pbn__Destination != null; + public void ResetDestination() => __pbn__Destination = null; + private string __pbn__Destination; + + [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] + [global::System.ComponentModel.DefaultValue("")] + public string ClientId + { + get { return __pbn__ClientId ?? ""; } + set { __pbn__ClientId = value; } + } + public bool ShouldSerializeClientId() => __pbn__ClientId != null; + public void ResetClientId() => __pbn__ClientId = null; + private string __pbn__ClientId; + + [global::ProtoBuf.ProtoMember(3, Name = @"fetch_size")] + public int FetchSize + { + get { return __pbn__FetchSize.GetValueOrDefault(); } + set { __pbn__FetchSize = value; } + } + public bool ShouldSerializeFetchSize() => __pbn__FetchSize != null; + public void ResetFetchSize() => __pbn__FetchSize = null; + private int? __pbn__FetchSize; + + [global::ProtoBuf.ProtoMember(4, Name = @"timeout")] + [global::System.ComponentModel.DefaultValue(-1)] + public long Timeout + { + get { return __pbn__Timeout ?? -1; } + set { __pbn__Timeout = value; } + } + public bool ShouldSerializeTimeout() => __pbn__Timeout != null; + public void ResetTimeout() => __pbn__Timeout = null; + private long? __pbn__Timeout; + + [global::ProtoBuf.ProtoMember(5, Name = @"unit")] + [global::System.ComponentModel.DefaultValue(2)] + public int Unit + { + get { return __pbn__Unit ?? 2; } + set { __pbn__Unit = value; } + } + public bool ShouldSerializeUnit() => __pbn__Unit != null; + public void ResetUnit() => __pbn__Unit = null; + private int? __pbn__Unit; + + [global::ProtoBuf.ProtoMember(6, Name = @"auto_ack")] + [global::System.ComponentModel.DefaultValue(false)] + public bool AutoAck + { + get { return __pbn__AutoAck ?? false; } + set { __pbn__AutoAck = value; } + } + public bool ShouldSerializeAutoAck() => __pbn__AutoAck != null; + public void ResetAutoAck() => __pbn__AutoAck = null; + private bool? __pbn__AutoAck; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Messages : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"batch_id")] + public long BatchId + { + get { return __pbn__BatchId.GetValueOrDefault(); } + set { __pbn__BatchId = value; } + } + public bool ShouldSerializeBatchId() => __pbn__BatchId != null; + public void ResetBatchId() => __pbn__BatchId = null; + private long? __pbn__BatchId; + + [global::ProtoBuf.ProtoMember(2)] + public global::System.Collections.Generic.List messages { get; } = new global::System.Collections.Generic.List(); + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Dump : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"journal")] + [global::System.ComponentModel.DefaultValue("")] + public string Journal + { + get { return __pbn__Journal ?? ""; } + set { __pbn__Journal = value; } + } + public bool ShouldSerializeJournal() => __pbn__Journal != null; + public void ResetJournal() => __pbn__Journal = null; + private string __pbn__Journal; + + [global::ProtoBuf.ProtoMember(2, Name = @"position")] + public long Position + { + get { return __pbn__Position.GetValueOrDefault(); } + set { __pbn__Position = value; } + } + public bool ShouldSerializePosition() => __pbn__Position != null; + public void ResetPosition() => __pbn__Position = null; + private long? __pbn__Position; + + [global::ProtoBuf.ProtoMember(3, Name = @"timestamp")] + [global::System.ComponentModel.DefaultValue(0)] + public long Timestamp + { + get { return __pbn__Timestamp ?? 0; } + set { __pbn__Timestamp = value; } + } + public bool ShouldSerializeTimestamp() => __pbn__Timestamp != null; + public void ResetTimestamp() => __pbn__Timestamp = null; + private long? __pbn__Timestamp; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class ClientRollback : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"destination")] + [global::System.ComponentModel.DefaultValue("")] + public string Destination + { + get { return __pbn__Destination ?? ""; } + set { __pbn__Destination = value; } + } + public bool ShouldSerializeDestination() => __pbn__Destination != null; + public void ResetDestination() => __pbn__Destination = null; + private string __pbn__Destination; + + [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] + [global::System.ComponentModel.DefaultValue("")] + public string ClientId + { + get { return __pbn__ClientId ?? ""; } + set { __pbn__ClientId = value; } + } + public bool ShouldSerializeClientId() => __pbn__ClientId != null; + public void ResetClientId() => __pbn__ClientId = null; + private string __pbn__ClientId; + + [global::ProtoBuf.ProtoMember(3, Name = @"batch_id")] + public long BatchId + { + get { return __pbn__BatchId.GetValueOrDefault(); } + set { __pbn__BatchId = value; } + } + public bool ShouldSerializeBatchId() => __pbn__BatchId != null; + public void ResetBatchId() => __pbn__BatchId = null; + private long? __pbn__BatchId; + + } + + [global::ProtoBuf.ProtoContract()] + public enum Compression + { + [global::ProtoBuf.ProtoEnum(Name = @"NONE")] + None = 1, + [global::ProtoBuf.ProtoEnum(Name = @"ZLIB")] + Zlib = 2, + [global::ProtoBuf.ProtoEnum(Name = @"GZIP")] + Gzip = 3, + [global::ProtoBuf.ProtoEnum(Name = @"LZF")] + Lzf = 4, + } + + [global::ProtoBuf.ProtoContract()] + public enum PacketType + { + [global::ProtoBuf.ProtoEnum(Name = @"HANDSHAKE")] + Handshake = 1, + [global::ProtoBuf.ProtoEnum(Name = @"CLIENTAUTHENTICATION")] + Clientauthentication = 2, + [global::ProtoBuf.ProtoEnum(Name = @"ACK")] + Ack = 3, + [global::ProtoBuf.ProtoEnum(Name = @"SUBSCRIPTION")] + Subscription = 4, + [global::ProtoBuf.ProtoEnum(Name = @"UNSUBSCRIPTION")] + Unsubscription = 5, + [global::ProtoBuf.ProtoEnum(Name = @"GET")] + Get = 6, + [global::ProtoBuf.ProtoEnum(Name = @"MESSAGES")] + Messages = 7, + [global::ProtoBuf.ProtoEnum(Name = @"CLIENTACK")] + Clientack = 8, + [global::ProtoBuf.ProtoEnum(Name = @"SHUTDOWN")] + Shutdown = 9, + [global::ProtoBuf.ProtoEnum(Name = @"DUMP")] + Dump = 10, + [global::ProtoBuf.ProtoEnum(Name = @"HEARTBEAT")] + Heartbeat = 11, + [global::ProtoBuf.ProtoEnum(Name = @"CLIENTROLLBACK")] + Clientrollback = 12, + } + +} + +#pragma warning restore CS0612, CS1591, CS3021, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 diff --git a/src/Canal.Csharp.Protocol/CanalProtocol.proto b/src/Canal.Csharp.Protocol/CanalProtocol.proto new file mode 100644 index 0000000..9f88fe9 --- /dev/null +++ b/src/Canal.Csharp.Protocol/CanalProtocol.proto @@ -0,0 +1,115 @@ +syntax = "proto2"; +package com.alibaba.otter.canal.protocol; + +option java_package = "com.alibaba.otter.canal.protocol"; +option java_outer_classname = "CanalPacket"; +option optimize_for = SPEED; + +enum Compression { + NONE = 1; + ZLIB = 2; + GZIP = 3; + LZF = 4; +} + +enum PacketType { + HANDSHAKE = 1; + CLIENTAUTHENTICATION = 2; + ACK = 3; + SUBSCRIPTION = 4; + UNSUBSCRIPTION = 5; + GET = 6; + MESSAGES = 7; + CLIENTACK = 8; + // management part + SHUTDOWN = 9; + // integration + DUMP = 10; + HEARTBEAT = 11; + CLIENTROLLBACK = 12; +} + +message Packet { + optional int32 magic_number = 1 [default = 17]; + optional int32 version = 2 [default = 1]; + optional PacketType type = 3; + optional Compression compression = 4 [default = NONE]; + optional bytes body = 5; +} + +message HeartBeat { + optional int64 send_timestamp = 1; + optional int64 start_timestamp = 2; +} + +message Handshake { + optional string communication_encoding = 1 [default = "utf8"]; + optional bytes seeds = 2; + repeated Compression supported_compressions = 3; +} + +// client authentication +message ClientAuth { + optional string username = 1; + optional bytes password = 2; // hashed password with seeds from Handshake message + optional int32 net_read_timeout = 3 [default = 0]; // in seconds + optional int32 net_write_timeout = 4 [default = 0]; // in seconds + optional string destination = 5; + optional string client_id = 6; + optional string filter = 7; + optional int64 start_timestamp = 8; +} + +message Ack { + optional int32 error_code = 1 [default = 0]; + optional string error_message = 2; // if something like compression is not supported, erorr_message will tell about it. +} + +message ClientAck { + optional string destination = 1; + optional string client_id = 2; + optional int64 batch_id = 3; +} + +// subscription +message Sub { + optional string destination = 1; + optional string client_id = 2; + optional string filter = 7; +} + +// Unsubscription +message Unsub { + optional string destination = 1; + optional string client_id = 2; + optional string filter = 7; +} + +// PullRequest +message Get { + optional string destination = 1; + optional string client_id = 2; + optional int32 fetch_size = 3; + optional int64 timeout = 4 [default = -1]; // 默认-1时代表不控制 + optional int32 unit = 5 [default = 2];// 数字类型,0:纳秒,1:毫秒,2:微秒,3:秒,4:分钟,5:小时,6:天 + optional bool auto_ack = 6 [default = false]; // 是否自动ack +} + +// +message Messages { + optional int64 batch_id = 1; + repeated bytes messages = 2; +} + +// TBD when new packets are required +message Dump{ + optional string journal = 1; + optional int64 position = 2; + optional int64 timestamp = 3 [default = 0]; +} + +message ClientRollback{ + optional string destination = 1; + optional string client_id = 2; + optional int64 batch_id = 3; +} \ No newline at end of file diff --git a/src/Canal.Csharp.Protocol/EntryProtocol.cs b/src/Canal.Csharp.Protocol/EntryProtocol.cs new file mode 100644 index 0000000..5c94c92 --- /dev/null +++ b/src/Canal.Csharp.Protocol/EntryProtocol.cs @@ -0,0 +1,545 @@ +// This file was generated by a tool; you should avoid making direct changes. +// Consider using 'partial classes' to extend these types +// Input: EntryProtocol.proto + +#pragma warning disable CS0612, CS1591, CS3021, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 +namespace com.alibaba.otter.canal.protocol +{ + + [global::ProtoBuf.ProtoContract()] + public partial class Entry : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"header")] + public Header Header { get; set; } + + [global::ProtoBuf.ProtoMember(2)] + [global::System.ComponentModel.DefaultValue(EntryType.Rowdata)] + public EntryType entryType + { + get { return __pbn__entryType ?? EntryType.Rowdata; } + set { __pbn__entryType = value; } + } + public bool ShouldSerializeentryType() => __pbn__entryType != null; + public void ResetentryType() => __pbn__entryType = null; + private EntryType? __pbn__entryType; + + [global::ProtoBuf.ProtoMember(3)] + public byte[] storeValue + { + get { return __pbn__storeValue; } + set { __pbn__storeValue = value; } + } + public bool ShouldSerializestoreValue() => __pbn__storeValue != null; + public void ResetstoreValue() => __pbn__storeValue = null; + private byte[] __pbn__storeValue; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Header : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"version")] + [global::System.ComponentModel.DefaultValue(1)] + public int Version + { + get { return __pbn__Version ?? 1; } + set { __pbn__Version = value; } + } + public bool ShouldSerializeVersion() => __pbn__Version != null; + public void ResetVersion() => __pbn__Version = null; + private int? __pbn__Version; + + [global::ProtoBuf.ProtoMember(2)] + [global::System.ComponentModel.DefaultValue("")] + public string logfileName + { + get { return __pbn__logfileName ?? ""; } + set { __pbn__logfileName = value; } + } + public bool ShouldSerializelogfileName() => __pbn__logfileName != null; + public void ResetlogfileName() => __pbn__logfileName = null; + private string __pbn__logfileName; + + [global::ProtoBuf.ProtoMember(3)] + public long logfileOffset + { + get { return __pbn__logfileOffset.GetValueOrDefault(); } + set { __pbn__logfileOffset = value; } + } + public bool ShouldSerializelogfileOffset() => __pbn__logfileOffset != null; + public void ResetlogfileOffset() => __pbn__logfileOffset = null; + private long? __pbn__logfileOffset; + + [global::ProtoBuf.ProtoMember(4)] + public long serverId + { + get { return __pbn__serverId.GetValueOrDefault(); } + set { __pbn__serverId = value; } + } + public bool ShouldSerializeserverId() => __pbn__serverId != null; + public void ResetserverId() => __pbn__serverId = null; + private long? __pbn__serverId; + + [global::ProtoBuf.ProtoMember(5)] + [global::System.ComponentModel.DefaultValue("")] + public string serverenCode + { + get { return __pbn__serverenCode ?? ""; } + set { __pbn__serverenCode = value; } + } + public bool ShouldSerializeserverenCode() => __pbn__serverenCode != null; + public void ResetserverenCode() => __pbn__serverenCode = null; + private string __pbn__serverenCode; + + [global::ProtoBuf.ProtoMember(6)] + public long executeTime + { + get { return __pbn__executeTime.GetValueOrDefault(); } + set { __pbn__executeTime = value; } + } + public bool ShouldSerializeexecuteTime() => __pbn__executeTime != null; + public void ResetexecuteTime() => __pbn__executeTime = null; + private long? __pbn__executeTime; + + [global::ProtoBuf.ProtoMember(7)] + [global::System.ComponentModel.DefaultValue(Type.Mysql)] + public Type sourceType + { + get { return __pbn__sourceType ?? Type.Mysql; } + set { __pbn__sourceType = value; } + } + public bool ShouldSerializesourceType() => __pbn__sourceType != null; + public void ResetsourceType() => __pbn__sourceType = null; + private Type? __pbn__sourceType; + + [global::ProtoBuf.ProtoMember(8)] + [global::System.ComponentModel.DefaultValue("")] + public string schemaName + { + get { return __pbn__schemaName ?? ""; } + set { __pbn__schemaName = value; } + } + public bool ShouldSerializeschemaName() => __pbn__schemaName != null; + public void ResetschemaName() => __pbn__schemaName = null; + private string __pbn__schemaName; + + [global::ProtoBuf.ProtoMember(9)] + [global::System.ComponentModel.DefaultValue("")] + public string tableName + { + get { return __pbn__tableName ?? ""; } + set { __pbn__tableName = value; } + } + public bool ShouldSerializetableName() => __pbn__tableName != null; + public void ResettableName() => __pbn__tableName = null; + private string __pbn__tableName; + + [global::ProtoBuf.ProtoMember(10)] + public long eventLength + { + get { return __pbn__eventLength.GetValueOrDefault(); } + set { __pbn__eventLength = value; } + } + public bool ShouldSerializeeventLength() => __pbn__eventLength != null; + public void ReseteventLength() => __pbn__eventLength = null; + private long? __pbn__eventLength; + + [global::ProtoBuf.ProtoMember(11)] + [global::System.ComponentModel.DefaultValue(EventType.Update)] + public EventType eventType + { + get { return __pbn__eventType ?? EventType.Update; } + set { __pbn__eventType = value; } + } + public bool ShouldSerializeeventType() => __pbn__eventType != null; + public void ReseteventType() => __pbn__eventType = null; + private EventType? __pbn__eventType; + + [global::ProtoBuf.ProtoMember(12, Name = @"props")] + public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); + + [global::ProtoBuf.ProtoMember(13, Name = @"gtid")] + [global::System.ComponentModel.DefaultValue("")] + public string Gtid + { + get { return __pbn__Gtid ?? ""; } + set { __pbn__Gtid = value; } + } + public bool ShouldSerializeGtid() => __pbn__Gtid != null; + public void ResetGtid() => __pbn__Gtid = null; + private string __pbn__Gtid; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Column : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"index")] + public int Index + { + get { return __pbn__Index.GetValueOrDefault(); } + set { __pbn__Index = value; } + } + public bool ShouldSerializeIndex() => __pbn__Index != null; + public void ResetIndex() => __pbn__Index = null; + private int? __pbn__Index; + + [global::ProtoBuf.ProtoMember(2)] + public int sqlType + { + get { return __pbn__sqlType.GetValueOrDefault(); } + set { __pbn__sqlType = value; } + } + public bool ShouldSerializesqlType() => __pbn__sqlType != null; + public void ResetsqlType() => __pbn__sqlType = null; + private int? __pbn__sqlType; + + [global::ProtoBuf.ProtoMember(3, Name = @"name")] + [global::System.ComponentModel.DefaultValue("")] + public string Name + { + get { return __pbn__Name ?? ""; } + set { __pbn__Name = value; } + } + public bool ShouldSerializeName() => __pbn__Name != null; + public void ResetName() => __pbn__Name = null; + private string __pbn__Name; + + [global::ProtoBuf.ProtoMember(4)] + public bool isKey + { + get { return __pbn__isKey.GetValueOrDefault(); } + set { __pbn__isKey = value; } + } + public bool ShouldSerializeisKey() => __pbn__isKey != null; + public void ResetisKey() => __pbn__isKey = null; + private bool? __pbn__isKey; + + [global::ProtoBuf.ProtoMember(5, Name = @"updated")] + public bool Updated + { + get { return __pbn__Updated.GetValueOrDefault(); } + set { __pbn__Updated = value; } + } + public bool ShouldSerializeUpdated() => __pbn__Updated != null; + public void ResetUpdated() => __pbn__Updated = null; + private bool? __pbn__Updated; + + [global::ProtoBuf.ProtoMember(6)] + [global::System.ComponentModel.DefaultValue(false)] + public bool isNull + { + get { return __pbn__isNull ?? false; } + set { __pbn__isNull = value; } + } + public bool ShouldSerializeisNull() => __pbn__isNull != null; + public void ResetisNull() => __pbn__isNull = null; + private bool? __pbn__isNull; + + [global::ProtoBuf.ProtoMember(7, Name = @"props")] + public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); + + [global::ProtoBuf.ProtoMember(8, Name = @"value")] + [global::System.ComponentModel.DefaultValue("")] + public string Value + { + get { return __pbn__Value ?? ""; } + set { __pbn__Value = value; } + } + public bool ShouldSerializeValue() => __pbn__Value != null; + public void ResetValue() => __pbn__Value = null; + private string __pbn__Value; + + [global::ProtoBuf.ProtoMember(9, Name = @"length")] + public int Length + { + get { return __pbn__Length.GetValueOrDefault(); } + set { __pbn__Length = value; } + } + public bool ShouldSerializeLength() => __pbn__Length != null; + public void ResetLength() => __pbn__Length = null; + private int? __pbn__Length; + + [global::ProtoBuf.ProtoMember(10)] + [global::System.ComponentModel.DefaultValue("")] + public string mysqlType + { + get { return __pbn__mysqlType ?? ""; } + set { __pbn__mysqlType = value; } + } + public bool ShouldSerializemysqlType() => __pbn__mysqlType != null; + public void ResetmysqlType() => __pbn__mysqlType = null; + private string __pbn__mysqlType; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class RowData : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1)] + public global::System.Collections.Generic.List beforeColumns { get; } = new global::System.Collections.Generic.List(); + + [global::ProtoBuf.ProtoMember(2)] + public global::System.Collections.Generic.List afterColumns { get; } = new global::System.Collections.Generic.List(); + + [global::ProtoBuf.ProtoMember(3, Name = @"props")] + public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); + + } + + [global::ProtoBuf.ProtoContract()] + public partial class RowChange : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1)] + public long tableId + { + get { return __pbn__tableId.GetValueOrDefault(); } + set { __pbn__tableId = value; } + } + public bool ShouldSerializetableId() => __pbn__tableId != null; + public void ResettableId() => __pbn__tableId = null; + private long? __pbn__tableId; + + [global::ProtoBuf.ProtoMember(2)] + [global::System.ComponentModel.DefaultValue(EventType.Update)] + public EventType eventType + { + get { return __pbn__eventType ?? EventType.Update; } + set { __pbn__eventType = value; } + } + public bool ShouldSerializeeventType() => __pbn__eventType != null; + public void ReseteventType() => __pbn__eventType = null; + private EventType? __pbn__eventType; + + [global::ProtoBuf.ProtoMember(10)] + [global::System.ComponentModel.DefaultValue(false)] + public bool isDdl + { + get { return __pbn__isDdl ?? false; } + set { __pbn__isDdl = value; } + } + public bool ShouldSerializeisDdl() => __pbn__isDdl != null; + public void ResetisDdl() => __pbn__isDdl = null; + private bool? __pbn__isDdl; + + [global::ProtoBuf.ProtoMember(11, Name = @"sql")] + [global::System.ComponentModel.DefaultValue("")] + public string Sql + { + get { return __pbn__Sql ?? ""; } + set { __pbn__Sql = value; } + } + public bool ShouldSerializeSql() => __pbn__Sql != null; + public void ResetSql() => __pbn__Sql = null; + private string __pbn__Sql; + + [global::ProtoBuf.ProtoMember(12)] + public global::System.Collections.Generic.List rowDatas { get; } = new global::System.Collections.Generic.List(); + + [global::ProtoBuf.ProtoMember(13, Name = @"props")] + public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); + + [global::ProtoBuf.ProtoMember(14)] + [global::System.ComponentModel.DefaultValue("")] + public string ddlSchemaName + { + get { return __pbn__ddlSchemaName ?? ""; } + set { __pbn__ddlSchemaName = value; } + } + public bool ShouldSerializeddlSchemaName() => __pbn__ddlSchemaName != null; + public void ResetddlSchemaName() => __pbn__ddlSchemaName = null; + private string __pbn__ddlSchemaName; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class TransactionBegin : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1)] + public long executeTime + { + get { return __pbn__executeTime.GetValueOrDefault(); } + set { __pbn__executeTime = value; } + } + public bool ShouldSerializeexecuteTime() => __pbn__executeTime != null; + public void ResetexecuteTime() => __pbn__executeTime = null; + private long? __pbn__executeTime; + + [global::ProtoBuf.ProtoMember(2)] + [global::System.ComponentModel.DefaultValue("")] + public string transactionId + { + get { return __pbn__transactionId ?? ""; } + set { __pbn__transactionId = value; } + } + public bool ShouldSerializetransactionId() => __pbn__transactionId != null; + public void ResettransactionId() => __pbn__transactionId = null; + private string __pbn__transactionId; + + [global::ProtoBuf.ProtoMember(3, Name = @"props")] + public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); + + [global::ProtoBuf.ProtoMember(4)] + public long threadId + { + get { return __pbn__threadId.GetValueOrDefault(); } + set { __pbn__threadId = value; } + } + public bool ShouldSerializethreadId() => __pbn__threadId != null; + public void ResetthreadId() => __pbn__threadId = null; + private long? __pbn__threadId; + + } + + [global::ProtoBuf.ProtoContract()] + public partial class TransactionEnd : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1)] + public long executeTime + { + get { return __pbn__executeTime.GetValueOrDefault(); } + set { __pbn__executeTime = value; } + } + public bool ShouldSerializeexecuteTime() => __pbn__executeTime != null; + public void ResetexecuteTime() => __pbn__executeTime = null; + private long? __pbn__executeTime; + + [global::ProtoBuf.ProtoMember(2)] + [global::System.ComponentModel.DefaultValue("")] + public string transactionId + { + get { return __pbn__transactionId ?? ""; } + set { __pbn__transactionId = value; } + } + public bool ShouldSerializetransactionId() => __pbn__transactionId != null; + public void ResettransactionId() => __pbn__transactionId = null; + private string __pbn__transactionId; + + [global::ProtoBuf.ProtoMember(3, Name = @"props")] + public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); + + } + + [global::ProtoBuf.ProtoContract()] + public partial class Pair : global::ProtoBuf.IExtensible + { + private global::ProtoBuf.IExtension __pbn__extensionData; + global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) + => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + + [global::ProtoBuf.ProtoMember(1, Name = @"key")] + [global::System.ComponentModel.DefaultValue("")] + public string Key + { + get { return __pbn__Key ?? ""; } + set { __pbn__Key = value; } + } + public bool ShouldSerializeKey() => __pbn__Key != null; + public void ResetKey() => __pbn__Key = null; + private string __pbn__Key; + + [global::ProtoBuf.ProtoMember(2, Name = @"value")] + [global::System.ComponentModel.DefaultValue("")] + public string Value + { + get { return __pbn__Value ?? ""; } + set { __pbn__Value = value; } + } + public bool ShouldSerializeValue() => __pbn__Value != null; + public void ResetValue() => __pbn__Value = null; + private string __pbn__Value; + + } + + [global::ProtoBuf.ProtoContract()] + public enum EntryType + { + [global::ProtoBuf.ProtoEnum(Name = @"TRANSACTIONBEGIN")] + Transactionbegin = 1, + [global::ProtoBuf.ProtoEnum(Name = @"ROWDATA")] + Rowdata = 2, + [global::ProtoBuf.ProtoEnum(Name = @"TRANSACTIONEND")] + Transactionend = 3, + [global::ProtoBuf.ProtoEnum(Name = @"HEARTBEAT")] + Heartbeat = 4, + [global::ProtoBuf.ProtoEnum(Name = @"GTIDLOG")] + Gtidlog = 5, + } + + [global::ProtoBuf.ProtoContract()] + public enum EventType + { + [global::ProtoBuf.ProtoEnum(Name = @"INSERT")] + Insert = 1, + [global::ProtoBuf.ProtoEnum(Name = @"UPDATE")] + Update = 2, + [global::ProtoBuf.ProtoEnum(Name = @"DELETE")] + Delete = 3, + [global::ProtoBuf.ProtoEnum(Name = @"CREATE")] + Create = 4, + [global::ProtoBuf.ProtoEnum(Name = @"ALTER")] + Alter = 5, + [global::ProtoBuf.ProtoEnum(Name = @"ERASE")] + Erase = 6, + [global::ProtoBuf.ProtoEnum(Name = @"QUERY")] + Query = 7, + [global::ProtoBuf.ProtoEnum(Name = @"TRUNCATE")] + Truncate = 8, + [global::ProtoBuf.ProtoEnum(Name = @"RENAME")] + Rename = 9, + [global::ProtoBuf.ProtoEnum(Name = @"CINDEX")] + Cindex = 10, + [global::ProtoBuf.ProtoEnum(Name = @"DINDEX")] + Dindex = 11, + [global::ProtoBuf.ProtoEnum(Name = @"GTID")] + Gtid = 12, + [global::ProtoBuf.ProtoEnum(Name = @"XACOMMIT")] + Xacommit = 13, + [global::ProtoBuf.ProtoEnum(Name = @"XAROLLBACK")] + Xarollback = 14, + [global::ProtoBuf.ProtoEnum(Name = @"MHEARTBEAT")] + Mheartbeat = 15, + } + + [global::ProtoBuf.ProtoContract()] + public enum Type + { + [global::ProtoBuf.ProtoEnum(Name = @"ORACLE")] + Oracle = 1, + [global::ProtoBuf.ProtoEnum(Name = @"MYSQL")] + Mysql = 2, + [global::ProtoBuf.ProtoEnum(Name = @"PGSQL")] + Pgsql = 3, + } + +} + +#pragma warning restore CS0612, CS1591, CS3021, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 diff --git a/src/Canal.Csharp.Protocol/EntryProtocol.proto b/src/Canal.Csharp.Protocol/EntryProtocol.proto new file mode 100644 index 0000000..5878ecf --- /dev/null +++ b/src/Canal.Csharp.Protocol/EntryProtocol.proto @@ -0,0 +1,207 @@ +syntax = "proto2"; +package com.alibaba.otter.canal.protocol; + +option java_package = "com.alibaba.otter.canal.protocol"; +option java_outer_classname = "CanalEntry"; +option optimize_for = SPEED; + +/**************************************************************** + * message model + *如果要在Enum中新增类型,确保以前的类型的下标值不变. + ****************************************************************/ +message Entry { + /**协议头部信息**/ + optional Header header = 1; + + /**打散后的事件类型**/ + optional EntryType entryType = 2 [default = ROWDATA]; + + /**传输的二进制数组**/ + optional bytes storeValue = 3; +} + +/**message Header**/ +message Header { + /**协议的版本号**/ + optional int32 version = 1 [default = 1]; + + /**binlog/redolog 文件名**/ + optional string logfileName = 2; + + /**binlog/redolog 文件的偏移位置**/ + optional int64 logfileOffset = 3; + + /**服务端serverId**/ + optional int64 serverId = 4; + + /** 变更数据的编码 **/ + optional string serverenCode = 5; + + /**变更数据的执行时间 **/ + optional int64 executeTime = 6; + + /** 变更数据的来源**/ + optional Type sourceType = 7 [default = MYSQL]; + + /** 变更数据的schemaname**/ + optional string schemaName = 8; + + /**变更数据的tablename**/ + optional string tableName = 9; + + /**每个event的长度**/ + optional int64 eventLength = 10; + + /**数据变更类型**/ + optional EventType eventType = 11 [default = UPDATE]; + + /**预留扩展**/ + repeated Pair props = 12; + + /**当前事务的gitd**/ + optional string gtid = 13; +} + +/**每个字段的数据结构**/ +message Column { + /**字段下标**/ + optional int32 index = 1; + + /**字段java中类型**/ + optional int32 sqlType = 2; + + /**字段名称(忽略大小写),在mysql中是没有的**/ + optional string name = 3; + + /**是否是主键**/ + optional bool isKey = 4; + + /**如果EventType=UPDATE,用于标识这个字段值是否有修改**/ + optional bool updated = 5; + + /** 标识是否为空 **/ + optional bool isNull = 6 [default = false]; + + /**预留扩展**/ + repeated Pair props = 7; + + /** 字段值,timestamp,Datetime是一个时间格式的文本 **/ + optional string value = 8; + + /** 对应数据对象原始长度 **/ + optional int32 length = 9; + + /**字段mysql类型**/ + optional string mysqlType = 10; +} + +message RowData { + + /** 字段信息,增量数据(修改前,删除前) **/ + repeated Column beforeColumns = 1; + + /** 字段信息,增量数据(修改后,新增后) **/ + repeated Column afterColumns = 2; + + /**预留扩展**/ + repeated Pair props = 3; +} + +/**message row 每行变更数据的数据结构**/ +message RowChange { + + /**tableId,由数据库产生**/ + optional int64 tableId = 1; + + /**数据变更类型**/ + optional EventType eventType = 2 [default = UPDATE]; + + /** 标识是否是ddl语句 **/ + optional bool isDdl = 10 [default = false]; + + /** ddl/query的sql语句 **/ + optional string sql = 11; + + /** 一次数据库变更可能存在多行 **/ + repeated RowData rowDatas = 12; + + /**预留扩展**/ + repeated Pair props = 13; + + /** ddl/query的schemaName,会存在跨库ddl,需要保留执行ddl的当前schemaName **/ + optional string ddlSchemaName = 14; +} + +/**开始事务的一些信息**/ +message TransactionBegin{ + + /**已废弃,请使用header里的executeTime**/ + optional int64 executeTime = 1; + + /**已废弃,Begin里不提供事务id**/ + optional string transactionId = 2; + + /**预留扩展**/ + repeated Pair props = 3; + + /**执行的thread Id**/ + optional int64 threadId = 4; +} + +/**结束事务的一些信息**/ +message TransactionEnd{ + + /**已废弃,请使用header里的executeTime**/ + optional int64 executeTime = 1; + + /**事务号**/ + optional string transactionId = 2; + + /**预留扩展**/ + repeated Pair props = 3; +} + +/**预留扩展**/ +message Pair{ + optional string key = 1; + optional string value = 2; +} + +/**打散后的事件类型,主要用于标识事务的开始,变更数据,结束**/ +enum EntryType{ + TRANSACTIONBEGIN = 1; + ROWDATA = 2; + TRANSACTIONEND = 3; + /** 心跳类型,内部使用,外部暂不可见,可忽略 **/ + HEARTBEAT = 4; + GTIDLOG = 5; +} + +/** 事件类型 **/ +enum EventType { + INSERT = 1; + UPDATE = 2; + DELETE = 3; + CREATE = 4; + ALTER = 5; + ERASE = 6; + QUERY = 7; + TRUNCATE = 8; + RENAME = 9; + /**CREATE INDEX**/ + CINDEX = 10; + DINDEX = 11; + GTID = 12; + /** XA **/ + XACOMMIT = 13; + XAROLLBACK = 14; + /** MASTER HEARTBEAT **/ + MHEARTBEAT = 15; +} + +/**数据库类型**/ +enum Type { + ORACLE = 1; + MYSQL = 2; + PGSQL = 3; +} From b5f7f252388d86352d88e7d42ba03512c105fcfd Mon Sep 17 00:00:00 2001 From: WithLin Date: Fri, 7 Sep 2018 10:31:13 +0800 Subject: [PATCH 02/50] Fix sln compile error --- canal-csharp.sln => canal-client-csharp.sln | 26 +++++---------------- 1 file changed, 6 insertions(+), 20 deletions(-) rename canal-csharp.sln => canal-client-csharp.sln (55%) diff --git a/canal-csharp.sln b/canal-client-csharp.sln similarity index 55% rename from canal-csharp.sln rename to canal-client-csharp.sln index da99473..25f78f6 100644 --- a/canal-csharp.sln +++ b/canal-client-csharp.sln @@ -16,13 +16,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{BD70CDB7-9 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net", "src\Canal4Net\Canal4Net.csproj", "{3611D6F6-FFAC-4CFE-A160-22E08AD0F2FA}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net.UnitTests", "test\Canal4Net.UnitTests\Canal4Net.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net.Core", "src\Canal4Net.Core\Canal4Net.Core.csproj", "{2D53A810-8638-41F3-8DE7-19C47E7BC129}" -EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net.Protocol", "src\Canal4Net.Protocol\Canal4Net.Protocol.csproj", "{D28DD917-DB36-4FBE-9D6A-7E09660563AF}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal.Csharp.Abstract", "src\Canal.Csharp.Abstract\Canal.Csharp.Abstract.csproj", "{C61A468E-66C4-4915-9C2C-91936EB99F2A}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -30,31 +26,21 @@ Global Release|Any CPU = Release|Any CPU EndGlobalSection GlobalSection(ProjectConfigurationPlatforms) = postSolution - {3611D6F6-FFAC-4CFE-A160-22E08AD0F2FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {3611D6F6-FFAC-4CFE-A160-22E08AD0F2FA}.Debug|Any CPU.Build.0 = Debug|Any CPU - {3611D6F6-FFAC-4CFE-A160-22E08AD0F2FA}.Release|Any CPU.ActiveCfg = Release|Any CPU - {3611D6F6-FFAC-4CFE-A160-22E08AD0F2FA}.Release|Any CPU.Build.0 = Release|Any CPU {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Debug|Any CPU.Build.0 = Debug|Any CPU {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Release|Any CPU.ActiveCfg = Release|Any CPU {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Release|Any CPU.Build.0 = Release|Any CPU - {2D53A810-8638-41F3-8DE7-19C47E7BC129}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {2D53A810-8638-41F3-8DE7-19C47E7BC129}.Debug|Any CPU.Build.0 = Debug|Any CPU - {2D53A810-8638-41F3-8DE7-19C47E7BC129}.Release|Any CPU.ActiveCfg = Release|Any CPU - {2D53A810-8638-41F3-8DE7-19C47E7BC129}.Release|Any CPU.Build.0 = Release|Any CPU - {D28DD917-DB36-4FBE-9D6A-7E09660563AF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {D28DD917-DB36-4FBE-9D6A-7E09660563AF}.Debug|Any CPU.Build.0 = Debug|Any CPU - {D28DD917-DB36-4FBE-9D6A-7E09660563AF}.Release|Any CPU.ActiveCfg = Release|Any CPU - {D28DD917-DB36-4FBE-9D6A-7E09660563AF}.Release|Any CPU.Build.0 = Release|Any CPU + {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU + {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU + {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE EndGlobalSection GlobalSection(NestedProjects) = preSolution - {3611D6F6-FFAC-4CFE-A160-22E08AD0F2FA} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} {83F407DD-5810-422F-8AF6-4E9BA75AC678} = {BD70CDB7-94E9-4621-B702-DC04DB9D59EF} - {2D53A810-8638-41F3-8DE7-19C47E7BC129} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} - {D28DD917-DB36-4FBE-9D6A-7E09660563AF} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} + {C61A468E-66C4-4915-9C2C-91936EB99F2A} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FD9B9146-8418-4F80-A666-9B47BE4F9C9C} From 5ade140ddc4a36ae892385fc108a6f2b345d75ed Mon Sep 17 00:00:00 2001 From: XiaoFu Date: Fri, 7 Sep 2018 10:37:59 +0800 Subject: [PATCH 03/50] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index ba627bb..2186861 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ -# Canal4Net +# canal-client-csharp C# client for canal. https://github.com/alibaba/canal From 9cd504c9984b33cd9dc183d83ca7bccc4712a5d1 Mon Sep 17 00:00:00 2001 From: XiaoFu Date: Fri, 7 Sep 2018 10:38:11 +0800 Subject: [PATCH 04/50] Update README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 2186861..afb81d4 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,2 @@ # canal-client-csharp -C# client for canal. https://github.com/alibaba/canal +The .NET canal client for Alibaba canal https://github.com/alibaba/canal From 0dcc689cfdae09d0c23382b7df1fc3ddf7f8f583 Mon Sep 17 00:00:00 2001 From: WithLin Date: Fri, 7 Sep 2018 10:39:19 +0800 Subject: [PATCH 05/50] Fix sln --- canal-client-csharp.sln | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/canal-client-csharp.sln b/canal-client-csharp.sln index 25f78f6..6c97223 100644 --- a/canal-client-csharp.sln +++ b/canal-client-csharp.sln @@ -20,6 +20,10 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net.UnitTests", "test EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal.Csharp.Abstract", "src\Canal.Csharp.Abstract\Canal.Csharp.Abstract.csproj", "{C61A468E-66C4-4915-9C2C-91936EB99F2A}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal.Csharp.Core", "src\Canal.Csharp.Core\Canal.Csharp.Core.csproj", "{E33BCF38-D450-4AFE-B409-E6E7C0251479}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal.Csharp.Protocol", "src\Canal.Csharp.Protocol\Canal.Csharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -34,6 +38,14 @@ Global {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Release|Any CPU.Build.0 = Release|Any CPU + {E33BCF38-D450-4AFE-B409-E6E7C0251479}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {E33BCF38-D450-4AFE-B409-E6E7C0251479}.Debug|Any CPU.Build.0 = Debug|Any CPU + {E33BCF38-D450-4AFE-B409-E6E7C0251479}.Release|Any CPU.ActiveCfg = Release|Any CPU + {E33BCF38-D450-4AFE-B409-E6E7C0251479}.Release|Any CPU.Build.0 = Release|Any CPU + {B9782080-16BD-4328-A394-3EC8D9B49326}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B9782080-16BD-4328-A394-3EC8D9B49326}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B9782080-16BD-4328-A394-3EC8D9B49326}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B9782080-16BD-4328-A394-3EC8D9B49326}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -41,6 +53,8 @@ Global GlobalSection(NestedProjects) = preSolution {83F407DD-5810-422F-8AF6-4E9BA75AC678} = {BD70CDB7-94E9-4621-B702-DC04DB9D59EF} {C61A468E-66C4-4915-9C2C-91936EB99F2A} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} + {E33BCF38-D450-4AFE-B409-E6E7C0251479} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} + {B9782080-16BD-4328-A394-3EC8D9B49326} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FD9B9146-8418-4F80-A666-9B47BE4F9C9C} From 745f6c9447cd0fd45451dc901a93d3feca77a41c Mon Sep 17 00:00:00 2001 From: WithLin Date: Thu, 13 Sep 2018 18:52:22 +0800 Subject: [PATCH 06/50] fix upgrade proto2 to proto3 --- src/Canal.Csharp.Protocol/CanalProtocol.cs | 3367 ++++++++++++++--- src/Canal.Csharp.Protocol/CanalProtocol.proto | 125 +- src/Canal.Csharp.Protocol/EntryProtocol.cs | 2947 ++++++++++++--- src/Canal.Csharp.Protocol/EntryProtocol.proto | 115 +- 4 files changed, 5419 insertions(+), 1135 deletions(-) diff --git a/src/Canal.Csharp.Protocol/CanalProtocol.cs b/src/Canal.Csharp.Protocol/CanalProtocol.cs index 2f92f22..5e67c62 100644 --- a/src/Canal.Csharp.Protocol/CanalProtocol.cs +++ b/src/Canal.Csharp.Protocol/CanalProtocol.cs @@ -1,607 +1,2884 @@ -// This file was generated by a tool; you should avoid making direct changes. -// Consider using 'partial classes' to extend these types -// Input: CanalProtocol.proto - -#pragma warning disable CS0612, CS1591, CS3021, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 -namespace com.alibaba.otter.canal.protocol -{ - - [global::ProtoBuf.ProtoContract()] - public partial class Packet : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); - - [global::ProtoBuf.ProtoMember(1, Name = @"magic_number")] - [global::System.ComponentModel.DefaultValue(17)] - public int MagicNumber - { - get { return __pbn__MagicNumber ?? 17; } - set { __pbn__MagicNumber = value; } - } - public bool ShouldSerializeMagicNumber() => __pbn__MagicNumber != null; - public void ResetMagicNumber() => __pbn__MagicNumber = null; - private int? __pbn__MagicNumber; - - [global::ProtoBuf.ProtoMember(2, Name = @"version")] - [global::System.ComponentModel.DefaultValue(1)] - public int Version - { - get { return __pbn__Version ?? 1; } - set { __pbn__Version = value; } - } - public bool ShouldSerializeVersion() => __pbn__Version != null; - public void ResetVersion() => __pbn__Version = null; - private int? __pbn__Version; - - [global::ProtoBuf.ProtoMember(3, Name = @"type")] - [global::System.ComponentModel.DefaultValue(PacketType.Handshake)] - public PacketType Type - { - get { return __pbn__Type ?? PacketType.Handshake; } - set { __pbn__Type = value; } - } - public bool ShouldSerializeType() => __pbn__Type != null; - public void ResetType() => __pbn__Type = null; - private PacketType? __pbn__Type; - - [global::ProtoBuf.ProtoMember(4, Name = @"compression")] - [global::System.ComponentModel.DefaultValue(Compression.None)] - public Compression Compression - { - get { return __pbn__Compression ?? Compression.None; } - set { __pbn__Compression = value; } - } - public bool ShouldSerializeCompression() => __pbn__Compression != null; - public void ResetCompression() => __pbn__Compression = null; - private Compression? __pbn__Compression; - - [global::ProtoBuf.ProtoMember(5, Name = @"body")] - public byte[] Body - { - get { return __pbn__Body; } - set { __pbn__Body = value; } - } - public bool ShouldSerializeBody() => __pbn__Body != null; - public void ResetBody() => __pbn__Body = null; - private byte[] __pbn__Body; +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: CanalProtocol.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Com.Alibaba.Otter.Canal.Protocol { + + /// Holder for reflection information generated from CanalProtocol.proto + public static partial class CanalProtocolReflection { + + #region Descriptor + /// File descriptor for CanalProtocol.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static CanalProtocolReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChNDYW5hbFByb3RvY29sLnByb3RvEiBjb20uYWxpYmFiYS5vdHRlci5jYW5h", + "bC5wcm90b2NvbCKFAgoGUGFja2V0EhYKDG1hZ2ljX251bWJlchgBIAEoBUgA", + "EhEKB3ZlcnNpb24YAiABKAVIARI6CgR0eXBlGAMgASgOMiwuY29tLmFsaWJh", + "YmEub3R0ZXIuY2FuYWwucHJvdG9jb2wuUGFja2V0VHlwZRJECgtjb21wcmVz", + "c2lvbhgEIAEoDjItLmNvbS5hbGliYWJhLm90dGVyLmNhbmFsLnByb3RvY29s", + "LkNvbXByZXNzaW9uSAISDAoEYm9keRgFIAEoDEIWChRtYWdpY19udW1iZXJf", + "cHJlc2VudEIRCg92ZXJzaW9uX3ByZXNlbnRCFQoTY29tcHJlc3Npb25fcHJl", + "c2VudCI8CglIZWFydEJlYXQSFgoOc2VuZF90aW1lc3RhbXAYASABKAMSFwoP", + "c3RhcnRfdGltZXN0YW1wGAIgASgDIq0BCglIYW5kc2hha2USIAoWY29tbXVu", + "aWNhdGlvbl9lbmNvZGluZxgBIAEoCUgAEg0KBXNlZWRzGAIgASgMEk0KFnN1", + "cHBvcnRlZF9jb21wcmVzc2lvbnMYAyABKA4yLS5jb20uYWxpYmFiYS5vdHRl", + "ci5jYW5hbC5wcm90b2NvbC5Db21wcmVzc2lvbkIgCh5jb21tdW5pY2F0aW9u", + "X2VuY29kaW5nX3ByZXNlbnQi8wEKCkNsaWVudEF1dGgSEAoIdXNlcm5hbWUY", + "ASABKAkSEAoIcGFzc3dvcmQYAiABKAwSGgoQbmV0X3JlYWRfdGltZW91dBgD", + "IAEoBUgAEhsKEW5ldF93cml0ZV90aW1lb3V0GAQgASgFSAESEwoLZGVzdGlu", + "YXRpb24YBSABKAkSEQoJY2xpZW50X2lkGAYgASgJEg4KBmZpbHRlchgHIAEo", + "CRIXCg9zdGFydF90aW1lc3RhbXAYCCABKANCGgoYbmV0X3JlYWRfdGltZW91", + "dF9wcmVzZW50QhsKGW5ldF93cml0ZV90aW1lb3V0X3ByZXNlbnQiSAoDQWNr", + "EhQKCmVycm9yX2NvZGUYASABKAVIABIVCg1lcnJvcl9tZXNzYWdlGAIgASgJ", + "QhQKEmVycm9yX2NvZGVfcHJlc2VudCJFCglDbGllbnRBY2sSEwoLZGVzdGlu", + "YXRpb24YASABKAkSEQoJY2xpZW50X2lkGAIgASgJEhAKCGJhdGNoX2lkGAMg", + "ASgDIj0KA1N1YhITCgtkZXN0aW5hdGlvbhgBIAEoCRIRCgljbGllbnRfaWQY", + "AiABKAkSDgoGZmlsdGVyGAcgASgJIj8KBVVuc3ViEhMKC2Rlc3RpbmF0aW9u", + "GAEgASgJEhEKCWNsaWVudF9pZBgCIAEoCRIOCgZmaWx0ZXIYByABKAkirwEK", + "A0dldBITCgtkZXN0aW5hdGlvbhgBIAEoCRIRCgljbGllbnRfaWQYAiABKAkS", + "EgoKZmV0Y2hfc2l6ZRgDIAEoBRIRCgd0aW1lb3V0GAQgASgDSAASDgoEdW5p", + "dBgFIAEoBUgBEhIKCGF1dG9fYWNrGAYgASgISAJCEQoPdGltZW91dF9wcmVz", + "ZW50Qg4KDHVuaXRfcHJlc2VudEISChBhdXRvX2Fja19wcmVzZW50Ii4KCE1l", + "c3NhZ2VzEhAKCGJhdGNoX2lkGAEgASgDEhAKCG1lc3NhZ2VzGAIgAygMIlMK", + "BER1bXASDwoHam91cm5hbBgBIAEoCRIQCghwb3NpdGlvbhgCIAEoAxITCgl0", + "aW1lc3RhbXAYAyABKANIAEITChF0aW1lc3RhbXBfcHJlc2VudCJKCg5DbGll", + "bnRSb2xsYmFjaxITCgtkZXN0aW5hdGlvbhgBIAEoCRIRCgljbGllbnRfaWQY", + "AiABKAkSEAoIYmF0Y2hfaWQYAyABKAMqVQoLQ29tcHJlc3Npb24SHwobQ09N", + "UFJFU1NJT05DT01QQVRJQkxFUFJPVE8yEAASCAoETk9ORRABEggKBFpMSUIQ", + "AhIICgRHWklQEAMSBwoDTFpGEAQq5gEKClBhY2tldFR5cGUSHwobUEFDS0FH", + "RVRZUEVDT01QQVRJQkxFUFJPVE8yEAASDQoJSEFORFNIQUtFEAESGAoUQ0xJ", + "RU5UQVVUSEVOVElDQVRJT04QAhIHCgNBQ0sQAxIQCgxTVUJTQ1JJUFRJT04Q", + "BBISCg5VTlNVQlNDUklQVElPThAFEgcKA0dFVBAGEgwKCE1FU1NBR0VTEAcS", + "DQoJQ0xJRU5UQUNLEAgSDAoIU0hVVERPV04QCRIICgREVU1QEAoSDQoJSEVB", + "UlRCRUFUEAsSEgoOQ0xJRU5UUk9MTEJBQ0sQDEIxCiBjb20uYWxpYmFiYS5v", + "dHRlci5jYW5hbC5wcm90b2NvbEILQ2FuYWxQYWNrZXRIAWIGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Com.Alibaba.Otter.Canal.Protocol.Compression), typeof(global::Com.Alibaba.Otter.Canal.Protocol.PacketType), }, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Packet), global::Com.Alibaba.Otter.Canal.Protocol.Packet.Parser, new[]{ "MagicNumber", "Version", "Type", "Compression", "Body" }, new[]{ "MagicNumberPresent", "VersionPresent", "CompressionPresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.HeartBeat), global::Com.Alibaba.Otter.Canal.Protocol.HeartBeat.Parser, new[]{ "SendTimestamp", "StartTimestamp" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Handshake), global::Com.Alibaba.Otter.Canal.Protocol.Handshake.Parser, new[]{ "CommunicationEncoding", "Seeds", "SupportedCompressions" }, new[]{ "CommunicationEncodingPresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.ClientAuth), global::Com.Alibaba.Otter.Canal.Protocol.ClientAuth.Parser, new[]{ "Username", "Password", "NetReadTimeout", "NetWriteTimeout", "Destination", "ClientId", "Filter", "StartTimestamp" }, new[]{ "NetReadTimeoutPresent", "NetWriteTimeoutPresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Ack), global::Com.Alibaba.Otter.Canal.Protocol.Ack.Parser, new[]{ "ErrorCode", "ErrorMessage" }, new[]{ "ErrorCodePresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.ClientAck), global::Com.Alibaba.Otter.Canal.Protocol.ClientAck.Parser, new[]{ "Destination", "ClientId", "BatchId" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Sub), global::Com.Alibaba.Otter.Canal.Protocol.Sub.Parser, new[]{ "Destination", "ClientId", "Filter" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Unsub), global::Com.Alibaba.Otter.Canal.Protocol.Unsub.Parser, new[]{ "Destination", "ClientId", "Filter" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Get), global::Com.Alibaba.Otter.Canal.Protocol.Get.Parser, new[]{ "Destination", "ClientId", "FetchSize", "Timeout", "Unit", "AutoAck" }, new[]{ "TimeoutPresent", "UnitPresent", "AutoAckPresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Messages), global::Com.Alibaba.Otter.Canal.Protocol.Messages.Parser, new[]{ "BatchId", "Messages_" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Dump), global::Com.Alibaba.Otter.Canal.Protocol.Dump.Parser, new[]{ "Journal", "Position", "Timestamp" }, new[]{ "TimestampPresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.ClientRollback), global::Com.Alibaba.Otter.Canal.Protocol.ClientRollback.Parser, new[]{ "Destination", "ClientId", "BatchId" }, null, null, null) + })); + } + #endregion + + } + #region Enums + public enum Compression { + [pbr::OriginalName("COMPRESSIONCOMPATIBLEPROTO2")] Compatibleproto2 = 0, + [pbr::OriginalName("NONE")] None = 1, + [pbr::OriginalName("ZLIB")] Zlib = 2, + [pbr::OriginalName("GZIP")] Gzip = 3, + [pbr::OriginalName("LZF")] Lzf = 4, + } + + public enum PacketType { + /// + ///compatible + /// + [pbr::OriginalName("PACKAGETYPECOMPATIBLEPROTO2")] Packagetypecompatibleproto2 = 0, + [pbr::OriginalName("HANDSHAKE")] Handshake = 1, + [pbr::OriginalName("CLIENTAUTHENTICATION")] Clientauthentication = 2, + [pbr::OriginalName("ACK")] Ack = 3, + [pbr::OriginalName("SUBSCRIPTION")] Subscription = 4, + [pbr::OriginalName("UNSUBSCRIPTION")] Unsubscription = 5, + [pbr::OriginalName("GET")] Get = 6, + [pbr::OriginalName("MESSAGES")] Messages = 7, + [pbr::OriginalName("CLIENTACK")] Clientack = 8, + /// + /// management part + /// + [pbr::OriginalName("SHUTDOWN")] Shutdown = 9, + /// + /// integration + /// + [pbr::OriginalName("DUMP")] Dump = 10, + [pbr::OriginalName("HEARTBEAT")] Heartbeat = 11, + [pbr::OriginalName("CLIENTROLLBACK")] Clientrollback = 12, + } + + #endregion + + #region Messages + public sealed partial class Packet : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Packet()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[0]; } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } } - [global::ProtoBuf.ProtoContract()] - public partial class HeartBeat : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Packet() { + OnConstruction(); + } - [global::ProtoBuf.ProtoMember(1, Name = @"send_timestamp")] - public long SendTimestamp - { - get { return __pbn__SendTimestamp.GetValueOrDefault(); } - set { __pbn__SendTimestamp = value; } - } - public bool ShouldSerializeSendTimestamp() => __pbn__SendTimestamp != null; - public void ResetSendTimestamp() => __pbn__SendTimestamp = null; - private long? __pbn__SendTimestamp; - - [global::ProtoBuf.ProtoMember(2, Name = @"start_timestamp")] - public long StartTimestamp - { - get { return __pbn__StartTimestamp.GetValueOrDefault(); } - set { __pbn__StartTimestamp = value; } - } - public bool ShouldSerializeStartTimestamp() => __pbn__StartTimestamp != null; - public void ResetStartTimestamp() => __pbn__StartTimestamp = null; - private long? __pbn__StartTimestamp; + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Packet(Packet other) : this() { + type_ = other.type_; + body_ = other.body_; + switch (other.MagicNumberPresentCase) { + case MagicNumberPresentOneofCase.MagicNumber: + MagicNumber = other.MagicNumber; + break; + } + + switch (other.VersionPresentCase) { + case VersionPresentOneofCase.Version: + Version = other.Version; + break; + } + + switch (other.CompressionPresentCase) { + case CompressionPresentOneofCase.Compression: + Compression = other.Compression; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Packet Clone() { + return new Packet(this); } - [global::ProtoBuf.ProtoContract()] - public partial class Handshake : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + /// Field number for the "magic_number" field. + public const int MagicNumberFieldNumber = 1; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int MagicNumber { + get { return magicNumberPresentCase_ == MagicNumberPresentOneofCase.MagicNumber ? (int) magicNumberPresent_ : 0; } + set { + magicNumberPresent_ = value; + magicNumberPresentCase_ = MagicNumberPresentOneofCase.MagicNumber; + } + } - [global::ProtoBuf.ProtoMember(1, Name = @"communication_encoding")] - [global::System.ComponentModel.DefaultValue(@"utf8")] - public string CommunicationEncoding - { - get { return __pbn__CommunicationEncoding ?? @"utf8"; } - set { __pbn__CommunicationEncoding = value; } - } - public bool ShouldSerializeCommunicationEncoding() => __pbn__CommunicationEncoding != null; - public void ResetCommunicationEncoding() => __pbn__CommunicationEncoding = null; - private string __pbn__CommunicationEncoding; - - [global::ProtoBuf.ProtoMember(2, Name = @"seeds")] - public byte[] Seeds - { - get { return __pbn__Seeds; } - set { __pbn__Seeds = value; } - } - public bool ShouldSerializeSeeds() => __pbn__Seeds != null; - public void ResetSeeds() => __pbn__Seeds = null; - private byte[] __pbn__Seeds; + /// Field number for the "version" field. + public const int VersionFieldNumber = 2; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Version { + get { return versionPresentCase_ == VersionPresentOneofCase.Version ? (int) versionPresent_ : 0; } + set { + versionPresent_ = value; + versionPresentCase_ = VersionPresentOneofCase.Version; + } + } - [global::ProtoBuf.ProtoMember(3, Name = @"supported_compressions")] - public global::System.Collections.Generic.List SupportedCompressions { get; } = new global::System.Collections.Generic.List(); + /// Field number for the "type" field. + public const int TypeFieldNumber = 3; + private global::Com.Alibaba.Otter.Canal.Protocol.PacketType type_ = 0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Com.Alibaba.Otter.Canal.Protocol.PacketType Type { + get { return type_; } + set { + type_ = value; + } + } + /// Field number for the "compression" field. + public const int CompressionFieldNumber = 4; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Com.Alibaba.Otter.Canal.Protocol.Compression Compression { + get { return compressionPresentCase_ == CompressionPresentOneofCase.Compression ? (global::Com.Alibaba.Otter.Canal.Protocol.Compression) compressionPresent_ : 0; } + set { + compressionPresent_ = value; + compressionPresentCase_ = CompressionPresentOneofCase.Compression; + } } - [global::ProtoBuf.ProtoContract()] - public partial class ClientAuth : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + /// Field number for the "body" field. + public const int BodyFieldNumber = 5; + private pb::ByteString body_ = pb::ByteString.Empty; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pb::ByteString Body { + get { return body_; } + set { + body_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } - [global::ProtoBuf.ProtoMember(1, Name = @"username")] - [global::System.ComponentModel.DefaultValue("")] - public string Username - { - get { return __pbn__Username ?? ""; } - set { __pbn__Username = value; } - } - public bool ShouldSerializeUsername() => __pbn__Username != null; - public void ResetUsername() => __pbn__Username = null; - private string __pbn__Username; - - [global::ProtoBuf.ProtoMember(2, Name = @"password")] - public byte[] Password - { - get { return __pbn__Password; } - set { __pbn__Password = value; } - } - public bool ShouldSerializePassword() => __pbn__Password != null; - public void ResetPassword() => __pbn__Password = null; - private byte[] __pbn__Password; - - [global::ProtoBuf.ProtoMember(3, Name = @"net_read_timeout")] - [global::System.ComponentModel.DefaultValue(0)] - public int NetReadTimeout - { - get { return __pbn__NetReadTimeout ?? 0; } - set { __pbn__NetReadTimeout = value; } - } - public bool ShouldSerializeNetReadTimeout() => __pbn__NetReadTimeout != null; - public void ResetNetReadTimeout() => __pbn__NetReadTimeout = null; - private int? __pbn__NetReadTimeout; - - [global::ProtoBuf.ProtoMember(4, Name = @"net_write_timeout")] - [global::System.ComponentModel.DefaultValue(0)] - public int NetWriteTimeout - { - get { return __pbn__NetWriteTimeout ?? 0; } - set { __pbn__NetWriteTimeout = value; } - } - public bool ShouldSerializeNetWriteTimeout() => __pbn__NetWriteTimeout != null; - public void ResetNetWriteTimeout() => __pbn__NetWriteTimeout = null; - private int? __pbn__NetWriteTimeout; - - [global::ProtoBuf.ProtoMember(5, Name = @"destination")] - [global::System.ComponentModel.DefaultValue("")] - public string Destination - { - get { return __pbn__Destination ?? ""; } - set { __pbn__Destination = value; } - } - public bool ShouldSerializeDestination() => __pbn__Destination != null; - public void ResetDestination() => __pbn__Destination = null; - private string __pbn__Destination; - - [global::ProtoBuf.ProtoMember(6, Name = @"client_id")] - [global::System.ComponentModel.DefaultValue("")] - public string ClientId - { - get { return __pbn__ClientId ?? ""; } - set { __pbn__ClientId = value; } - } - public bool ShouldSerializeClientId() => __pbn__ClientId != null; - public void ResetClientId() => __pbn__ClientId = null; - private string __pbn__ClientId; - - [global::ProtoBuf.ProtoMember(7, Name = @"filter")] - [global::System.ComponentModel.DefaultValue("")] - public string Filter - { - get { return __pbn__Filter ?? ""; } - set { __pbn__Filter = value; } - } - public bool ShouldSerializeFilter() => __pbn__Filter != null; - public void ResetFilter() => __pbn__Filter = null; - private string __pbn__Filter; - - [global::ProtoBuf.ProtoMember(8, Name = @"start_timestamp")] - public long StartTimestamp - { - get { return __pbn__StartTimestamp.GetValueOrDefault(); } - set { __pbn__StartTimestamp = value; } - } - public bool ShouldSerializeStartTimestamp() => __pbn__StartTimestamp != null; - public void ResetStartTimestamp() => __pbn__StartTimestamp = null; - private long? __pbn__StartTimestamp; + private object magicNumberPresent_; + /// Enum of possible cases for the "magic_number_present" oneof. + public enum MagicNumberPresentOneofCase { + None = 0, + MagicNumber = 1, + } + private MagicNumberPresentOneofCase magicNumberPresentCase_ = MagicNumberPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public MagicNumberPresentOneofCase MagicNumberPresentCase { + get { return magicNumberPresentCase_; } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearMagicNumberPresent() { + magicNumberPresentCase_ = MagicNumberPresentOneofCase.None; + magicNumberPresent_ = null; } - [global::ProtoBuf.ProtoContract()] - public partial class Ack : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + private object versionPresent_; + /// Enum of possible cases for the "version_present" oneof. + public enum VersionPresentOneofCase { + None = 0, + Version = 2, + } + private VersionPresentOneofCase versionPresentCase_ = VersionPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public VersionPresentOneofCase VersionPresentCase { + get { return versionPresentCase_; } + } - [global::ProtoBuf.ProtoMember(1, Name = @"error_code")] - [global::System.ComponentModel.DefaultValue(0)] - public int ErrorCode - { - get { return __pbn__ErrorCode ?? 0; } - set { __pbn__ErrorCode = value; } - } - public bool ShouldSerializeErrorCode() => __pbn__ErrorCode != null; - public void ResetErrorCode() => __pbn__ErrorCode = null; - private int? __pbn__ErrorCode; - - [global::ProtoBuf.ProtoMember(2, Name = @"error_message")] - [global::System.ComponentModel.DefaultValue("")] - public string ErrorMessage - { - get { return __pbn__ErrorMessage ?? ""; } - set { __pbn__ErrorMessage = value; } - } - public bool ShouldSerializeErrorMessage() => __pbn__ErrorMessage != null; - public void ResetErrorMessage() => __pbn__ErrorMessage = null; - private string __pbn__ErrorMessage; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearVersionPresent() { + versionPresentCase_ = VersionPresentOneofCase.None; + versionPresent_ = null; + } + private object compressionPresent_; + /// Enum of possible cases for the "compression_present" oneof. + public enum CompressionPresentOneofCase { + None = 0, + Compression = 4, + } + private CompressionPresentOneofCase compressionPresentCase_ = CompressionPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public CompressionPresentOneofCase CompressionPresentCase { + get { return compressionPresentCase_; } } - [global::ProtoBuf.ProtoContract()] - public partial class ClientAck : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearCompressionPresent() { + compressionPresentCase_ = CompressionPresentOneofCase.None; + compressionPresent_ = null; + } - [global::ProtoBuf.ProtoMember(1, Name = @"destination")] - [global::System.ComponentModel.DefaultValue("")] - public string Destination - { - get { return __pbn__Destination ?? ""; } - set { __pbn__Destination = value; } - } - public bool ShouldSerializeDestination() => __pbn__Destination != null; - public void ResetDestination() => __pbn__Destination = null; - private string __pbn__Destination; - - [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] - [global::System.ComponentModel.DefaultValue("")] - public string ClientId - { - get { return __pbn__ClientId ?? ""; } - set { __pbn__ClientId = value; } - } - public bool ShouldSerializeClientId() => __pbn__ClientId != null; - public void ResetClientId() => __pbn__ClientId = null; - private string __pbn__ClientId; - - [global::ProtoBuf.ProtoMember(3, Name = @"batch_id")] - public long BatchId - { - get { return __pbn__BatchId.GetValueOrDefault(); } - set { __pbn__BatchId = value; } - } - public bool ShouldSerializeBatchId() => __pbn__BatchId != null; - public void ResetBatchId() => __pbn__BatchId = null; - private long? __pbn__BatchId; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Packet); + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Packet other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (MagicNumber != other.MagicNumber) return false; + if (Version != other.Version) return false; + if (Type != other.Type) return false; + if (Compression != other.Compression) return false; + if (Body != other.Body) return false; + if (MagicNumberPresentCase != other.MagicNumberPresentCase) return false; + if (VersionPresentCase != other.VersionPresentCase) return false; + if (CompressionPresentCase != other.CompressionPresentCase) return false; + return Equals(_unknownFields, other._unknownFields); } - [global::ProtoBuf.ProtoContract()] - public partial class Sub : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (magicNumberPresentCase_ == MagicNumberPresentOneofCase.MagicNumber) hash ^= MagicNumber.GetHashCode(); + if (versionPresentCase_ == VersionPresentOneofCase.Version) hash ^= Version.GetHashCode(); + if (Type != 0) hash ^= Type.GetHashCode(); + if (compressionPresentCase_ == CompressionPresentOneofCase.Compression) hash ^= Compression.GetHashCode(); + if (Body.Length != 0) hash ^= Body.GetHashCode(); + hash ^= (int) magicNumberPresentCase_; + hash ^= (int) versionPresentCase_; + hash ^= (int) compressionPresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } - [global::ProtoBuf.ProtoMember(1, Name = @"destination")] - [global::System.ComponentModel.DefaultValue("")] - public string Destination - { - get { return __pbn__Destination ?? ""; } - set { __pbn__Destination = value; } - } - public bool ShouldSerializeDestination() => __pbn__Destination != null; - public void ResetDestination() => __pbn__Destination = null; - private string __pbn__Destination; - - [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] - [global::System.ComponentModel.DefaultValue("")] - public string ClientId - { - get { return __pbn__ClientId ?? ""; } - set { __pbn__ClientId = value; } - } - public bool ShouldSerializeClientId() => __pbn__ClientId != null; - public void ResetClientId() => __pbn__ClientId = null; - private string __pbn__ClientId; - - [global::ProtoBuf.ProtoMember(7, Name = @"filter")] - [global::System.ComponentModel.DefaultValue("")] - public string Filter - { - get { return __pbn__Filter ?? ""; } - set { __pbn__Filter = value; } - } - public bool ShouldSerializeFilter() => __pbn__Filter != null; - public void ResetFilter() => __pbn__Filter = null; - private string __pbn__Filter; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (magicNumberPresentCase_ == MagicNumberPresentOneofCase.MagicNumber) { + output.WriteRawTag(8); + output.WriteInt32(MagicNumber); + } + if (versionPresentCase_ == VersionPresentOneofCase.Version) { + output.WriteRawTag(16); + output.WriteInt32(Version); + } + if (Type != 0) { + output.WriteRawTag(24); + output.WriteEnum((int) Type); + } + if (compressionPresentCase_ == CompressionPresentOneofCase.Compression) { + output.WriteRawTag(32); + output.WriteEnum((int) Compression); + } + if (Body.Length != 0) { + output.WriteRawTag(42); + output.WriteBytes(Body); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } } - [global::ProtoBuf.ProtoContract()] - public partial class Unsub : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (magicNumberPresentCase_ == MagicNumberPresentOneofCase.MagicNumber) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(MagicNumber); + } + if (versionPresentCase_ == VersionPresentOneofCase.Version) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Version); + } + if (Type != 0) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Type); + } + if (compressionPresentCase_ == CompressionPresentOneofCase.Compression) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) Compression); + } + if (Body.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeBytesSize(Body); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } - [global::ProtoBuf.ProtoMember(1, Name = @"destination")] - [global::System.ComponentModel.DefaultValue("")] - public string Destination - { - get { return __pbn__Destination ?? ""; } - set { __pbn__Destination = value; } - } - public bool ShouldSerializeDestination() => __pbn__Destination != null; - public void ResetDestination() => __pbn__Destination = null; - private string __pbn__Destination; - - [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] - [global::System.ComponentModel.DefaultValue("")] - public string ClientId - { - get { return __pbn__ClientId ?? ""; } - set { __pbn__ClientId = value; } - } - public bool ShouldSerializeClientId() => __pbn__ClientId != null; - public void ResetClientId() => __pbn__ClientId = null; - private string __pbn__ClientId; - - [global::ProtoBuf.ProtoMember(7, Name = @"filter")] - [global::System.ComponentModel.DefaultValue("")] - public string Filter - { - get { return __pbn__Filter ?? ""; } - set { __pbn__Filter = value; } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Packet other) { + if (other == null) { + return; + } + if (other.Type != 0) { + Type = other.Type; + } + if (other.Body.Length != 0) { + Body = other.Body; + } + switch (other.MagicNumberPresentCase) { + case MagicNumberPresentOneofCase.MagicNumber: + MagicNumber = other.MagicNumber; + break; + } + + switch (other.VersionPresentCase) { + case VersionPresentOneofCase.Version: + Version = other.Version; + break; + } + + switch (other.CompressionPresentCase) { + case CompressionPresentOneofCase.Compression: + Compression = other.Compression; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + MagicNumber = input.ReadInt32(); + break; + } + case 16: { + Version = input.ReadInt32(); + break; + } + case 24: { + type_ = (global::Com.Alibaba.Otter.Canal.Protocol.PacketType) input.ReadEnum(); + break; + } + case 32: { + compressionPresent_ = input.ReadEnum(); + compressionPresentCase_ = CompressionPresentOneofCase.Compression; + break; + } + case 42: { + Body = input.ReadBytes(); + break; + } } - public bool ShouldSerializeFilter() => __pbn__Filter != null; - public void ResetFilter() => __pbn__Filter = null; - private string __pbn__Filter; + } + } + + } + + public sealed partial class HeartBeat : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new HeartBeat()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[1]; } } - [global::ProtoBuf.ProtoContract()] - public partial class Get : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } - [global::ProtoBuf.ProtoMember(1, Name = @"destination")] - [global::System.ComponentModel.DefaultValue("")] - public string Destination - { - get { return __pbn__Destination ?? ""; } - set { __pbn__Destination = value; } - } - public bool ShouldSerializeDestination() => __pbn__Destination != null; - public void ResetDestination() => __pbn__Destination = null; - private string __pbn__Destination; - - [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] - [global::System.ComponentModel.DefaultValue("")] - public string ClientId - { - get { return __pbn__ClientId ?? ""; } - set { __pbn__ClientId = value; } - } - public bool ShouldSerializeClientId() => __pbn__ClientId != null; - public void ResetClientId() => __pbn__ClientId = null; - private string __pbn__ClientId; - - [global::ProtoBuf.ProtoMember(3, Name = @"fetch_size")] - public int FetchSize - { - get { return __pbn__FetchSize.GetValueOrDefault(); } - set { __pbn__FetchSize = value; } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public HeartBeat() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public HeartBeat(HeartBeat other) : this() { + sendTimestamp_ = other.sendTimestamp_; + startTimestamp_ = other.startTimestamp_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public HeartBeat Clone() { + return new HeartBeat(this); + } + + /// Field number for the "send_timestamp" field. + public const int SendTimestampFieldNumber = 1; + private long sendTimestamp_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long SendTimestamp { + get { return sendTimestamp_; } + set { + sendTimestamp_ = value; + } + } + + /// Field number for the "start_timestamp" field. + public const int StartTimestampFieldNumber = 2; + private long startTimestamp_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long StartTimestamp { + get { return startTimestamp_; } + set { + startTimestamp_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as HeartBeat); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(HeartBeat other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (SendTimestamp != other.SendTimestamp) return false; + if (StartTimestamp != other.StartTimestamp) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (SendTimestamp != 0L) hash ^= SendTimestamp.GetHashCode(); + if (StartTimestamp != 0L) hash ^= StartTimestamp.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (SendTimestamp != 0L) { + output.WriteRawTag(8); + output.WriteInt64(SendTimestamp); + } + if (StartTimestamp != 0L) { + output.WriteRawTag(16); + output.WriteInt64(StartTimestamp); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (SendTimestamp != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(SendTimestamp); + } + if (StartTimestamp != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(StartTimestamp); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(HeartBeat other) { + if (other == null) { + return; + } + if (other.SendTimestamp != 0L) { + SendTimestamp = other.SendTimestamp; + } + if (other.StartTimestamp != 0L) { + StartTimestamp = other.StartTimestamp; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + SendTimestamp = input.ReadInt64(); + break; + } + case 16: { + StartTimestamp = input.ReadInt64(); + break; + } } - public bool ShouldSerializeFetchSize() => __pbn__FetchSize != null; - public void ResetFetchSize() => __pbn__FetchSize = null; - private int? __pbn__FetchSize; - - [global::ProtoBuf.ProtoMember(4, Name = @"timeout")] - [global::System.ComponentModel.DefaultValue(-1)] - public long Timeout - { - get { return __pbn__Timeout ?? -1; } - set { __pbn__Timeout = value; } + } + } + + } + + public sealed partial class Handshake : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Handshake()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[2]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Handshake() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Handshake(Handshake other) : this() { + seeds_ = other.seeds_; + supportedCompressions_ = other.supportedCompressions_; + switch (other.CommunicationEncodingPresentCase) { + case CommunicationEncodingPresentOneofCase.CommunicationEncoding: + CommunicationEncoding = other.CommunicationEncoding; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Handshake Clone() { + return new Handshake(this); + } + + /// Field number for the "communication_encoding" field. + public const int CommunicationEncodingFieldNumber = 1; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string CommunicationEncoding { + get { return communicationEncodingPresentCase_ == CommunicationEncodingPresentOneofCase.CommunicationEncoding ? (string) communicationEncodingPresent_ : ""; } + set { + communicationEncodingPresent_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + communicationEncodingPresentCase_ = CommunicationEncodingPresentOneofCase.CommunicationEncoding; + } + } + + /// Field number for the "seeds" field. + public const int SeedsFieldNumber = 2; + private pb::ByteString seeds_ = pb::ByteString.Empty; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pb::ByteString Seeds { + get { return seeds_; } + set { + seeds_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "supported_compressions" field. + public const int SupportedCompressionsFieldNumber = 3; + private global::Com.Alibaba.Otter.Canal.Protocol.Compression supportedCompressions_ = 0; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Com.Alibaba.Otter.Canal.Protocol.Compression SupportedCompressions { + get { return supportedCompressions_; } + set { + supportedCompressions_ = value; + } + } + + private object communicationEncodingPresent_; + /// Enum of possible cases for the "communication_encoding_present" oneof. + public enum CommunicationEncodingPresentOneofCase { + None = 0, + CommunicationEncoding = 1, + } + private CommunicationEncodingPresentOneofCase communicationEncodingPresentCase_ = CommunicationEncodingPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public CommunicationEncodingPresentOneofCase CommunicationEncodingPresentCase { + get { return communicationEncodingPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearCommunicationEncodingPresent() { + communicationEncodingPresentCase_ = CommunicationEncodingPresentOneofCase.None; + communicationEncodingPresent_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Handshake); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Handshake other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (CommunicationEncoding != other.CommunicationEncoding) return false; + if (Seeds != other.Seeds) return false; + if (SupportedCompressions != other.SupportedCompressions) return false; + if (CommunicationEncodingPresentCase != other.CommunicationEncodingPresentCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (communicationEncodingPresentCase_ == CommunicationEncodingPresentOneofCase.CommunicationEncoding) hash ^= CommunicationEncoding.GetHashCode(); + if (Seeds.Length != 0) hash ^= Seeds.GetHashCode(); + if (SupportedCompressions != 0) hash ^= SupportedCompressions.GetHashCode(); + hash ^= (int) communicationEncodingPresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (communicationEncodingPresentCase_ == CommunicationEncodingPresentOneofCase.CommunicationEncoding) { + output.WriteRawTag(10); + output.WriteString(CommunicationEncoding); + } + if (Seeds.Length != 0) { + output.WriteRawTag(18); + output.WriteBytes(Seeds); + } + if (SupportedCompressions != 0) { + output.WriteRawTag(24); + output.WriteEnum((int) SupportedCompressions); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (communicationEncodingPresentCase_ == CommunicationEncodingPresentOneofCase.CommunicationEncoding) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(CommunicationEncoding); + } + if (Seeds.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeBytesSize(Seeds); + } + if (SupportedCompressions != 0) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) SupportedCompressions); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Handshake other) { + if (other == null) { + return; + } + if (other.Seeds.Length != 0) { + Seeds = other.Seeds; + } + if (other.SupportedCompressions != 0) { + SupportedCompressions = other.SupportedCompressions; + } + switch (other.CommunicationEncodingPresentCase) { + case CommunicationEncodingPresentOneofCase.CommunicationEncoding: + CommunicationEncoding = other.CommunicationEncoding; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + CommunicationEncoding = input.ReadString(); + break; + } + case 18: { + Seeds = input.ReadBytes(); + break; + } + case 24: { + supportedCompressions_ = (global::Com.Alibaba.Otter.Canal.Protocol.Compression) input.ReadEnum(); + break; + } } - public bool ShouldSerializeTimeout() => __pbn__Timeout != null; - public void ResetTimeout() => __pbn__Timeout = null; - private long? __pbn__Timeout; - - [global::ProtoBuf.ProtoMember(5, Name = @"unit")] - [global::System.ComponentModel.DefaultValue(2)] - public int Unit - { - get { return __pbn__Unit ?? 2; } - set { __pbn__Unit = value; } + } + } + + } + + /// + /// client authentication + /// + public sealed partial class ClientAuth : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ClientAuth()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[3]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ClientAuth() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ClientAuth(ClientAuth other) : this() { + username_ = other.username_; + password_ = other.password_; + destination_ = other.destination_; + clientId_ = other.clientId_; + filter_ = other.filter_; + startTimestamp_ = other.startTimestamp_; + switch (other.NetReadTimeoutPresentCase) { + case NetReadTimeoutPresentOneofCase.NetReadTimeout: + NetReadTimeout = other.NetReadTimeout; + break; + } + + switch (other.NetWriteTimeoutPresentCase) { + case NetWriteTimeoutPresentOneofCase.NetWriteTimeout: + NetWriteTimeout = other.NetWriteTimeout; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ClientAuth Clone() { + return new ClientAuth(this); + } + + /// Field number for the "username" field. + public const int UsernameFieldNumber = 1; + private string username_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Username { + get { return username_; } + set { + username_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "password" field. + public const int PasswordFieldNumber = 2; + private pb::ByteString password_ = pb::ByteString.Empty; + /// + /// hashed password with seeds from Handshake message + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pb::ByteString Password { + get { return password_; } + set { + password_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "net_read_timeout" field. + public const int NetReadTimeoutFieldNumber = 3; + /// + /// in seconds + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int NetReadTimeout { + get { return netReadTimeoutPresentCase_ == NetReadTimeoutPresentOneofCase.NetReadTimeout ? (int) netReadTimeoutPresent_ : 0; } + set { + netReadTimeoutPresent_ = value; + netReadTimeoutPresentCase_ = NetReadTimeoutPresentOneofCase.NetReadTimeout; + } + } + + /// Field number for the "net_write_timeout" field. + public const int NetWriteTimeoutFieldNumber = 4; + /// + /// in seconds + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int NetWriteTimeout { + get { return netWriteTimeoutPresentCase_ == NetWriteTimeoutPresentOneofCase.NetWriteTimeout ? (int) netWriteTimeoutPresent_ : 0; } + set { + netWriteTimeoutPresent_ = value; + netWriteTimeoutPresentCase_ = NetWriteTimeoutPresentOneofCase.NetWriteTimeout; + } + } + + /// Field number for the "destination" field. + public const int DestinationFieldNumber = 5; + private string destination_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Destination { + get { return destination_; } + set { + destination_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "client_id" field. + public const int ClientIdFieldNumber = 6; + private string clientId_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ClientId { + get { return clientId_; } + set { + clientId_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "filter" field. + public const int FilterFieldNumber = 7; + private string filter_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Filter { + get { return filter_; } + set { + filter_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "start_timestamp" field. + public const int StartTimestampFieldNumber = 8; + private long startTimestamp_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long StartTimestamp { + get { return startTimestamp_; } + set { + startTimestamp_ = value; + } + } + + private object netReadTimeoutPresent_; + /// Enum of possible cases for the "net_read_timeout_present" oneof. + public enum NetReadTimeoutPresentOneofCase { + None = 0, + NetReadTimeout = 3, + } + private NetReadTimeoutPresentOneofCase netReadTimeoutPresentCase_ = NetReadTimeoutPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public NetReadTimeoutPresentOneofCase NetReadTimeoutPresentCase { + get { return netReadTimeoutPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearNetReadTimeoutPresent() { + netReadTimeoutPresentCase_ = NetReadTimeoutPresentOneofCase.None; + netReadTimeoutPresent_ = null; + } + + private object netWriteTimeoutPresent_; + /// Enum of possible cases for the "net_write_timeout_present" oneof. + public enum NetWriteTimeoutPresentOneofCase { + None = 0, + NetWriteTimeout = 4, + } + private NetWriteTimeoutPresentOneofCase netWriteTimeoutPresentCase_ = NetWriteTimeoutPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public NetWriteTimeoutPresentOneofCase NetWriteTimeoutPresentCase { + get { return netWriteTimeoutPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearNetWriteTimeoutPresent() { + netWriteTimeoutPresentCase_ = NetWriteTimeoutPresentOneofCase.None; + netWriteTimeoutPresent_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as ClientAuth); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(ClientAuth other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Username != other.Username) return false; + if (Password != other.Password) return false; + if (NetReadTimeout != other.NetReadTimeout) return false; + if (NetWriteTimeout != other.NetWriteTimeout) return false; + if (Destination != other.Destination) return false; + if (ClientId != other.ClientId) return false; + if (Filter != other.Filter) return false; + if (StartTimestamp != other.StartTimestamp) return false; + if (NetReadTimeoutPresentCase != other.NetReadTimeoutPresentCase) return false; + if (NetWriteTimeoutPresentCase != other.NetWriteTimeoutPresentCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Username.Length != 0) hash ^= Username.GetHashCode(); + if (Password.Length != 0) hash ^= Password.GetHashCode(); + if (netReadTimeoutPresentCase_ == NetReadTimeoutPresentOneofCase.NetReadTimeout) hash ^= NetReadTimeout.GetHashCode(); + if (netWriteTimeoutPresentCase_ == NetWriteTimeoutPresentOneofCase.NetWriteTimeout) hash ^= NetWriteTimeout.GetHashCode(); + if (Destination.Length != 0) hash ^= Destination.GetHashCode(); + if (ClientId.Length != 0) hash ^= ClientId.GetHashCode(); + if (Filter.Length != 0) hash ^= Filter.GetHashCode(); + if (StartTimestamp != 0L) hash ^= StartTimestamp.GetHashCode(); + hash ^= (int) netReadTimeoutPresentCase_; + hash ^= (int) netWriteTimeoutPresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Username.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Username); + } + if (Password.Length != 0) { + output.WriteRawTag(18); + output.WriteBytes(Password); + } + if (netReadTimeoutPresentCase_ == NetReadTimeoutPresentOneofCase.NetReadTimeout) { + output.WriteRawTag(24); + output.WriteInt32(NetReadTimeout); + } + if (netWriteTimeoutPresentCase_ == NetWriteTimeoutPresentOneofCase.NetWriteTimeout) { + output.WriteRawTag(32); + output.WriteInt32(NetWriteTimeout); + } + if (Destination.Length != 0) { + output.WriteRawTag(42); + output.WriteString(Destination); + } + if (ClientId.Length != 0) { + output.WriteRawTag(50); + output.WriteString(ClientId); + } + if (Filter.Length != 0) { + output.WriteRawTag(58); + output.WriteString(Filter); + } + if (StartTimestamp != 0L) { + output.WriteRawTag(64); + output.WriteInt64(StartTimestamp); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Username.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Username); + } + if (Password.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeBytesSize(Password); + } + if (netReadTimeoutPresentCase_ == NetReadTimeoutPresentOneofCase.NetReadTimeout) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(NetReadTimeout); + } + if (netWriteTimeoutPresentCase_ == NetWriteTimeoutPresentOneofCase.NetWriteTimeout) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(NetWriteTimeout); + } + if (Destination.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Destination); + } + if (ClientId.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ClientId); + } + if (Filter.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Filter); + } + if (StartTimestamp != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(StartTimestamp); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ClientAuth other) { + if (other == null) { + return; + } + if (other.Username.Length != 0) { + Username = other.Username; + } + if (other.Password.Length != 0) { + Password = other.Password; + } + if (other.Destination.Length != 0) { + Destination = other.Destination; + } + if (other.ClientId.Length != 0) { + ClientId = other.ClientId; + } + if (other.Filter.Length != 0) { + Filter = other.Filter; + } + if (other.StartTimestamp != 0L) { + StartTimestamp = other.StartTimestamp; + } + switch (other.NetReadTimeoutPresentCase) { + case NetReadTimeoutPresentOneofCase.NetReadTimeout: + NetReadTimeout = other.NetReadTimeout; + break; + } + + switch (other.NetWriteTimeoutPresentCase) { + case NetWriteTimeoutPresentOneofCase.NetWriteTimeout: + NetWriteTimeout = other.NetWriteTimeout; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Username = input.ReadString(); + break; + } + case 18: { + Password = input.ReadBytes(); + break; + } + case 24: { + NetReadTimeout = input.ReadInt32(); + break; + } + case 32: { + NetWriteTimeout = input.ReadInt32(); + break; + } + case 42: { + Destination = input.ReadString(); + break; + } + case 50: { + ClientId = input.ReadString(); + break; + } + case 58: { + Filter = input.ReadString(); + break; + } + case 64: { + StartTimestamp = input.ReadInt64(); + break; + } } - public bool ShouldSerializeUnit() => __pbn__Unit != null; - public void ResetUnit() => __pbn__Unit = null; - private int? __pbn__Unit; - - [global::ProtoBuf.ProtoMember(6, Name = @"auto_ack")] - [global::System.ComponentModel.DefaultValue(false)] - public bool AutoAck - { - get { return __pbn__AutoAck ?? false; } - set { __pbn__AutoAck = value; } + } + } + + } + + public sealed partial class Ack : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Ack()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[4]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Ack() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Ack(Ack other) : this() { + errorMessage_ = other.errorMessage_; + switch (other.ErrorCodePresentCase) { + case ErrorCodePresentOneofCase.ErrorCode: + ErrorCode = other.ErrorCode; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Ack Clone() { + return new Ack(this); + } + + /// Field number for the "error_code" field. + public const int ErrorCodeFieldNumber = 1; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int ErrorCode { + get { return errorCodePresentCase_ == ErrorCodePresentOneofCase.ErrorCode ? (int) errorCodePresent_ : 0; } + set { + errorCodePresent_ = value; + errorCodePresentCase_ = ErrorCodePresentOneofCase.ErrorCode; + } + } + + /// Field number for the "error_message" field. + public const int ErrorMessageFieldNumber = 2; + private string errorMessage_ = ""; + /// + /// if something like compression is not supported, erorr_message will tell about it. + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ErrorMessage { + get { return errorMessage_; } + set { + errorMessage_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + private object errorCodePresent_; + /// Enum of possible cases for the "error_code_present" oneof. + public enum ErrorCodePresentOneofCase { + None = 0, + ErrorCode = 1, + } + private ErrorCodePresentOneofCase errorCodePresentCase_ = ErrorCodePresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ErrorCodePresentOneofCase ErrorCodePresentCase { + get { return errorCodePresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearErrorCodePresent() { + errorCodePresentCase_ = ErrorCodePresentOneofCase.None; + errorCodePresent_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Ack); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Ack other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (ErrorCode != other.ErrorCode) return false; + if (ErrorMessage != other.ErrorMessage) return false; + if (ErrorCodePresentCase != other.ErrorCodePresentCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (errorCodePresentCase_ == ErrorCodePresentOneofCase.ErrorCode) hash ^= ErrorCode.GetHashCode(); + if (ErrorMessage.Length != 0) hash ^= ErrorMessage.GetHashCode(); + hash ^= (int) errorCodePresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (errorCodePresentCase_ == ErrorCodePresentOneofCase.ErrorCode) { + output.WriteRawTag(8); + output.WriteInt32(ErrorCode); + } + if (ErrorMessage.Length != 0) { + output.WriteRawTag(18); + output.WriteString(ErrorMessage); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (errorCodePresentCase_ == ErrorCodePresentOneofCase.ErrorCode) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(ErrorCode); + } + if (ErrorMessage.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ErrorMessage); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Ack other) { + if (other == null) { + return; + } + if (other.ErrorMessage.Length != 0) { + ErrorMessage = other.ErrorMessage; + } + switch (other.ErrorCodePresentCase) { + case ErrorCodePresentOneofCase.ErrorCode: + ErrorCode = other.ErrorCode; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + ErrorCode = input.ReadInt32(); + break; + } + case 18: { + ErrorMessage = input.ReadString(); + break; + } } - public bool ShouldSerializeAutoAck() => __pbn__AutoAck != null; - public void ResetAutoAck() => __pbn__AutoAck = null; - private bool? __pbn__AutoAck; + } + } + + } + + public sealed partial class ClientAck : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ClientAck()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[5]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ClientAck() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ClientAck(ClientAck other) : this() { + destination_ = other.destination_; + clientId_ = other.clientId_; + batchId_ = other.batchId_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ClientAck Clone() { + return new ClientAck(this); + } + + /// Field number for the "destination" field. + public const int DestinationFieldNumber = 1; + private string destination_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Destination { + get { return destination_; } + set { + destination_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "client_id" field. + public const int ClientIdFieldNumber = 2; + private string clientId_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ClientId { + get { return clientId_; } + set { + clientId_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "batch_id" field. + public const int BatchIdFieldNumber = 3; + private long batchId_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long BatchId { + get { return batchId_; } + set { + batchId_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as ClientAck); + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(ClientAck other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Destination != other.Destination) return false; + if (ClientId != other.ClientId) return false; + if (BatchId != other.BatchId) return false; + return Equals(_unknownFields, other._unknownFields); } - [global::ProtoBuf.ProtoContract()] - public partial class Messages : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Destination.Length != 0) hash ^= Destination.GetHashCode(); + if (ClientId.Length != 0) hash ^= ClientId.GetHashCode(); + if (BatchId != 0L) hash ^= BatchId.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Destination.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Destination); + } + if (ClientId.Length != 0) { + output.WriteRawTag(18); + output.WriteString(ClientId); + } + if (BatchId != 0L) { + output.WriteRawTag(24); + output.WriteInt64(BatchId); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Destination.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Destination); + } + if (ClientId.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ClientId); + } + if (BatchId != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(BatchId); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } - [global::ProtoBuf.ProtoMember(1, Name = @"batch_id")] - public long BatchId - { - get { return __pbn__BatchId.GetValueOrDefault(); } - set { __pbn__BatchId = value; } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ClientAck other) { + if (other == null) { + return; + } + if (other.Destination.Length != 0) { + Destination = other.Destination; + } + if (other.ClientId.Length != 0) { + ClientId = other.ClientId; + } + if (other.BatchId != 0L) { + BatchId = other.BatchId; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Destination = input.ReadString(); + break; + } + case 18: { + ClientId = input.ReadString(); + break; + } + case 24: { + BatchId = input.ReadInt64(); + break; + } } - public bool ShouldSerializeBatchId() => __pbn__BatchId != null; - public void ResetBatchId() => __pbn__BatchId = null; - private long? __pbn__BatchId; + } + } + + } + + /// + /// subscription + /// + public sealed partial class Sub : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Sub()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[6]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Sub() { + OnConstruction(); + } + + partial void OnConstruction(); - [global::ProtoBuf.ProtoMember(2)] - public global::System.Collections.Generic.List messages { get; } = new global::System.Collections.Generic.List(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Sub(Sub other) : this() { + destination_ = other.destination_; + clientId_ = other.clientId_; + filter_ = other.filter_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Sub Clone() { + return new Sub(this); + } + /// Field number for the "destination" field. + public const int DestinationFieldNumber = 1; + private string destination_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Destination { + get { return destination_; } + set { + destination_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } } - [global::ProtoBuf.ProtoContract()] - public partial class Dump : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + /// Field number for the "client_id" field. + public const int ClientIdFieldNumber = 2; + private string clientId_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ClientId { + get { return clientId_; } + set { + clientId_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } - [global::ProtoBuf.ProtoMember(1, Name = @"journal")] - [global::System.ComponentModel.DefaultValue("")] - public string Journal - { - get { return __pbn__Journal ?? ""; } - set { __pbn__Journal = value; } + /// Field number for the "filter" field. + public const int FilterFieldNumber = 7; + private string filter_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Filter { + get { return filter_; } + set { + filter_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Sub); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Sub other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Destination != other.Destination) return false; + if (ClientId != other.ClientId) return false; + if (Filter != other.Filter) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Destination.Length != 0) hash ^= Destination.GetHashCode(); + if (ClientId.Length != 0) hash ^= ClientId.GetHashCode(); + if (Filter.Length != 0) hash ^= Filter.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Destination.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Destination); + } + if (ClientId.Length != 0) { + output.WriteRawTag(18); + output.WriteString(ClientId); + } + if (Filter.Length != 0) { + output.WriteRawTag(58); + output.WriteString(Filter); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Destination.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Destination); + } + if (ClientId.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ClientId); + } + if (Filter.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Filter); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Sub other) { + if (other == null) { + return; + } + if (other.Destination.Length != 0) { + Destination = other.Destination; + } + if (other.ClientId.Length != 0) { + ClientId = other.ClientId; + } + if (other.Filter.Length != 0) { + Filter = other.Filter; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Destination = input.ReadString(); + break; + } + case 18: { + ClientId = input.ReadString(); + break; + } + case 58: { + Filter = input.ReadString(); + break; + } } - public bool ShouldSerializeJournal() => __pbn__Journal != null; - public void ResetJournal() => __pbn__Journal = null; - private string __pbn__Journal; - - [global::ProtoBuf.ProtoMember(2, Name = @"position")] - public long Position - { - get { return __pbn__Position.GetValueOrDefault(); } - set { __pbn__Position = value; } + } + } + + } + + /// + /// Unsubscription + /// + public sealed partial class Unsub : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Unsub()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[7]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Unsub() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Unsub(Unsub other) : this() { + destination_ = other.destination_; + clientId_ = other.clientId_; + filter_ = other.filter_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Unsub Clone() { + return new Unsub(this); + } + + /// Field number for the "destination" field. + public const int DestinationFieldNumber = 1; + private string destination_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Destination { + get { return destination_; } + set { + destination_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "client_id" field. + public const int ClientIdFieldNumber = 2; + private string clientId_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ClientId { + get { return clientId_; } + set { + clientId_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "filter" field. + public const int FilterFieldNumber = 7; + private string filter_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Filter { + get { return filter_; } + set { + filter_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Unsub); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Unsub other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Destination != other.Destination) return false; + if (ClientId != other.ClientId) return false; + if (Filter != other.Filter) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Destination.Length != 0) hash ^= Destination.GetHashCode(); + if (ClientId.Length != 0) hash ^= ClientId.GetHashCode(); + if (Filter.Length != 0) hash ^= Filter.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Destination.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Destination); + } + if (ClientId.Length != 0) { + output.WriteRawTag(18); + output.WriteString(ClientId); + } + if (Filter.Length != 0) { + output.WriteRawTag(58); + output.WriteString(Filter); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Destination.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Destination); + } + if (ClientId.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ClientId); + } + if (Filter.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Filter); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Unsub other) { + if (other == null) { + return; + } + if (other.Destination.Length != 0) { + Destination = other.Destination; + } + if (other.ClientId.Length != 0) { + ClientId = other.ClientId; + } + if (other.Filter.Length != 0) { + Filter = other.Filter; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Destination = input.ReadString(); + break; + } + case 18: { + ClientId = input.ReadString(); + break; + } + case 58: { + Filter = input.ReadString(); + break; + } } - public bool ShouldSerializePosition() => __pbn__Position != null; - public void ResetPosition() => __pbn__Position = null; - private long? __pbn__Position; - - [global::ProtoBuf.ProtoMember(3, Name = @"timestamp")] - [global::System.ComponentModel.DefaultValue(0)] - public long Timestamp - { - get { return __pbn__Timestamp ?? 0; } - set { __pbn__Timestamp = value; } + } + } + + } + + /// + /// PullRequest + /// + public sealed partial class Get : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Get()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[8]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Get() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Get(Get other) : this() { + destination_ = other.destination_; + clientId_ = other.clientId_; + fetchSize_ = other.fetchSize_; + switch (other.TimeoutPresentCase) { + case TimeoutPresentOneofCase.Timeout: + Timeout = other.Timeout; + break; + } + + switch (other.UnitPresentCase) { + case UnitPresentOneofCase.Unit: + Unit = other.Unit; + break; + } + + switch (other.AutoAckPresentCase) { + case AutoAckPresentOneofCase.AutoAck: + AutoAck = other.AutoAck; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Get Clone() { + return new Get(this); + } + + /// Field number for the "destination" field. + public const int DestinationFieldNumber = 1; + private string destination_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Destination { + get { return destination_; } + set { + destination_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "client_id" field. + public const int ClientIdFieldNumber = 2; + private string clientId_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ClientId { + get { return clientId_; } + set { + clientId_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "fetch_size" field. + public const int FetchSizeFieldNumber = 3; + private int fetchSize_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int FetchSize { + get { return fetchSize_; } + set { + fetchSize_ = value; + } + } + + /// Field number for the "timeout" field. + public const int TimeoutFieldNumber = 4; + /// + /// 默认-1时代表不控制 + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Timeout { + get { return timeoutPresentCase_ == TimeoutPresentOneofCase.Timeout ? (long) timeoutPresent_ : 0L; } + set { + timeoutPresent_ = value; + timeoutPresentCase_ = TimeoutPresentOneofCase.Timeout; + } + } + + /// Field number for the "unit" field. + public const int UnitFieldNumber = 5; + /// + /// 数字类型,0:纳秒,1:毫秒,2:微秒,3:秒,4:分钟,5:小时,6:天 + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Unit { + get { return unitPresentCase_ == UnitPresentOneofCase.Unit ? (int) unitPresent_ : 0; } + set { + unitPresent_ = value; + unitPresentCase_ = UnitPresentOneofCase.Unit; + } + } + + /// Field number for the "auto_ack" field. + public const int AutoAckFieldNumber = 6; + /// + /// 是否自动ack + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool AutoAck { + get { return autoAckPresentCase_ == AutoAckPresentOneofCase.AutoAck ? (bool) autoAckPresent_ : false; } + set { + autoAckPresent_ = value; + autoAckPresentCase_ = AutoAckPresentOneofCase.AutoAck; + } + } + + private object timeoutPresent_; + /// Enum of possible cases for the "timeout_present" oneof. + public enum TimeoutPresentOneofCase { + None = 0, + Timeout = 4, + } + private TimeoutPresentOneofCase timeoutPresentCase_ = TimeoutPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public TimeoutPresentOneofCase TimeoutPresentCase { + get { return timeoutPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearTimeoutPresent() { + timeoutPresentCase_ = TimeoutPresentOneofCase.None; + timeoutPresent_ = null; + } + + private object unitPresent_; + /// Enum of possible cases for the "unit_present" oneof. + public enum UnitPresentOneofCase { + None = 0, + Unit = 5, + } + private UnitPresentOneofCase unitPresentCase_ = UnitPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public UnitPresentOneofCase UnitPresentCase { + get { return unitPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearUnitPresent() { + unitPresentCase_ = UnitPresentOneofCase.None; + unitPresent_ = null; + } + + private object autoAckPresent_; + /// Enum of possible cases for the "auto_ack_present" oneof. + public enum AutoAckPresentOneofCase { + None = 0, + AutoAck = 6, + } + private AutoAckPresentOneofCase autoAckPresentCase_ = AutoAckPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public AutoAckPresentOneofCase AutoAckPresentCase { + get { return autoAckPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearAutoAckPresent() { + autoAckPresentCase_ = AutoAckPresentOneofCase.None; + autoAckPresent_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Get); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Get other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Destination != other.Destination) return false; + if (ClientId != other.ClientId) return false; + if (FetchSize != other.FetchSize) return false; + if (Timeout != other.Timeout) return false; + if (Unit != other.Unit) return false; + if (AutoAck != other.AutoAck) return false; + if (TimeoutPresentCase != other.TimeoutPresentCase) return false; + if (UnitPresentCase != other.UnitPresentCase) return false; + if (AutoAckPresentCase != other.AutoAckPresentCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Destination.Length != 0) hash ^= Destination.GetHashCode(); + if (ClientId.Length != 0) hash ^= ClientId.GetHashCode(); + if (FetchSize != 0) hash ^= FetchSize.GetHashCode(); + if (timeoutPresentCase_ == TimeoutPresentOneofCase.Timeout) hash ^= Timeout.GetHashCode(); + if (unitPresentCase_ == UnitPresentOneofCase.Unit) hash ^= Unit.GetHashCode(); + if (autoAckPresentCase_ == AutoAckPresentOneofCase.AutoAck) hash ^= AutoAck.GetHashCode(); + hash ^= (int) timeoutPresentCase_; + hash ^= (int) unitPresentCase_; + hash ^= (int) autoAckPresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Destination.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Destination); + } + if (ClientId.Length != 0) { + output.WriteRawTag(18); + output.WriteString(ClientId); + } + if (FetchSize != 0) { + output.WriteRawTag(24); + output.WriteInt32(FetchSize); + } + if (timeoutPresentCase_ == TimeoutPresentOneofCase.Timeout) { + output.WriteRawTag(32); + output.WriteInt64(Timeout); + } + if (unitPresentCase_ == UnitPresentOneofCase.Unit) { + output.WriteRawTag(40); + output.WriteInt32(Unit); + } + if (autoAckPresentCase_ == AutoAckPresentOneofCase.AutoAck) { + output.WriteRawTag(48); + output.WriteBool(AutoAck); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Destination.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Destination); + } + if (ClientId.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ClientId); + } + if (FetchSize != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(FetchSize); + } + if (timeoutPresentCase_ == TimeoutPresentOneofCase.Timeout) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Timeout); + } + if (unitPresentCase_ == UnitPresentOneofCase.Unit) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Unit); + } + if (autoAckPresentCase_ == AutoAckPresentOneofCase.AutoAck) { + size += 1 + 1; + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Get other) { + if (other == null) { + return; + } + if (other.Destination.Length != 0) { + Destination = other.Destination; + } + if (other.ClientId.Length != 0) { + ClientId = other.ClientId; + } + if (other.FetchSize != 0) { + FetchSize = other.FetchSize; + } + switch (other.TimeoutPresentCase) { + case TimeoutPresentOneofCase.Timeout: + Timeout = other.Timeout; + break; + } + + switch (other.UnitPresentCase) { + case UnitPresentOneofCase.Unit: + Unit = other.Unit; + break; + } + + switch (other.AutoAckPresentCase) { + case AutoAckPresentOneofCase.AutoAck: + AutoAck = other.AutoAck; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Destination = input.ReadString(); + break; + } + case 18: { + ClientId = input.ReadString(); + break; + } + case 24: { + FetchSize = input.ReadInt32(); + break; + } + case 32: { + Timeout = input.ReadInt64(); + break; + } + case 40: { + Unit = input.ReadInt32(); + break; + } + case 48: { + AutoAck = input.ReadBool(); + break; + } } - public bool ShouldSerializeTimestamp() => __pbn__Timestamp != null; - public void ResetTimestamp() => __pbn__Timestamp = null; - private long? __pbn__Timestamp; + } + } + + } + + /// + /// + public sealed partial class Messages : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Messages()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[9]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Messages() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Messages(Messages other) : this() { + batchId_ = other.batchId_; + messages_ = other.messages_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Messages Clone() { + return new Messages(this); } - [global::ProtoBuf.ProtoContract()] - public partial class ClientRollback : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + /// Field number for the "batch_id" field. + public const int BatchIdFieldNumber = 1; + private long batchId_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long BatchId { + get { return batchId_; } + set { + batchId_ = value; + } + } + + /// Field number for the "messages" field. + public const int Messages_FieldNumber = 2; + private static readonly pb::FieldCodec _repeated_messages_codec + = pb::FieldCodec.ForBytes(18); + private readonly pbc::RepeatedField messages_ = new pbc::RepeatedField(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Messages_ { + get { return messages_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Messages); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Messages other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (BatchId != other.BatchId) return false; + if(!messages_.Equals(other.messages_)) return false; + return Equals(_unknownFields, other._unknownFields); + } - [global::ProtoBuf.ProtoMember(1, Name = @"destination")] - [global::System.ComponentModel.DefaultValue("")] - public string Destination - { - get { return __pbn__Destination ?? ""; } - set { __pbn__Destination = value; } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (BatchId != 0L) hash ^= BatchId.GetHashCode(); + hash ^= messages_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (BatchId != 0L) { + output.WriteRawTag(8); + output.WriteInt64(BatchId); + } + messages_.WriteTo(output, _repeated_messages_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (BatchId != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(BatchId); + } + size += messages_.CalculateSize(_repeated_messages_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Messages other) { + if (other == null) { + return; + } + if (other.BatchId != 0L) { + BatchId = other.BatchId; + } + messages_.Add(other.messages_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + BatchId = input.ReadInt64(); + break; + } + case 18: { + messages_.AddEntriesFrom(input, _repeated_messages_codec); + break; + } } - public bool ShouldSerializeDestination() => __pbn__Destination != null; - public void ResetDestination() => __pbn__Destination = null; - private string __pbn__Destination; - - [global::ProtoBuf.ProtoMember(2, Name = @"client_id")] - [global::System.ComponentModel.DefaultValue("")] - public string ClientId - { - get { return __pbn__ClientId ?? ""; } - set { __pbn__ClientId = value; } + } + } + + } + + /// + /// TBD when new packets are required + /// + public sealed partial class Dump : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Dump()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[10]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Dump() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Dump(Dump other) : this() { + journal_ = other.journal_; + position_ = other.position_; + switch (other.TimestampPresentCase) { + case TimestampPresentOneofCase.Timestamp: + Timestamp = other.Timestamp; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Dump Clone() { + return new Dump(this); + } + + /// Field number for the "journal" field. + public const int JournalFieldNumber = 1; + private string journal_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Journal { + get { return journal_; } + set { + journal_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "position" field. + public const int PositionFieldNumber = 2; + private long position_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Position { + get { return position_; } + set { + position_ = value; + } + } + + /// Field number for the "timestamp" field. + public const int TimestampFieldNumber = 3; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long Timestamp { + get { return timestampPresentCase_ == TimestampPresentOneofCase.Timestamp ? (long) timestampPresent_ : 0L; } + set { + timestampPresent_ = value; + timestampPresentCase_ = TimestampPresentOneofCase.Timestamp; + } + } + + private object timestampPresent_; + /// Enum of possible cases for the "timestamp_present" oneof. + public enum TimestampPresentOneofCase { + None = 0, + Timestamp = 3, + } + private TimestampPresentOneofCase timestampPresentCase_ = TimestampPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public TimestampPresentOneofCase TimestampPresentCase { + get { return timestampPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearTimestampPresent() { + timestampPresentCase_ = TimestampPresentOneofCase.None; + timestampPresent_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Dump); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Dump other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Journal != other.Journal) return false; + if (Position != other.Position) return false; + if (Timestamp != other.Timestamp) return false; + if (TimestampPresentCase != other.TimestampPresentCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Journal.Length != 0) hash ^= Journal.GetHashCode(); + if (Position != 0L) hash ^= Position.GetHashCode(); + if (timestampPresentCase_ == TimestampPresentOneofCase.Timestamp) hash ^= Timestamp.GetHashCode(); + hash ^= (int) timestampPresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Journal.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Journal); + } + if (Position != 0L) { + output.WriteRawTag(16); + output.WriteInt64(Position); + } + if (timestampPresentCase_ == TimestampPresentOneofCase.Timestamp) { + output.WriteRawTag(24); + output.WriteInt64(Timestamp); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Journal.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Journal); + } + if (Position != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Position); + } + if (timestampPresentCase_ == TimestampPresentOneofCase.Timestamp) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(Timestamp); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Dump other) { + if (other == null) { + return; + } + if (other.Journal.Length != 0) { + Journal = other.Journal; + } + if (other.Position != 0L) { + Position = other.Position; + } + switch (other.TimestampPresentCase) { + case TimestampPresentOneofCase.Timestamp: + Timestamp = other.Timestamp; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Journal = input.ReadString(); + break; + } + case 16: { + Position = input.ReadInt64(); + break; + } + case 24: { + Timestamp = input.ReadInt64(); + break; + } } - public bool ShouldSerializeClientId() => __pbn__ClientId != null; - public void ResetClientId() => __pbn__ClientId = null; - private string __pbn__ClientId; - - [global::ProtoBuf.ProtoMember(3, Name = @"batch_id")] - public long BatchId - { - get { return __pbn__BatchId.GetValueOrDefault(); } - set { __pbn__BatchId = value; } + } + } + + } + + public sealed partial class ClientRollback : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new ClientRollback()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.CanalProtocolReflection.Descriptor.MessageTypes[11]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ClientRollback() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ClientRollback(ClientRollback other) : this() { + destination_ = other.destination_; + clientId_ = other.clientId_; + batchId_ = other.batchId_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public ClientRollback Clone() { + return new ClientRollback(this); + } + + /// Field number for the "destination" field. + public const int DestinationFieldNumber = 1; + private string destination_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Destination { + get { return destination_; } + set { + destination_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "client_id" field. + public const int ClientIdFieldNumber = 2; + private string clientId_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ClientId { + get { return clientId_; } + set { + clientId_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "batch_id" field. + public const int BatchIdFieldNumber = 3; + private long batchId_; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long BatchId { + get { return batchId_; } + set { + batchId_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as ClientRollback); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(ClientRollback other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Destination != other.Destination) return false; + if (ClientId != other.ClientId) return false; + if (BatchId != other.BatchId) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Destination.Length != 0) hash ^= Destination.GetHashCode(); + if (ClientId.Length != 0) hash ^= ClientId.GetHashCode(); + if (BatchId != 0L) hash ^= BatchId.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Destination.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Destination); + } + if (ClientId.Length != 0) { + output.WriteRawTag(18); + output.WriteString(ClientId); + } + if (BatchId != 0L) { + output.WriteRawTag(24); + output.WriteInt64(BatchId); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Destination.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Destination); + } + if (ClientId.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ClientId); + } + if (BatchId != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(BatchId); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(ClientRollback other) { + if (other == null) { + return; + } + if (other.Destination.Length != 0) { + Destination = other.Destination; + } + if (other.ClientId.Length != 0) { + ClientId = other.ClientId; + } + if (other.BatchId != 0L) { + BatchId = other.BatchId; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Destination = input.ReadString(); + break; + } + case 18: { + ClientId = input.ReadString(); + break; + } + case 24: { + BatchId = input.ReadInt64(); + break; + } } - public bool ShouldSerializeBatchId() => __pbn__BatchId != null; - public void ResetBatchId() => __pbn__BatchId = null; - private long? __pbn__BatchId; - - } - - [global::ProtoBuf.ProtoContract()] - public enum Compression - { - [global::ProtoBuf.ProtoEnum(Name = @"NONE")] - None = 1, - [global::ProtoBuf.ProtoEnum(Name = @"ZLIB")] - Zlib = 2, - [global::ProtoBuf.ProtoEnum(Name = @"GZIP")] - Gzip = 3, - [global::ProtoBuf.ProtoEnum(Name = @"LZF")] - Lzf = 4, - } - - [global::ProtoBuf.ProtoContract()] - public enum PacketType - { - [global::ProtoBuf.ProtoEnum(Name = @"HANDSHAKE")] - Handshake = 1, - [global::ProtoBuf.ProtoEnum(Name = @"CLIENTAUTHENTICATION")] - Clientauthentication = 2, - [global::ProtoBuf.ProtoEnum(Name = @"ACK")] - Ack = 3, - [global::ProtoBuf.ProtoEnum(Name = @"SUBSCRIPTION")] - Subscription = 4, - [global::ProtoBuf.ProtoEnum(Name = @"UNSUBSCRIPTION")] - Unsubscription = 5, - [global::ProtoBuf.ProtoEnum(Name = @"GET")] - Get = 6, - [global::ProtoBuf.ProtoEnum(Name = @"MESSAGES")] - Messages = 7, - [global::ProtoBuf.ProtoEnum(Name = @"CLIENTACK")] - Clientack = 8, - [global::ProtoBuf.ProtoEnum(Name = @"SHUTDOWN")] - Shutdown = 9, - [global::ProtoBuf.ProtoEnum(Name = @"DUMP")] - Dump = 10, - [global::ProtoBuf.ProtoEnum(Name = @"HEARTBEAT")] - Heartbeat = 11, - [global::ProtoBuf.ProtoEnum(Name = @"CLIENTROLLBACK")] - Clientrollback = 12, + } } + } + + #endregion + } -#pragma warning restore CS0612, CS1591, CS3021, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 +#endregion Designer generated code diff --git a/src/Canal.Csharp.Protocol/CanalProtocol.proto b/src/Canal.Csharp.Protocol/CanalProtocol.proto index 9f88fe9..660b804 100644 --- a/src/Canal.Csharp.Protocol/CanalProtocol.proto +++ b/src/Canal.Csharp.Protocol/CanalProtocol.proto @@ -1,4 +1,4 @@ -syntax = "proto2"; +syntax = "proto3"; package com.alibaba.otter.canal.protocol; option java_package = "com.alibaba.otter.canal.protocol"; @@ -6,6 +6,7 @@ option java_outer_classname = "CanalPacket"; option optimize_for = SPEED; enum Compression { + COMPRESSIONCOMPATIBLEPROTO2 = 0; NONE = 1; ZLIB = 2; GZIP = 3; @@ -13,6 +14,8 @@ enum Compression { } enum PacketType { + //compatible + PACKAGETYPECOMPATIBLEPROTO2 = 0; HANDSHAKE = 1; CLIENTAUTHENTICATION = 2; ACK = 3; @@ -30,86 +33,122 @@ enum PacketType { } message Packet { - optional int32 magic_number = 1 [default = 17]; - optional int32 version = 2 [default = 1]; - optional PacketType type = 3; - optional Compression compression = 4 [default = NONE]; - optional bytes body = 5; + //[default = 17]; + oneof magic_number_present { + int32 magic_number = 1; + } + //[default = 1]; + oneof version_present { + int32 version = 2; + }; + PacketType type = 3; + //[default = NONE]; + oneof compression_present { + Compression compression = 4; + } + + bytes body = 5; } message HeartBeat { - optional int64 send_timestamp = 1; - optional int64 start_timestamp = 2; + int64 send_timestamp = 1; + int64 start_timestamp = 2; } message Handshake { - optional string communication_encoding = 1 [default = "utf8"]; - optional bytes seeds = 2; - repeated Compression supported_compressions = 3; + // [default = "utf8"]; + oneof communication_encoding_present { + string communication_encoding = 1; + } + bytes seeds = 2; + Compression supported_compressions = 3; } // client authentication message ClientAuth { - optional string username = 1; - optional bytes password = 2; // hashed password with seeds from Handshake message - optional int32 net_read_timeout = 3 [default = 0]; // in seconds - optional int32 net_write_timeout = 4 [default = 0]; // in seconds - optional string destination = 5; - optional string client_id = 6; - optional string filter = 7; - optional int64 start_timestamp = 8; + string username = 1; + bytes password = 2; // hashed password with seeds from Handshake message + // [default = 0] + oneof net_read_timeout_present { + int32 net_read_timeout = 3; // in seconds + } + // [default = 0]; + oneof net_write_timeout_present { + int32 net_write_timeout = 4; // in seconds + } + string destination = 5; + string client_id = 6; + string filter = 7; + int64 start_timestamp = 8; } message Ack { - optional int32 error_code = 1 [default = 0]; - optional string error_message = 2; // if something like compression is not supported, erorr_message will tell about it. + //[default = 0] + oneof error_code_present { + int32 error_code = 1; + } + string error_message = 2; // if something like compression is not supported, erorr_message will tell about it. } message ClientAck { - optional string destination = 1; - optional string client_id = 2; - optional int64 batch_id = 3; + string destination = 1; + string client_id = 2; + int64 batch_id = 3; } // subscription message Sub { - optional string destination = 1; - optional string client_id = 2; - optional string filter = 7; + string destination = 1; + string client_id = 2; + string filter = 7; } // Unsubscription message Unsub { - optional string destination = 1; - optional string client_id = 2; - optional string filter = 7; + string destination = 1; + string client_id = 2; + string filter = 7; } // PullRequest message Get { - optional string destination = 1; - optional string client_id = 2; - optional int32 fetch_size = 3; - optional int64 timeout = 4 [default = -1]; // 默认-1时代表不控制 - optional int32 unit = 5 [default = 2];// 数字类型,0:纳秒,1:毫秒,2:微秒,3:秒,4:分钟,5:小时,6:天 - optional bool auto_ack = 6 [default = false]; // 是否自动ack + string destination = 1; + string client_id = 2; + int32 fetch_size = 3; + //[default = -1] + oneof timeout_present { + int64 timeout = 4; // 默认-1时代表不控制 + } + //[default = 2] + oneof unit_present { + int32 unit = 5;// 数字类型,0:纳秒,1:毫秒,2:微秒,3:秒,4:分钟,5:小时,6:天 + } + //[default = false] + oneof auto_ack_present { + bool auto_ack = 6; // 是否自动ack + } + } // message Messages { - optional int64 batch_id = 1; + int64 batch_id = 1; repeated bytes messages = 2; } // TBD when new packets are required message Dump{ - optional string journal = 1; - optional int64 position = 2; - optional int64 timestamp = 3 [default = 0]; + string journal = 1; + int64 position = 2; + // [default = 0] + oneof timestamp_present { + int64 timestamp = 3; + } + } message ClientRollback{ - optional string destination = 1; - optional string client_id = 2; - optional int64 batch_id = 3; + string destination = 1; + string client_id = 2; + int64 batch_id = 3; } \ No newline at end of file diff --git a/src/Canal.Csharp.Protocol/EntryProtocol.cs b/src/Canal.Csharp.Protocol/EntryProtocol.cs index 5c94c92..067baa6 100644 --- a/src/Canal.Csharp.Protocol/EntryProtocol.cs +++ b/src/Canal.Csharp.Protocol/EntryProtocol.cs @@ -1,545 +1,2490 @@ -// This file was generated by a tool; you should avoid making direct changes. -// Consider using 'partial classes' to extend these types -// Input: EntryProtocol.proto - -#pragma warning disable CS0612, CS1591, CS3021, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 -namespace com.alibaba.otter.canal.protocol -{ - - [global::ProtoBuf.ProtoContract()] - public partial class Entry : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); - - [global::ProtoBuf.ProtoMember(1, Name = @"header")] - public Header Header { get; set; } - - [global::ProtoBuf.ProtoMember(2)] - [global::System.ComponentModel.DefaultValue(EntryType.Rowdata)] - public EntryType entryType - { - get { return __pbn__entryType ?? EntryType.Rowdata; } - set { __pbn__entryType = value; } - } - public bool ShouldSerializeentryType() => __pbn__entryType != null; - public void ResetentryType() => __pbn__entryType = null; - private EntryType? __pbn__entryType; - - [global::ProtoBuf.ProtoMember(3)] - public byte[] storeValue - { - get { return __pbn__storeValue; } - set { __pbn__storeValue = value; } - } - public bool ShouldSerializestoreValue() => __pbn__storeValue != null; - public void ResetstoreValue() => __pbn__storeValue = null; - private byte[] __pbn__storeValue; +// +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: EntryProtocol.proto +// +#pragma warning disable 1591, 0612, 3021 +#region Designer generated code + +using pb = global::Google.Protobuf; +using pbc = global::Google.Protobuf.Collections; +using pbr = global::Google.Protobuf.Reflection; +using scg = global::System.Collections.Generic; +namespace Com.Alibaba.Otter.Canal.Protocol { + + /// Holder for reflection information generated from EntryProtocol.proto + public static partial class EntryProtocolReflection { + + #region Descriptor + /// File descriptor for EntryProtocol.proto + public static pbr::FileDescriptor Descriptor { + get { return descriptor; } + } + private static pbr::FileDescriptor descriptor; + + static EntryProtocolReflection() { + byte[] descriptorData = global::System.Convert.FromBase64String( + string.Concat( + "ChNFbnRyeVByb3RvY29sLnByb3RvEiBjb20uYWxpYmFiYS5vdHRlci5jYW5h", + "bC5wcm90b2NvbCKsAQoFRW50cnkSOAoGaGVhZGVyGAEgASgLMiguY29tLmFs", + "aWJhYmEub3R0ZXIuY2FuYWwucHJvdG9jb2wuSGVhZGVyEkAKCWVudHJ5VHlw", + "ZRgCIAEoDjIrLmNvbS5hbGliYWJhLm90dGVyLmNhbmFsLnByb3RvY29sLkVu", + "dHJ5VHlwZUgAEhIKCnN0b3JlVmFsdWUYAyABKAxCEwoRZW50cnlUeXBlX3By", + "ZXNlbnQiwwMKBkhlYWRlchIRCgd2ZXJzaW9uGAEgASgFSAASEwoLbG9nZmls", + "ZU5hbWUYAiABKAkSFQoNbG9nZmlsZU9mZnNldBgDIAEoAxIQCghzZXJ2ZXJJ", + "ZBgEIAEoAxIUCgxzZXJ2ZXJlbkNvZGUYBSABKAkSEwoLZXhlY3V0ZVRpbWUY", + "BiABKAMSPAoKc291cmNlVHlwZRgHIAEoDjImLmNvbS5hbGliYWJhLm90dGVy", + "LmNhbmFsLnByb3RvY29sLlR5cGVIARISCgpzY2hlbWFOYW1lGAggASgJEhEK", + "CXRhYmxlTmFtZRgJIAEoCRITCgtldmVudExlbmd0aBgKIAEoAxJACglldmVu", + "dFR5cGUYCyABKA4yKy5jb20uYWxpYmFiYS5vdHRlci5jYW5hbC5wcm90b2Nv", + "bC5FdmVudFR5cGVIAhI1CgVwcm9wcxgMIAMoCzImLmNvbS5hbGliYWJhLm90", + "dGVyLmNhbmFsLnByb3RvY29sLlBhaXISDAoEZ3RpZBgNIAEoCUIRCg92ZXJz", + "aW9uX3ByZXNlbnRCFAoSc291cmNlVHlwZV9wcmVzZW50QhMKEWV2ZW50VHlw", + "ZV9wcmVzZW50IuMBCgZDb2x1bW4SDQoFaW5kZXgYASABKAUSDwoHc3FsVHlw", + "ZRgCIAEoBRIMCgRuYW1lGAMgASgJEg0KBWlzS2V5GAQgASgIEg8KB3VwZGF0", + "ZWQYBSABKAgSEAoGaXNOdWxsGAYgASgISAASNQoFcHJvcHMYByADKAsyJi5j", + "b20uYWxpYmFiYS5vdHRlci5jYW5hbC5wcm90b2NvbC5QYWlyEg0KBXZhbHVl", + "GAggASgJEg4KBmxlbmd0aBgJIAEoBRIRCglteXNxbFR5cGUYCiABKAlCEAoO", + "aXNOdWxsX3ByZXNlbnQiwQEKB1Jvd0RhdGESPwoNYmVmb3JlQ29sdW1ucxgB", + "IAMoCzIoLmNvbS5hbGliYWJhLm90dGVyLmNhbmFsLnByb3RvY29sLkNvbHVt", + "bhI+CgxhZnRlckNvbHVtbnMYAiADKAsyKC5jb20uYWxpYmFiYS5vdHRlci5j", + "YW5hbC5wcm90b2NvbC5Db2x1bW4SNQoFcHJvcHMYAyADKAsyJi5jb20uYWxp", + "YmFiYS5vdHRlci5jYW5hbC5wcm90b2NvbC5QYWlyIq0CCglSb3dDaGFuZ2US", + "DwoHdGFibGVJZBgBIAEoAxJACglldmVudFR5cGUYAiABKA4yKy5jb20uYWxp", + "YmFiYS5vdHRlci5jYW5hbC5wcm90b2NvbC5FdmVudFR5cGVIABIPCgVpc0Rk", + "bBgKIAEoCEgBEgsKA3NxbBgLIAEoCRI7Cghyb3dEYXRhcxgMIAMoCzIpLmNv", + "bS5hbGliYWJhLm90dGVyLmNhbmFsLnByb3RvY29sLlJvd0RhdGESNQoFcHJv", + "cHMYDSADKAsyJi5jb20uYWxpYmFiYS5vdHRlci5jYW5hbC5wcm90b2NvbC5Q", + "YWlyEhUKDWRkbFNjaGVtYU5hbWUYDiABKAlCEwoRZXZlbnRUeXBlX3ByZXNl", + "bnRCDwoNaXNEZGxfcHJlc2VudCKHAQoQVHJhbnNhY3Rpb25CZWdpbhITCgtl", + "eGVjdXRlVGltZRgBIAEoAxIVCg10cmFuc2FjdGlvbklkGAIgASgJEjUKBXBy", + "b3BzGAMgAygLMiYuY29tLmFsaWJhYmEub3R0ZXIuY2FuYWwucHJvdG9jb2wu", + "UGFpchIQCgh0aHJlYWRJZBgEIAEoAyJzCg5UcmFuc2FjdGlvbkVuZBITCgtl", + "eGVjdXRlVGltZRgBIAEoAxIVCg10cmFuc2FjdGlvbklkGAIgASgJEjUKBXBy", + "b3BzGAMgAygLMiYuY29tLmFsaWJhYmEub3R0ZXIuY2FuYWwucHJvdG9jb2wu", + "UGFpciIiCgRQYWlyEgsKA2tleRgBIAEoCRINCgV2YWx1ZRgCIAEoCSp9CglF", + "bnRyeVR5cGUSHQoZRU5UUllUWVBFQ09NUEFUSUJMRVBST1RPMhAAEhQKEFRS", + "QU5TQUNUSU9OQkVHSU4QARILCgdST1dEQVRBEAISEgoOVFJBTlNBQ1RJT05F", + "TkQQAxINCglIRUFSVEJFQVQQBBILCgdHVElETE9HEAUq5QEKCUV2ZW50VHlw", + "ZRIdChlFVkVOVFRZUEVDT01QQVRJQkxFUFJPVE8yEAASCgoGSU5TRVJUEAES", + "CgoGVVBEQVRFEAISCgoGREVMRVRFEAMSCgoGQ1JFQVRFEAQSCQoFQUxURVIQ", + "BRIJCgVFUkFTRRAGEgkKBVFVRVJZEAcSDAoIVFJVTkNBVEUQCBIKCgZSRU5B", + "TUUQCRIKCgZDSU5ERVgQChIKCgZESU5ERVgQCxIICgRHVElEEAwSDAoIWEFD", + "T01NSVQQDRIOCgpYQVJPTExCQUNLEA4SDgoKTUhFQVJUQkVBVBAPKkIKBFR5", + "cGUSGAoUVFlQRUNPTVBBVElCTEVQUk9UTzIQABIKCgZPUkFDTEUQARIJCgVN", + "WVNRTBACEgkKBVBHU1FMEANCMAogY29tLmFsaWJhYmEub3R0ZXIuY2FuYWwu", + "cHJvdG9jb2xCCkNhbmFsRW50cnlIAWIGcHJvdG8z")); + descriptor = pbr::FileDescriptor.FromGeneratedCode(descriptorData, + new pbr::FileDescriptor[] { }, + new pbr::GeneratedClrTypeInfo(new[] {typeof(global::Com.Alibaba.Otter.Canal.Protocol.EntryType), typeof(global::Com.Alibaba.Otter.Canal.Protocol.EventType), typeof(global::Com.Alibaba.Otter.Canal.Protocol.Type), }, new pbr::GeneratedClrTypeInfo[] { + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Entry), global::Com.Alibaba.Otter.Canal.Protocol.Entry.Parser, new[]{ "Header", "EntryType", "StoreValue" }, new[]{ "EntryTypePresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Header), global::Com.Alibaba.Otter.Canal.Protocol.Header.Parser, new[]{ "Version", "LogfileName", "LogfileOffset", "ServerId", "ServerenCode", "ExecuteTime", "SourceType", "SchemaName", "TableName", "EventLength", "EventType", "Props", "Gtid" }, new[]{ "VersionPresent", "SourceTypePresent", "EventTypePresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Column), global::Com.Alibaba.Otter.Canal.Protocol.Column.Parser, new[]{ "Index", "SqlType", "Name", "IsKey", "Updated", "IsNull", "Props", "Value", "Length", "MysqlType" }, new[]{ "IsNullPresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.RowData), global::Com.Alibaba.Otter.Canal.Protocol.RowData.Parser, new[]{ "BeforeColumns", "AfterColumns", "Props" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.RowChange), global::Com.Alibaba.Otter.Canal.Protocol.RowChange.Parser, new[]{ "TableId", "EventType", "IsDdl", "Sql", "RowDatas", "Props", "DdlSchemaName" }, new[]{ "EventTypePresent", "IsDdlPresent" }, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.TransactionBegin), global::Com.Alibaba.Otter.Canal.Protocol.TransactionBegin.Parser, new[]{ "ExecuteTime", "TransactionId", "Props", "ThreadId" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.TransactionEnd), global::Com.Alibaba.Otter.Canal.Protocol.TransactionEnd.Parser, new[]{ "ExecuteTime", "TransactionId", "Props" }, null, null, null), + new pbr::GeneratedClrTypeInfo(typeof(global::Com.Alibaba.Otter.Canal.Protocol.Pair), global::Com.Alibaba.Otter.Canal.Protocol.Pair.Parser, new[]{ "Key", "Value" }, null, null, null) + })); + } + #endregion + + } + #region Enums + /// + ///*打散后的事件类型,主要用于标识事务的开始,变更数据,结束* + /// + public enum EntryType { + [pbr::OriginalName("ENTRYTYPECOMPATIBLEPROTO2")] Compatibleproto2 = 0, + [pbr::OriginalName("TRANSACTIONBEGIN")] Transactionbegin = 1, + [pbr::OriginalName("ROWDATA")] Rowdata = 2, + [pbr::OriginalName("TRANSACTIONEND")] Transactionend = 3, + /// + ///* 心跳类型,内部使用,外部暂不可见,可忽略 * + /// + [pbr::OriginalName("HEARTBEAT")] Heartbeat = 4, + [pbr::OriginalName("GTIDLOG")] Gtidlog = 5, + } + + /// + ///* 事件类型 * + /// + public enum EventType { + [pbr::OriginalName("EVENTTYPECOMPATIBLEPROTO2")] Compatibleproto2 = 0, + [pbr::OriginalName("INSERT")] Insert = 1, + [pbr::OriginalName("UPDATE")] Update = 2, + [pbr::OriginalName("DELETE")] Delete = 3, + [pbr::OriginalName("CREATE")] Create = 4, + [pbr::OriginalName("ALTER")] Alter = 5, + [pbr::OriginalName("ERASE")] Erase = 6, + [pbr::OriginalName("QUERY")] Query = 7, + [pbr::OriginalName("TRUNCATE")] Truncate = 8, + [pbr::OriginalName("RENAME")] Rename = 9, + /// + ///*CREATE INDEX* + /// + [pbr::OriginalName("CINDEX")] Cindex = 10, + [pbr::OriginalName("DINDEX")] Dindex = 11, + [pbr::OriginalName("GTID")] Gtid = 12, + /// + ///* XA * + /// + [pbr::OriginalName("XACOMMIT")] Xacommit = 13, + [pbr::OriginalName("XAROLLBACK")] Xarollback = 14, + /// + ///* MASTER HEARTBEAT * + /// + [pbr::OriginalName("MHEARTBEAT")] Mheartbeat = 15, + } + + /// + ///*数据库类型* + /// + public enum Type { + [pbr::OriginalName("TYPECOMPATIBLEPROTO2")] Compatibleproto2 = 0, + [pbr::OriginalName("ORACLE")] Oracle = 1, + [pbr::OriginalName("MYSQL")] Mysql = 2, + [pbr::OriginalName("PGSQL")] Pgsql = 3, + } + + #endregion + + #region Messages + /// + ///*************************************************************** + /// message model + ///如果要在Enum中新增类型,确保以前的类型的下标值不变. + ///************************************************************** + /// + public sealed partial class Entry : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Entry()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.EntryProtocolReflection.Descriptor.MessageTypes[0]; } + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } } - [global::ProtoBuf.ProtoContract()] - public partial class Header : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Entry() { + OnConstruction(); + } - [global::ProtoBuf.ProtoMember(1, Name = @"version")] - [global::System.ComponentModel.DefaultValue(1)] - public int Version - { - get { return __pbn__Version ?? 1; } - set { __pbn__Version = value; } - } - public bool ShouldSerializeVersion() => __pbn__Version != null; - public void ResetVersion() => __pbn__Version = null; - private int? __pbn__Version; - - [global::ProtoBuf.ProtoMember(2)] - [global::System.ComponentModel.DefaultValue("")] - public string logfileName - { - get { return __pbn__logfileName ?? ""; } - set { __pbn__logfileName = value; } - } - public bool ShouldSerializelogfileName() => __pbn__logfileName != null; - public void ResetlogfileName() => __pbn__logfileName = null; - private string __pbn__logfileName; - - [global::ProtoBuf.ProtoMember(3)] - public long logfileOffset - { - get { return __pbn__logfileOffset.GetValueOrDefault(); } - set { __pbn__logfileOffset = value; } - } - public bool ShouldSerializelogfileOffset() => __pbn__logfileOffset != null; - public void ResetlogfileOffset() => __pbn__logfileOffset = null; - private long? __pbn__logfileOffset; - - [global::ProtoBuf.ProtoMember(4)] - public long serverId - { - get { return __pbn__serverId.GetValueOrDefault(); } - set { __pbn__serverId = value; } - } - public bool ShouldSerializeserverId() => __pbn__serverId != null; - public void ResetserverId() => __pbn__serverId = null; - private long? __pbn__serverId; - - [global::ProtoBuf.ProtoMember(5)] - [global::System.ComponentModel.DefaultValue("")] - public string serverenCode - { - get { return __pbn__serverenCode ?? ""; } - set { __pbn__serverenCode = value; } - } - public bool ShouldSerializeserverenCode() => __pbn__serverenCode != null; - public void ResetserverenCode() => __pbn__serverenCode = null; - private string __pbn__serverenCode; - - [global::ProtoBuf.ProtoMember(6)] - public long executeTime - { - get { return __pbn__executeTime.GetValueOrDefault(); } - set { __pbn__executeTime = value; } - } - public bool ShouldSerializeexecuteTime() => __pbn__executeTime != null; - public void ResetexecuteTime() => __pbn__executeTime = null; - private long? __pbn__executeTime; - - [global::ProtoBuf.ProtoMember(7)] - [global::System.ComponentModel.DefaultValue(Type.Mysql)] - public Type sourceType - { - get { return __pbn__sourceType ?? Type.Mysql; } - set { __pbn__sourceType = value; } - } - public bool ShouldSerializesourceType() => __pbn__sourceType != null; - public void ResetsourceType() => __pbn__sourceType = null; - private Type? __pbn__sourceType; - - [global::ProtoBuf.ProtoMember(8)] - [global::System.ComponentModel.DefaultValue("")] - public string schemaName - { - get { return __pbn__schemaName ?? ""; } - set { __pbn__schemaName = value; } - } - public bool ShouldSerializeschemaName() => __pbn__schemaName != null; - public void ResetschemaName() => __pbn__schemaName = null; - private string __pbn__schemaName; - - [global::ProtoBuf.ProtoMember(9)] - [global::System.ComponentModel.DefaultValue("")] - public string tableName - { - get { return __pbn__tableName ?? ""; } - set { __pbn__tableName = value; } - } - public bool ShouldSerializetableName() => __pbn__tableName != null; - public void ResettableName() => __pbn__tableName = null; - private string __pbn__tableName; - - [global::ProtoBuf.ProtoMember(10)] - public long eventLength - { - get { return __pbn__eventLength.GetValueOrDefault(); } - set { __pbn__eventLength = value; } - } - public bool ShouldSerializeeventLength() => __pbn__eventLength != null; - public void ReseteventLength() => __pbn__eventLength = null; - private long? __pbn__eventLength; - - [global::ProtoBuf.ProtoMember(11)] - [global::System.ComponentModel.DefaultValue(EventType.Update)] - public EventType eventType - { - get { return __pbn__eventType ?? EventType.Update; } - set { __pbn__eventType = value; } - } - public bool ShouldSerializeeventType() => __pbn__eventType != null; - public void ReseteventType() => __pbn__eventType = null; - private EventType? __pbn__eventType; - - [global::ProtoBuf.ProtoMember(12, Name = @"props")] - public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); - - [global::ProtoBuf.ProtoMember(13, Name = @"gtid")] - [global::System.ComponentModel.DefaultValue("")] - public string Gtid - { - get { return __pbn__Gtid ?? ""; } - set { __pbn__Gtid = value; } - } - public bool ShouldSerializeGtid() => __pbn__Gtid != null; - public void ResetGtid() => __pbn__Gtid = null; - private string __pbn__Gtid; + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Entry(Entry other) : this() { + header_ = other.header_ != null ? other.header_.Clone() : null; + storeValue_ = other.storeValue_; + switch (other.EntryTypePresentCase) { + case EntryTypePresentOneofCase.EntryType: + EntryType = other.EntryType; + break; + } + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); } - [global::ProtoBuf.ProtoContract()] - public partial class Column : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Entry Clone() { + return new Entry(this); + } - [global::ProtoBuf.ProtoMember(1, Name = @"index")] - public int Index - { - get { return __pbn__Index.GetValueOrDefault(); } - set { __pbn__Index = value; } - } - public bool ShouldSerializeIndex() => __pbn__Index != null; - public void ResetIndex() => __pbn__Index = null; - private int? __pbn__Index; - - [global::ProtoBuf.ProtoMember(2)] - public int sqlType - { - get { return __pbn__sqlType.GetValueOrDefault(); } - set { __pbn__sqlType = value; } - } - public bool ShouldSerializesqlType() => __pbn__sqlType != null; - public void ResetsqlType() => __pbn__sqlType = null; - private int? __pbn__sqlType; - - [global::ProtoBuf.ProtoMember(3, Name = @"name")] - [global::System.ComponentModel.DefaultValue("")] - public string Name - { - get { return __pbn__Name ?? ""; } - set { __pbn__Name = value; } - } - public bool ShouldSerializeName() => __pbn__Name != null; - public void ResetName() => __pbn__Name = null; - private string __pbn__Name; - - [global::ProtoBuf.ProtoMember(4)] - public bool isKey - { - get { return __pbn__isKey.GetValueOrDefault(); } - set { __pbn__isKey = value; } - } - public bool ShouldSerializeisKey() => __pbn__isKey != null; - public void ResetisKey() => __pbn__isKey = null; - private bool? __pbn__isKey; - - [global::ProtoBuf.ProtoMember(5, Name = @"updated")] - public bool Updated - { - get { return __pbn__Updated.GetValueOrDefault(); } - set { __pbn__Updated = value; } - } - public bool ShouldSerializeUpdated() => __pbn__Updated != null; - public void ResetUpdated() => __pbn__Updated = null; - private bool? __pbn__Updated; - - [global::ProtoBuf.ProtoMember(6)] - [global::System.ComponentModel.DefaultValue(false)] - public bool isNull - { - get { return __pbn__isNull ?? false; } - set { __pbn__isNull = value; } - } - public bool ShouldSerializeisNull() => __pbn__isNull != null; - public void ResetisNull() => __pbn__isNull = null; - private bool? __pbn__isNull; - - [global::ProtoBuf.ProtoMember(7, Name = @"props")] - public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); - - [global::ProtoBuf.ProtoMember(8, Name = @"value")] - [global::System.ComponentModel.DefaultValue("")] - public string Value - { - get { return __pbn__Value ?? ""; } - set { __pbn__Value = value; } - } - public bool ShouldSerializeValue() => __pbn__Value != null; - public void ResetValue() => __pbn__Value = null; - private string __pbn__Value; - - [global::ProtoBuf.ProtoMember(9, Name = @"length")] - public int Length - { - get { return __pbn__Length.GetValueOrDefault(); } - set { __pbn__Length = value; } - } - public bool ShouldSerializeLength() => __pbn__Length != null; - public void ResetLength() => __pbn__Length = null; - private int? __pbn__Length; - - [global::ProtoBuf.ProtoMember(10)] - [global::System.ComponentModel.DefaultValue("")] - public string mysqlType - { - get { return __pbn__mysqlType ?? ""; } - set { __pbn__mysqlType = value; } - } - public bool ShouldSerializemysqlType() => __pbn__mysqlType != null; - public void ResetmysqlType() => __pbn__mysqlType = null; - private string __pbn__mysqlType; + /// Field number for the "header" field. + public const int HeaderFieldNumber = 1; + private global::Com.Alibaba.Otter.Canal.Protocol.Header header_; + /// + ///*协议头部信息* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Com.Alibaba.Otter.Canal.Protocol.Header Header { + get { return header_; } + set { + header_ = value; + } + } + + /// Field number for the "entryType" field. + public const int EntryTypeFieldNumber = 2; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Com.Alibaba.Otter.Canal.Protocol.EntryType EntryType { + get { return entryTypePresentCase_ == EntryTypePresentOneofCase.EntryType ? (global::Com.Alibaba.Otter.Canal.Protocol.EntryType) entryTypePresent_ : 0; } + set { + entryTypePresent_ = value; + entryTypePresentCase_ = EntryTypePresentOneofCase.EntryType; + } + } + + /// Field number for the "storeValue" field. + public const int StoreValueFieldNumber = 3; + private pb::ByteString storeValue_ = pb::ByteString.Empty; + /// + ///*传输的二进制数组* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pb::ByteString StoreValue { + get { return storeValue_; } + set { + storeValue_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + private object entryTypePresent_; + /// Enum of possible cases for the "entryType_present" oneof. + public enum EntryTypePresentOneofCase { + None = 0, + EntryType = 2, + } + private EntryTypePresentOneofCase entryTypePresentCase_ = EntryTypePresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EntryTypePresentOneofCase EntryTypePresentCase { + get { return entryTypePresentCase_; } } - [global::ProtoBuf.ProtoContract()] - public partial class RowData : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearEntryTypePresent() { + entryTypePresentCase_ = EntryTypePresentOneofCase.None; + entryTypePresent_ = null; + } - [global::ProtoBuf.ProtoMember(1)] - public global::System.Collections.Generic.List beforeColumns { get; } = new global::System.Collections.Generic.List(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Entry); + } - [global::ProtoBuf.ProtoMember(2)] - public global::System.Collections.Generic.List afterColumns { get; } = new global::System.Collections.Generic.List(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Entry other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (!object.Equals(Header, other.Header)) return false; + if (EntryType != other.EntryType) return false; + if (StoreValue != other.StoreValue) return false; + if (EntryTypePresentCase != other.EntryTypePresentCase) return false; + return Equals(_unknownFields, other._unknownFields); + } - [global::ProtoBuf.ProtoMember(3, Name = @"props")] - public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (header_ != null) hash ^= Header.GetHashCode(); + if (entryTypePresentCase_ == EntryTypePresentOneofCase.EntryType) hash ^= EntryType.GetHashCode(); + if (StoreValue.Length != 0) hash ^= StoreValue.GetHashCode(); + hash ^= (int) entryTypePresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); } - [global::ProtoBuf.ProtoContract()] - public partial class RowChange : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (header_ != null) { + output.WriteRawTag(10); + output.WriteMessage(Header); + } + if (entryTypePresentCase_ == EntryTypePresentOneofCase.EntryType) { + output.WriteRawTag(16); + output.WriteEnum((int) EntryType); + } + if (StoreValue.Length != 0) { + output.WriteRawTag(26); + output.WriteBytes(StoreValue); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } - [global::ProtoBuf.ProtoMember(1)] - public long tableId - { - get { return __pbn__tableId.GetValueOrDefault(); } - set { __pbn__tableId = value; } - } - public bool ShouldSerializetableId() => __pbn__tableId != null; - public void ResettableId() => __pbn__tableId = null; - private long? __pbn__tableId; - - [global::ProtoBuf.ProtoMember(2)] - [global::System.ComponentModel.DefaultValue(EventType.Update)] - public EventType eventType - { - get { return __pbn__eventType ?? EventType.Update; } - set { __pbn__eventType = value; } - } - public bool ShouldSerializeeventType() => __pbn__eventType != null; - public void ReseteventType() => __pbn__eventType = null; - private EventType? __pbn__eventType; - - [global::ProtoBuf.ProtoMember(10)] - [global::System.ComponentModel.DefaultValue(false)] - public bool isDdl - { - get { return __pbn__isDdl ?? false; } - set { __pbn__isDdl = value; } - } - public bool ShouldSerializeisDdl() => __pbn__isDdl != null; - public void ResetisDdl() => __pbn__isDdl = null; - private bool? __pbn__isDdl; - - [global::ProtoBuf.ProtoMember(11, Name = @"sql")] - [global::System.ComponentModel.DefaultValue("")] - public string Sql - { - get { return __pbn__Sql ?? ""; } - set { __pbn__Sql = value; } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (header_ != null) { + size += 1 + pb::CodedOutputStream.ComputeMessageSize(Header); + } + if (entryTypePresentCase_ == EntryTypePresentOneofCase.EntryType) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) EntryType); + } + if (StoreValue.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeBytesSize(StoreValue); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Entry other) { + if (other == null) { + return; + } + if (other.header_ != null) { + if (header_ == null) { + header_ = new global::Com.Alibaba.Otter.Canal.Protocol.Header(); } - public bool ShouldSerializeSql() => __pbn__Sql != null; - public void ResetSql() => __pbn__Sql = null; - private string __pbn__Sql; - - [global::ProtoBuf.ProtoMember(12)] - public global::System.Collections.Generic.List rowDatas { get; } = new global::System.Collections.Generic.List(); - - [global::ProtoBuf.ProtoMember(13, Name = @"props")] - public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); - - [global::ProtoBuf.ProtoMember(14)] - [global::System.ComponentModel.DefaultValue("")] - public string ddlSchemaName - { - get { return __pbn__ddlSchemaName ?? ""; } - set { __pbn__ddlSchemaName = value; } + Header.MergeFrom(other.Header); + } + if (other.StoreValue.Length != 0) { + StoreValue = other.StoreValue; + } + switch (other.EntryTypePresentCase) { + case EntryTypePresentOneofCase.EntryType: + EntryType = other.EntryType; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + if (header_ == null) { + header_ = new global::Com.Alibaba.Otter.Canal.Protocol.Header(); + } + input.ReadMessage(header_); + break; + } + case 16: { + entryTypePresent_ = input.ReadEnum(); + entryTypePresentCase_ = EntryTypePresentOneofCase.EntryType; + break; + } + case 26: { + StoreValue = input.ReadBytes(); + break; + } } - public bool ShouldSerializeddlSchemaName() => __pbn__ddlSchemaName != null; - public void ResetddlSchemaName() => __pbn__ddlSchemaName = null; - private string __pbn__ddlSchemaName; + } + } + + } + + /// + ///*message Header* + /// + public sealed partial class Header : pb::IMessage
{ + private static readonly pb::MessageParser
_parser = new pb::MessageParser
(() => new Header()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser
Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.EntryProtocolReflection.Descriptor.MessageTypes[1]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Header() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Header(Header other) : this() { + logfileName_ = other.logfileName_; + logfileOffset_ = other.logfileOffset_; + serverId_ = other.serverId_; + serverenCode_ = other.serverenCode_; + executeTime_ = other.executeTime_; + schemaName_ = other.schemaName_; + tableName_ = other.tableName_; + eventLength_ = other.eventLength_; + props_ = other.props_.Clone(); + gtid_ = other.gtid_; + switch (other.VersionPresentCase) { + case VersionPresentOneofCase.Version: + Version = other.Version; + break; + } + + switch (other.SourceTypePresentCase) { + case SourceTypePresentOneofCase.SourceType: + SourceType = other.SourceType; + break; + } + + switch (other.EventTypePresentCase) { + case EventTypePresentOneofCase.EventType: + EventType = other.EventType; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Header Clone() { + return new Header(this); + } + + /// Field number for the "version" field. + public const int VersionFieldNumber = 1; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Version { + get { return versionPresentCase_ == VersionPresentOneofCase.Version ? (int) versionPresent_ : 0; } + set { + versionPresent_ = value; + versionPresentCase_ = VersionPresentOneofCase.Version; + } + } + + /// Field number for the "logfileName" field. + public const int LogfileNameFieldNumber = 2; + private string logfileName_ = ""; + /// + ///*binlog/redolog 文件名* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string LogfileName { + get { return logfileName_; } + set { + logfileName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "logfileOffset" field. + public const int LogfileOffsetFieldNumber = 3; + private long logfileOffset_; + /// + ///*binlog/redolog 文件的偏移位置* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long LogfileOffset { + get { return logfileOffset_; } + set { + logfileOffset_ = value; + } + } + /// Field number for the "serverId" field. + public const int ServerIdFieldNumber = 4; + private long serverId_; + /// + ///*服务端serverId* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long ServerId { + get { return serverId_; } + set { + serverId_ = value; + } } - [global::ProtoBuf.ProtoContract()] - public partial class TransactionBegin : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + /// Field number for the "serverenCode" field. + public const int ServerenCodeFieldNumber = 5; + private string serverenCode_ = ""; + /// + ///* 变更数据的编码 * + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string ServerenCode { + get { return serverenCode_; } + set { + serverenCode_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "executeTime" field. + public const int ExecuteTimeFieldNumber = 6; + private long executeTime_; + /// + ///*变更数据的执行时间 * + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long ExecuteTime { + get { return executeTime_; } + set { + executeTime_ = value; + } + } + + /// Field number for the "sourceType" field. + public const int SourceTypeFieldNumber = 7; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Com.Alibaba.Otter.Canal.Protocol.Type SourceType { + get { return sourceTypePresentCase_ == SourceTypePresentOneofCase.SourceType ? (global::Com.Alibaba.Otter.Canal.Protocol.Type) sourceTypePresent_ : 0; } + set { + sourceTypePresent_ = value; + sourceTypePresentCase_ = SourceTypePresentOneofCase.SourceType; + } + } + + /// Field number for the "schemaName" field. + public const int SchemaNameFieldNumber = 8; + private string schemaName_ = ""; + /// + ///* 变更数据的schemaname* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string SchemaName { + get { return schemaName_; } + set { + schemaName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "tableName" field. + public const int TableNameFieldNumber = 9; + private string tableName_ = ""; + /// + ///*变更数据的tablename* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string TableName { + get { return tableName_; } + set { + tableName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "eventLength" field. + public const int EventLengthFieldNumber = 10; + private long eventLength_; + /// + ///*每个event的长度* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long EventLength { + get { return eventLength_; } + set { + eventLength_ = value; + } + } + + /// Field number for the "eventType" field. + public const int EventTypeFieldNumber = 11; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Com.Alibaba.Otter.Canal.Protocol.EventType EventType { + get { return eventTypePresentCase_ == EventTypePresentOneofCase.EventType ? (global::Com.Alibaba.Otter.Canal.Protocol.EventType) eventTypePresent_ : 0; } + set { + eventTypePresent_ = value; + eventTypePresentCase_ = EventTypePresentOneofCase.EventType; + } + } + + /// Field number for the "props" field. + public const int PropsFieldNumber = 12; + private static readonly pb::FieldCodec _repeated_props_codec + = pb::FieldCodec.ForMessage(98, global::Com.Alibaba.Otter.Canal.Protocol.Pair.Parser); + private readonly pbc::RepeatedField props_ = new pbc::RepeatedField(); + /// + ///*预留扩展* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Props { + get { return props_; } + } + + /// Field number for the "gtid" field. + public const int GtidFieldNumber = 13; + private string gtid_ = ""; + /// + ///*当前事务的gitd* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Gtid { + get { return gtid_; } + set { + gtid_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + private object versionPresent_; + /// Enum of possible cases for the "version_present" oneof. + public enum VersionPresentOneofCase { + None = 0, + Version = 1, + } + private VersionPresentOneofCase versionPresentCase_ = VersionPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public VersionPresentOneofCase VersionPresentCase { + get { return versionPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearVersionPresent() { + versionPresentCase_ = VersionPresentOneofCase.None; + versionPresent_ = null; + } - [global::ProtoBuf.ProtoMember(1)] - public long executeTime - { - get { return __pbn__executeTime.GetValueOrDefault(); } - set { __pbn__executeTime = value; } + private object sourceTypePresent_; + /// Enum of possible cases for the "sourceType_present" oneof. + public enum SourceTypePresentOneofCase { + None = 0, + SourceType = 7, + } + private SourceTypePresentOneofCase sourceTypePresentCase_ = SourceTypePresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public SourceTypePresentOneofCase SourceTypePresentCase { + get { return sourceTypePresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearSourceTypePresent() { + sourceTypePresentCase_ = SourceTypePresentOneofCase.None; + sourceTypePresent_ = null; + } + + private object eventTypePresent_; + /// Enum of possible cases for the "eventType_present" oneof. + public enum EventTypePresentOneofCase { + None = 0, + EventType = 11, + } + private EventTypePresentOneofCase eventTypePresentCase_ = EventTypePresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EventTypePresentOneofCase EventTypePresentCase { + get { return eventTypePresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearEventTypePresent() { + eventTypePresentCase_ = EventTypePresentOneofCase.None; + eventTypePresent_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Header); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Header other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Version != other.Version) return false; + if (LogfileName != other.LogfileName) return false; + if (LogfileOffset != other.LogfileOffset) return false; + if (ServerId != other.ServerId) return false; + if (ServerenCode != other.ServerenCode) return false; + if (ExecuteTime != other.ExecuteTime) return false; + if (SourceType != other.SourceType) return false; + if (SchemaName != other.SchemaName) return false; + if (TableName != other.TableName) return false; + if (EventLength != other.EventLength) return false; + if (EventType != other.EventType) return false; + if(!props_.Equals(other.props_)) return false; + if (Gtid != other.Gtid) return false; + if (VersionPresentCase != other.VersionPresentCase) return false; + if (SourceTypePresentCase != other.SourceTypePresentCase) return false; + if (EventTypePresentCase != other.EventTypePresentCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (versionPresentCase_ == VersionPresentOneofCase.Version) hash ^= Version.GetHashCode(); + if (LogfileName.Length != 0) hash ^= LogfileName.GetHashCode(); + if (LogfileOffset != 0L) hash ^= LogfileOffset.GetHashCode(); + if (ServerId != 0L) hash ^= ServerId.GetHashCode(); + if (ServerenCode.Length != 0) hash ^= ServerenCode.GetHashCode(); + if (ExecuteTime != 0L) hash ^= ExecuteTime.GetHashCode(); + if (sourceTypePresentCase_ == SourceTypePresentOneofCase.SourceType) hash ^= SourceType.GetHashCode(); + if (SchemaName.Length != 0) hash ^= SchemaName.GetHashCode(); + if (TableName.Length != 0) hash ^= TableName.GetHashCode(); + if (EventLength != 0L) hash ^= EventLength.GetHashCode(); + if (eventTypePresentCase_ == EventTypePresentOneofCase.EventType) hash ^= EventType.GetHashCode(); + hash ^= props_.GetHashCode(); + if (Gtid.Length != 0) hash ^= Gtid.GetHashCode(); + hash ^= (int) versionPresentCase_; + hash ^= (int) sourceTypePresentCase_; + hash ^= (int) eventTypePresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (versionPresentCase_ == VersionPresentOneofCase.Version) { + output.WriteRawTag(8); + output.WriteInt32(Version); + } + if (LogfileName.Length != 0) { + output.WriteRawTag(18); + output.WriteString(LogfileName); + } + if (LogfileOffset != 0L) { + output.WriteRawTag(24); + output.WriteInt64(LogfileOffset); + } + if (ServerId != 0L) { + output.WriteRawTag(32); + output.WriteInt64(ServerId); + } + if (ServerenCode.Length != 0) { + output.WriteRawTag(42); + output.WriteString(ServerenCode); + } + if (ExecuteTime != 0L) { + output.WriteRawTag(48); + output.WriteInt64(ExecuteTime); + } + if (sourceTypePresentCase_ == SourceTypePresentOneofCase.SourceType) { + output.WriteRawTag(56); + output.WriteEnum((int) SourceType); + } + if (SchemaName.Length != 0) { + output.WriteRawTag(66); + output.WriteString(SchemaName); + } + if (TableName.Length != 0) { + output.WriteRawTag(74); + output.WriteString(TableName); + } + if (EventLength != 0L) { + output.WriteRawTag(80); + output.WriteInt64(EventLength); + } + if (eventTypePresentCase_ == EventTypePresentOneofCase.EventType) { + output.WriteRawTag(88); + output.WriteEnum((int) EventType); + } + props_.WriteTo(output, _repeated_props_codec); + if (Gtid.Length != 0) { + output.WriteRawTag(106); + output.WriteString(Gtid); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (versionPresentCase_ == VersionPresentOneofCase.Version) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Version); + } + if (LogfileName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(LogfileName); + } + if (LogfileOffset != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(LogfileOffset); + } + if (ServerId != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(ServerId); + } + if (ServerenCode.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(ServerenCode); + } + if (ExecuteTime != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(ExecuteTime); + } + if (sourceTypePresentCase_ == SourceTypePresentOneofCase.SourceType) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) SourceType); + } + if (SchemaName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(SchemaName); + } + if (TableName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(TableName); + } + if (EventLength != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(EventLength); + } + if (eventTypePresentCase_ == EventTypePresentOneofCase.EventType) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) EventType); + } + size += props_.CalculateSize(_repeated_props_codec); + if (Gtid.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Gtid); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Header other) { + if (other == null) { + return; + } + if (other.LogfileName.Length != 0) { + LogfileName = other.LogfileName; + } + if (other.LogfileOffset != 0L) { + LogfileOffset = other.LogfileOffset; + } + if (other.ServerId != 0L) { + ServerId = other.ServerId; + } + if (other.ServerenCode.Length != 0) { + ServerenCode = other.ServerenCode; + } + if (other.ExecuteTime != 0L) { + ExecuteTime = other.ExecuteTime; + } + if (other.SchemaName.Length != 0) { + SchemaName = other.SchemaName; + } + if (other.TableName.Length != 0) { + TableName = other.TableName; + } + if (other.EventLength != 0L) { + EventLength = other.EventLength; + } + props_.Add(other.props_); + if (other.Gtid.Length != 0) { + Gtid = other.Gtid; + } + switch (other.VersionPresentCase) { + case VersionPresentOneofCase.Version: + Version = other.Version; + break; + } + + switch (other.SourceTypePresentCase) { + case SourceTypePresentOneofCase.SourceType: + SourceType = other.SourceType; + break; + } + + switch (other.EventTypePresentCase) { + case EventTypePresentOneofCase.EventType: + EventType = other.EventType; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Version = input.ReadInt32(); + break; + } + case 18: { + LogfileName = input.ReadString(); + break; + } + case 24: { + LogfileOffset = input.ReadInt64(); + break; + } + case 32: { + ServerId = input.ReadInt64(); + break; + } + case 42: { + ServerenCode = input.ReadString(); + break; + } + case 48: { + ExecuteTime = input.ReadInt64(); + break; + } + case 56: { + sourceTypePresent_ = input.ReadEnum(); + sourceTypePresentCase_ = SourceTypePresentOneofCase.SourceType; + break; + } + case 66: { + SchemaName = input.ReadString(); + break; + } + case 74: { + TableName = input.ReadString(); + break; + } + case 80: { + EventLength = input.ReadInt64(); + break; + } + case 88: { + eventTypePresent_ = input.ReadEnum(); + eventTypePresentCase_ = EventTypePresentOneofCase.EventType; + break; + } + case 98: { + props_.AddEntriesFrom(input, _repeated_props_codec); + break; + } + case 106: { + Gtid = input.ReadString(); + break; + } } - public bool ShouldSerializeexecuteTime() => __pbn__executeTime != null; - public void ResetexecuteTime() => __pbn__executeTime = null; - private long? __pbn__executeTime; - - [global::ProtoBuf.ProtoMember(2)] - [global::System.ComponentModel.DefaultValue("")] - public string transactionId - { - get { return __pbn__transactionId ?? ""; } - set { __pbn__transactionId = value; } + } + } + + } + + /// + ///*每个字段的数据结构* + /// + public sealed partial class Column : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Column()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.EntryProtocolReflection.Descriptor.MessageTypes[2]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Column() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Column(Column other) : this() { + index_ = other.index_; + sqlType_ = other.sqlType_; + name_ = other.name_; + isKey_ = other.isKey_; + updated_ = other.updated_; + props_ = other.props_.Clone(); + value_ = other.value_; + length_ = other.length_; + mysqlType_ = other.mysqlType_; + switch (other.IsNullPresentCase) { + case IsNullPresentOneofCase.IsNull: + IsNull = other.IsNull; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Column Clone() { + return new Column(this); + } + + /// Field number for the "index" field. + public const int IndexFieldNumber = 1; + private int index_; + /// + ///*字段下标* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Index { + get { return index_; } + set { + index_ = value; + } + } + + /// Field number for the "sqlType" field. + public const int SqlTypeFieldNumber = 2; + private int sqlType_; + /// + ///*字段java中类型* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int SqlType { + get { return sqlType_; } + set { + sqlType_ = value; + } + } + + /// Field number for the "name" field. + public const int NameFieldNumber = 3; + private string name_ = ""; + /// + ///*字段名称(忽略大小写),在mysql中是没有的* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Name { + get { return name_; } + set { + name_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "isKey" field. + public const int IsKeyFieldNumber = 4; + private bool isKey_; + /// + ///*是否是主键* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool IsKey { + get { return isKey_; } + set { + isKey_ = value; + } + } + + /// Field number for the "updated" field. + public const int UpdatedFieldNumber = 5; + private bool updated_; + /// + ///*如果EventType=UPDATE,用于标识这个字段值是否有修改* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Updated { + get { return updated_; } + set { + updated_ = value; + } + } + + /// Field number for the "isNull" field. + public const int IsNullFieldNumber = 6; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool IsNull { + get { return isNullPresentCase_ == IsNullPresentOneofCase.IsNull ? (bool) isNullPresent_ : false; } + set { + isNullPresent_ = value; + isNullPresentCase_ = IsNullPresentOneofCase.IsNull; + } + } + + /// Field number for the "props" field. + public const int PropsFieldNumber = 7; + private static readonly pb::FieldCodec _repeated_props_codec + = pb::FieldCodec.ForMessage(58, global::Com.Alibaba.Otter.Canal.Protocol.Pair.Parser); + private readonly pbc::RepeatedField props_ = new pbc::RepeatedField(); + /// + ///*预留扩展* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Props { + get { return props_; } + } + + /// Field number for the "value" field. + public const int ValueFieldNumber = 8; + private string value_ = ""; + /// + ///* 字段值,timestamp,Datetime是一个时间格式的文本 * + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Value { + get { return value_; } + set { + value_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "length" field. + public const int LengthFieldNumber = 9; + private int length_; + /// + ///* 对应数据对象原始长度 * + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int Length { + get { return length_; } + set { + length_ = value; + } + } + + /// Field number for the "mysqlType" field. + public const int MysqlTypeFieldNumber = 10; + private string mysqlType_ = ""; + /// + ///*字段mysql类型* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string MysqlType { + get { return mysqlType_; } + set { + mysqlType_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + private object isNullPresent_; + /// Enum of possible cases for the "isNull_present" oneof. + public enum IsNullPresentOneofCase { + None = 0, + IsNull = 6, + } + private IsNullPresentOneofCase isNullPresentCase_ = IsNullPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public IsNullPresentOneofCase IsNullPresentCase { + get { return isNullPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearIsNullPresent() { + isNullPresentCase_ = IsNullPresentOneofCase.None; + isNullPresent_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Column); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Column other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Index != other.Index) return false; + if (SqlType != other.SqlType) return false; + if (Name != other.Name) return false; + if (IsKey != other.IsKey) return false; + if (Updated != other.Updated) return false; + if (IsNull != other.IsNull) return false; + if(!props_.Equals(other.props_)) return false; + if (Value != other.Value) return false; + if (Length != other.Length) return false; + if (MysqlType != other.MysqlType) return false; + if (IsNullPresentCase != other.IsNullPresentCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Index != 0) hash ^= Index.GetHashCode(); + if (SqlType != 0) hash ^= SqlType.GetHashCode(); + if (Name.Length != 0) hash ^= Name.GetHashCode(); + if (IsKey != false) hash ^= IsKey.GetHashCode(); + if (Updated != false) hash ^= Updated.GetHashCode(); + if (isNullPresentCase_ == IsNullPresentOneofCase.IsNull) hash ^= IsNull.GetHashCode(); + hash ^= props_.GetHashCode(); + if (Value.Length != 0) hash ^= Value.GetHashCode(); + if (Length != 0) hash ^= Length.GetHashCode(); + if (MysqlType.Length != 0) hash ^= MysqlType.GetHashCode(); + hash ^= (int) isNullPresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Index != 0) { + output.WriteRawTag(8); + output.WriteInt32(Index); + } + if (SqlType != 0) { + output.WriteRawTag(16); + output.WriteInt32(SqlType); + } + if (Name.Length != 0) { + output.WriteRawTag(26); + output.WriteString(Name); + } + if (IsKey != false) { + output.WriteRawTag(32); + output.WriteBool(IsKey); + } + if (Updated != false) { + output.WriteRawTag(40); + output.WriteBool(Updated); + } + if (isNullPresentCase_ == IsNullPresentOneofCase.IsNull) { + output.WriteRawTag(48); + output.WriteBool(IsNull); + } + props_.WriteTo(output, _repeated_props_codec); + if (Value.Length != 0) { + output.WriteRawTag(66); + output.WriteString(Value); + } + if (Length != 0) { + output.WriteRawTag(72); + output.WriteInt32(Length); + } + if (MysqlType.Length != 0) { + output.WriteRawTag(82); + output.WriteString(MysqlType); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Index != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Index); + } + if (SqlType != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(SqlType); + } + if (Name.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Name); + } + if (IsKey != false) { + size += 1 + 1; + } + if (Updated != false) { + size += 1 + 1; + } + if (isNullPresentCase_ == IsNullPresentOneofCase.IsNull) { + size += 1 + 1; + } + size += props_.CalculateSize(_repeated_props_codec); + if (Value.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Value); + } + if (Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeInt32Size(Length); + } + if (MysqlType.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(MysqlType); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Column other) { + if (other == null) { + return; + } + if (other.Index != 0) { + Index = other.Index; + } + if (other.SqlType != 0) { + SqlType = other.SqlType; + } + if (other.Name.Length != 0) { + Name = other.Name; + } + if (other.IsKey != false) { + IsKey = other.IsKey; + } + if (other.Updated != false) { + Updated = other.Updated; + } + props_.Add(other.props_); + if (other.Value.Length != 0) { + Value = other.Value; + } + if (other.Length != 0) { + Length = other.Length; + } + if (other.MysqlType.Length != 0) { + MysqlType = other.MysqlType; + } + switch (other.IsNullPresentCase) { + case IsNullPresentOneofCase.IsNull: + IsNull = other.IsNull; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + Index = input.ReadInt32(); + break; + } + case 16: { + SqlType = input.ReadInt32(); + break; + } + case 26: { + Name = input.ReadString(); + break; + } + case 32: { + IsKey = input.ReadBool(); + break; + } + case 40: { + Updated = input.ReadBool(); + break; + } + case 48: { + IsNull = input.ReadBool(); + break; + } + case 58: { + props_.AddEntriesFrom(input, _repeated_props_codec); + break; + } + case 66: { + Value = input.ReadString(); + break; + } + case 72: { + Length = input.ReadInt32(); + break; + } + case 82: { + MysqlType = input.ReadString(); + break; + } } - public bool ShouldSerializetransactionId() => __pbn__transactionId != null; - public void ResettransactionId() => __pbn__transactionId = null; - private string __pbn__transactionId; - - [global::ProtoBuf.ProtoMember(3, Name = @"props")] - public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); - - [global::ProtoBuf.ProtoMember(4)] - public long threadId - { - get { return __pbn__threadId.GetValueOrDefault(); } - set { __pbn__threadId = value; } + } + } + + } + + public sealed partial class RowData : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new RowData()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.EntryProtocolReflection.Descriptor.MessageTypes[3]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public RowData() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public RowData(RowData other) : this() { + beforeColumns_ = other.beforeColumns_.Clone(); + afterColumns_ = other.afterColumns_.Clone(); + props_ = other.props_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public RowData Clone() { + return new RowData(this); + } + + /// Field number for the "beforeColumns" field. + public const int BeforeColumnsFieldNumber = 1; + private static readonly pb::FieldCodec _repeated_beforeColumns_codec + = pb::FieldCodec.ForMessage(10, global::Com.Alibaba.Otter.Canal.Protocol.Column.Parser); + private readonly pbc::RepeatedField beforeColumns_ = new pbc::RepeatedField(); + /// + ///* 字段信息,增量数据(修改前,删除前) * + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField BeforeColumns { + get { return beforeColumns_; } + } + + /// Field number for the "afterColumns" field. + public const int AfterColumnsFieldNumber = 2; + private static readonly pb::FieldCodec _repeated_afterColumns_codec + = pb::FieldCodec.ForMessage(18, global::Com.Alibaba.Otter.Canal.Protocol.Column.Parser); + private readonly pbc::RepeatedField afterColumns_ = new pbc::RepeatedField(); + /// + ///* 字段信息,增量数据(修改后,新增后) * + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField AfterColumns { + get { return afterColumns_; } + } + + /// Field number for the "props" field. + public const int PropsFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_props_codec + = pb::FieldCodec.ForMessage(26, global::Com.Alibaba.Otter.Canal.Protocol.Pair.Parser); + private readonly pbc::RepeatedField props_ = new pbc::RepeatedField(); + /// + ///*预留扩展* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Props { + get { return props_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as RowData); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(RowData other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if(!beforeColumns_.Equals(other.beforeColumns_)) return false; + if(!afterColumns_.Equals(other.afterColumns_)) return false; + if(!props_.Equals(other.props_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + hash ^= beforeColumns_.GetHashCode(); + hash ^= afterColumns_.GetHashCode(); + hash ^= props_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + beforeColumns_.WriteTo(output, _repeated_beforeColumns_codec); + afterColumns_.WriteTo(output, _repeated_afterColumns_codec); + props_.WriteTo(output, _repeated_props_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + size += beforeColumns_.CalculateSize(_repeated_beforeColumns_codec); + size += afterColumns_.CalculateSize(_repeated_afterColumns_codec); + size += props_.CalculateSize(_repeated_props_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(RowData other) { + if (other == null) { + return; + } + beforeColumns_.Add(other.beforeColumns_); + afterColumns_.Add(other.afterColumns_); + props_.Add(other.props_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + beforeColumns_.AddEntriesFrom(input, _repeated_beforeColumns_codec); + break; + } + case 18: { + afterColumns_.AddEntriesFrom(input, _repeated_afterColumns_codec); + break; + } + case 26: { + props_.AddEntriesFrom(input, _repeated_props_codec); + break; + } } - public bool ShouldSerializethreadId() => __pbn__threadId != null; - public void ResetthreadId() => __pbn__threadId = null; - private long? __pbn__threadId; + } + } + + } + + /// + ///*message row 每行变更数据的数据结构* + /// + public sealed partial class RowChange : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new RowChange()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.EntryProtocolReflection.Descriptor.MessageTypes[4]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public RowChange() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public RowChange(RowChange other) : this() { + tableId_ = other.tableId_; + sql_ = other.sql_; + rowDatas_ = other.rowDatas_.Clone(); + props_ = other.props_.Clone(); + ddlSchemaName_ = other.ddlSchemaName_; + switch (other.EventTypePresentCase) { + case EventTypePresentOneofCase.EventType: + EventType = other.EventType; + break; + } + + switch (other.IsDdlPresentCase) { + case IsDdlPresentOneofCase.IsDdl: + IsDdl = other.IsDdl; + break; + } + + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public RowChange Clone() { + return new RowChange(this); + } + + /// Field number for the "tableId" field. + public const int TableIdFieldNumber = 1; + private long tableId_; + /// + ///*tableId,由数据库产生* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long TableId { + get { return tableId_; } + set { + tableId_ = value; + } + } + + /// Field number for the "eventType" field. + public const int EventTypeFieldNumber = 2; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public global::Com.Alibaba.Otter.Canal.Protocol.EventType EventType { + get { return eventTypePresentCase_ == EventTypePresentOneofCase.EventType ? (global::Com.Alibaba.Otter.Canal.Protocol.EventType) eventTypePresent_ : 0; } + set { + eventTypePresent_ = value; + eventTypePresentCase_ = EventTypePresentOneofCase.EventType; + } + } + + /// Field number for the "isDdl" field. + public const int IsDdlFieldNumber = 10; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool IsDdl { + get { return isDdlPresentCase_ == IsDdlPresentOneofCase.IsDdl ? (bool) isDdlPresent_ : false; } + set { + isDdlPresent_ = value; + isDdlPresentCase_ = IsDdlPresentOneofCase.IsDdl; + } + } + /// Field number for the "sql" field. + public const int SqlFieldNumber = 11; + private string sql_ = ""; + /// + ///* ddl/query的sql语句 * + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Sql { + get { return sql_; } + set { + sql_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } } - [global::ProtoBuf.ProtoContract()] - public partial class TransactionEnd : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + /// Field number for the "rowDatas" field. + public const int RowDatasFieldNumber = 12; + private static readonly pb::FieldCodec _repeated_rowDatas_codec + = pb::FieldCodec.ForMessage(98, global::Com.Alibaba.Otter.Canal.Protocol.RowData.Parser); + private readonly pbc::RepeatedField rowDatas_ = new pbc::RepeatedField(); + /// + ///* 一次数据库变更可能存在多行 * + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField RowDatas { + get { return rowDatas_; } + } + + /// Field number for the "props" field. + public const int PropsFieldNumber = 13; + private static readonly pb::FieldCodec _repeated_props_codec + = pb::FieldCodec.ForMessage(106, global::Com.Alibaba.Otter.Canal.Protocol.Pair.Parser); + private readonly pbc::RepeatedField props_ = new pbc::RepeatedField(); + /// + ///*预留扩展* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Props { + get { return props_; } + } + + /// Field number for the "ddlSchemaName" field. + public const int DdlSchemaNameFieldNumber = 14; + private string ddlSchemaName_ = ""; + /// + ///* ddl/query的schemaName,会存在跨库ddl,需要保留执行ddl的当前schemaName * + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string DdlSchemaName { + get { return ddlSchemaName_; } + set { + ddlSchemaName_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + private object eventTypePresent_; + /// Enum of possible cases for the "eventType_present" oneof. + public enum EventTypePresentOneofCase { + None = 0, + EventType = 2, + } + private EventTypePresentOneofCase eventTypePresentCase_ = EventTypePresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public EventTypePresentOneofCase EventTypePresentCase { + get { return eventTypePresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearEventTypePresent() { + eventTypePresentCase_ = EventTypePresentOneofCase.None; + eventTypePresent_ = null; + } + + private object isDdlPresent_; + /// Enum of possible cases for the "isDdl_present" oneof. + public enum IsDdlPresentOneofCase { + None = 0, + IsDdl = 10, + } + private IsDdlPresentOneofCase isDdlPresentCase_ = IsDdlPresentOneofCase.None; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public IsDdlPresentOneofCase IsDdlPresentCase { + get { return isDdlPresentCase_; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void ClearIsDdlPresent() { + isDdlPresentCase_ = IsDdlPresentOneofCase.None; + isDdlPresent_ = null; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as RowChange); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(RowChange other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (TableId != other.TableId) return false; + if (EventType != other.EventType) return false; + if (IsDdl != other.IsDdl) return false; + if (Sql != other.Sql) return false; + if(!rowDatas_.Equals(other.rowDatas_)) return false; + if(!props_.Equals(other.props_)) return false; + if (DdlSchemaName != other.DdlSchemaName) return false; + if (EventTypePresentCase != other.EventTypePresentCase) return false; + if (IsDdlPresentCase != other.IsDdlPresentCase) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (TableId != 0L) hash ^= TableId.GetHashCode(); + if (eventTypePresentCase_ == EventTypePresentOneofCase.EventType) hash ^= EventType.GetHashCode(); + if (isDdlPresentCase_ == IsDdlPresentOneofCase.IsDdl) hash ^= IsDdl.GetHashCode(); + if (Sql.Length != 0) hash ^= Sql.GetHashCode(); + hash ^= rowDatas_.GetHashCode(); + hash ^= props_.GetHashCode(); + if (DdlSchemaName.Length != 0) hash ^= DdlSchemaName.GetHashCode(); + hash ^= (int) eventTypePresentCase_; + hash ^= (int) isDdlPresentCase_; + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (TableId != 0L) { + output.WriteRawTag(8); + output.WriteInt64(TableId); + } + if (eventTypePresentCase_ == EventTypePresentOneofCase.EventType) { + output.WriteRawTag(16); + output.WriteEnum((int) EventType); + } + if (isDdlPresentCase_ == IsDdlPresentOneofCase.IsDdl) { + output.WriteRawTag(80); + output.WriteBool(IsDdl); + } + if (Sql.Length != 0) { + output.WriteRawTag(90); + output.WriteString(Sql); + } + rowDatas_.WriteTo(output, _repeated_rowDatas_codec); + props_.WriteTo(output, _repeated_props_codec); + if (DdlSchemaName.Length != 0) { + output.WriteRawTag(114); + output.WriteString(DdlSchemaName); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } - [global::ProtoBuf.ProtoMember(1)] - public long executeTime - { - get { return __pbn__executeTime.GetValueOrDefault(); } - set { __pbn__executeTime = value; } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (TableId != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(TableId); + } + if (eventTypePresentCase_ == EventTypePresentOneofCase.EventType) { + size += 1 + pb::CodedOutputStream.ComputeEnumSize((int) EventType); + } + if (isDdlPresentCase_ == IsDdlPresentOneofCase.IsDdl) { + size += 1 + 1; + } + if (Sql.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Sql); + } + size += rowDatas_.CalculateSize(_repeated_rowDatas_codec); + size += props_.CalculateSize(_repeated_props_codec); + if (DdlSchemaName.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(DdlSchemaName); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(RowChange other) { + if (other == null) { + return; + } + if (other.TableId != 0L) { + TableId = other.TableId; + } + if (other.Sql.Length != 0) { + Sql = other.Sql; + } + rowDatas_.Add(other.rowDatas_); + props_.Add(other.props_); + if (other.DdlSchemaName.Length != 0) { + DdlSchemaName = other.DdlSchemaName; + } + switch (other.EventTypePresentCase) { + case EventTypePresentOneofCase.EventType: + EventType = other.EventType; + break; + } + + switch (other.IsDdlPresentCase) { + case IsDdlPresentOneofCase.IsDdl: + IsDdl = other.IsDdl; + break; + } + + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + TableId = input.ReadInt64(); + break; + } + case 16: { + eventTypePresent_ = input.ReadEnum(); + eventTypePresentCase_ = EventTypePresentOneofCase.EventType; + break; + } + case 80: { + IsDdl = input.ReadBool(); + break; + } + case 90: { + Sql = input.ReadString(); + break; + } + case 98: { + rowDatas_.AddEntriesFrom(input, _repeated_rowDatas_codec); + break; + } + case 106: { + props_.AddEntriesFrom(input, _repeated_props_codec); + break; + } + case 114: { + DdlSchemaName = input.ReadString(); + break; + } } - public bool ShouldSerializeexecuteTime() => __pbn__executeTime != null; - public void ResetexecuteTime() => __pbn__executeTime = null; - private long? __pbn__executeTime; - - [global::ProtoBuf.ProtoMember(2)] - [global::System.ComponentModel.DefaultValue("")] - public string transactionId - { - get { return __pbn__transactionId ?? ""; } - set { __pbn__transactionId = value; } + } + } + + } + + /// + ///*开始事务的一些信息* + /// + public sealed partial class TransactionBegin : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TransactionBegin()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.EntryProtocolReflection.Descriptor.MessageTypes[5]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public TransactionBegin() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public TransactionBegin(TransactionBegin other) : this() { + executeTime_ = other.executeTime_; + transactionId_ = other.transactionId_; + props_ = other.props_.Clone(); + threadId_ = other.threadId_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public TransactionBegin Clone() { + return new TransactionBegin(this); + } + + /// Field number for the "executeTime" field. + public const int ExecuteTimeFieldNumber = 1; + private long executeTime_; + /// + ///*已废弃,请使用header里的executeTime* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long ExecuteTime { + get { return executeTime_; } + set { + executeTime_ = value; + } + } + + /// Field number for the "transactionId" field. + public const int TransactionIdFieldNumber = 2; + private string transactionId_ = ""; + /// + ///*已废弃,Begin里不提供事务id* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string TransactionId { + get { return transactionId_; } + set { + transactionId_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "props" field. + public const int PropsFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_props_codec + = pb::FieldCodec.ForMessage(26, global::Com.Alibaba.Otter.Canal.Protocol.Pair.Parser); + private readonly pbc::RepeatedField props_ = new pbc::RepeatedField(); + /// + ///*预留扩展* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Props { + get { return props_; } + } + + /// Field number for the "threadId" field. + public const int ThreadIdFieldNumber = 4; + private long threadId_; + /// + ///*执行的thread Id* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long ThreadId { + get { return threadId_; } + set { + threadId_ = value; + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as TransactionBegin); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(TransactionBegin other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (ExecuteTime != other.ExecuteTime) return false; + if (TransactionId != other.TransactionId) return false; + if(!props_.Equals(other.props_)) return false; + if (ThreadId != other.ThreadId) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (ExecuteTime != 0L) hash ^= ExecuteTime.GetHashCode(); + if (TransactionId.Length != 0) hash ^= TransactionId.GetHashCode(); + hash ^= props_.GetHashCode(); + if (ThreadId != 0L) hash ^= ThreadId.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (ExecuteTime != 0L) { + output.WriteRawTag(8); + output.WriteInt64(ExecuteTime); + } + if (TransactionId.Length != 0) { + output.WriteRawTag(18); + output.WriteString(TransactionId); + } + props_.WriteTo(output, _repeated_props_codec); + if (ThreadId != 0L) { + output.WriteRawTag(32); + output.WriteInt64(ThreadId); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (ExecuteTime != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(ExecuteTime); + } + if (TransactionId.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(TransactionId); + } + size += props_.CalculateSize(_repeated_props_codec); + if (ThreadId != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(ThreadId); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(TransactionBegin other) { + if (other == null) { + return; + } + if (other.ExecuteTime != 0L) { + ExecuteTime = other.ExecuteTime; + } + if (other.TransactionId.Length != 0) { + TransactionId = other.TransactionId; + } + props_.Add(other.props_); + if (other.ThreadId != 0L) { + ThreadId = other.ThreadId; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + ExecuteTime = input.ReadInt64(); + break; + } + case 18: { + TransactionId = input.ReadString(); + break; + } + case 26: { + props_.AddEntriesFrom(input, _repeated_props_codec); + break; + } + case 32: { + ThreadId = input.ReadInt64(); + break; + } } - public bool ShouldSerializetransactionId() => __pbn__transactionId != null; - public void ResettransactionId() => __pbn__transactionId = null; - private string __pbn__transactionId; + } + } + + } + + /// + ///*结束事务的一些信息* + /// + public sealed partial class TransactionEnd : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new TransactionEnd()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.EntryProtocolReflection.Descriptor.MessageTypes[6]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public TransactionEnd() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public TransactionEnd(TransactionEnd other) : this() { + executeTime_ = other.executeTime_; + transactionId_ = other.transactionId_; + props_ = other.props_.Clone(); + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public TransactionEnd Clone() { + return new TransactionEnd(this); + } - [global::ProtoBuf.ProtoMember(3, Name = @"props")] - public global::System.Collections.Generic.List Props { get; } = new global::System.Collections.Generic.List(); + /// Field number for the "executeTime" field. + public const int ExecuteTimeFieldNumber = 1; + private long executeTime_; + /// + ///*已废弃,请使用header里的executeTime* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public long ExecuteTime { + get { return executeTime_; } + set { + executeTime_ = value; + } + } + + /// Field number for the "transactionId" field. + public const int TransactionIdFieldNumber = 2; + private string transactionId_ = ""; + /// + ///*事务号* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string TransactionId { + get { return transactionId_; } + set { + transactionId_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + /// Field number for the "props" field. + public const int PropsFieldNumber = 3; + private static readonly pb::FieldCodec _repeated_props_codec + = pb::FieldCodec.ForMessage(26, global::Com.Alibaba.Otter.Canal.Protocol.Pair.Parser); + private readonly pbc::RepeatedField props_ = new pbc::RepeatedField(); + /// + ///*预留扩展* + /// + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public pbc::RepeatedField Props { + get { return props_; } } - [global::ProtoBuf.ProtoContract()] - public partial class Pair : global::ProtoBuf.IExtensible - { - private global::ProtoBuf.IExtension __pbn__extensionData; - global::ProtoBuf.IExtension global::ProtoBuf.IExtensible.GetExtensionObject(bool createIfMissing) - => global::ProtoBuf.Extensible.GetExtensionObject(ref __pbn__extensionData, createIfMissing); + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as TransactionEnd); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(TransactionEnd other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (ExecuteTime != other.ExecuteTime) return false; + if (TransactionId != other.TransactionId) return false; + if(!props_.Equals(other.props_)) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (ExecuteTime != 0L) hash ^= ExecuteTime.GetHashCode(); + if (TransactionId.Length != 0) hash ^= TransactionId.GetHashCode(); + hash ^= props_.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } - [global::ProtoBuf.ProtoMember(1, Name = @"key")] - [global::System.ComponentModel.DefaultValue("")] - public string Key - { - get { return __pbn__Key ?? ""; } - set { __pbn__Key = value; } + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (ExecuteTime != 0L) { + output.WriteRawTag(8); + output.WriteInt64(ExecuteTime); + } + if (TransactionId.Length != 0) { + output.WriteRawTag(18); + output.WriteString(TransactionId); + } + props_.WriteTo(output, _repeated_props_codec); + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (ExecuteTime != 0L) { + size += 1 + pb::CodedOutputStream.ComputeInt64Size(ExecuteTime); + } + if (TransactionId.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(TransactionId); + } + size += props_.CalculateSize(_repeated_props_codec); + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(TransactionEnd other) { + if (other == null) { + return; + } + if (other.ExecuteTime != 0L) { + ExecuteTime = other.ExecuteTime; + } + if (other.TransactionId.Length != 0) { + TransactionId = other.TransactionId; + } + props_.Add(other.props_); + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 8: { + ExecuteTime = input.ReadInt64(); + break; + } + case 18: { + TransactionId = input.ReadString(); + break; + } + case 26: { + props_.AddEntriesFrom(input, _repeated_props_codec); + break; + } } - public bool ShouldSerializeKey() => __pbn__Key != null; - public void ResetKey() => __pbn__Key = null; - private string __pbn__Key; - - [global::ProtoBuf.ProtoMember(2, Name = @"value")] - [global::System.ComponentModel.DefaultValue("")] - public string Value - { - get { return __pbn__Value ?? ""; } - set { __pbn__Value = value; } + } + } + + } + + /// + ///*预留扩展* + /// + public sealed partial class Pair : pb::IMessage { + private static readonly pb::MessageParser _parser = new pb::MessageParser(() => new Pair()); + private pb::UnknownFieldSet _unknownFields; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pb::MessageParser Parser { get { return _parser; } } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public static pbr::MessageDescriptor Descriptor { + get { return global::Com.Alibaba.Otter.Canal.Protocol.EntryProtocolReflection.Descriptor.MessageTypes[7]; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + pbr::MessageDescriptor pb::IMessage.Descriptor { + get { return Descriptor; } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Pair() { + OnConstruction(); + } + + partial void OnConstruction(); + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Pair(Pair other) : this() { + key_ = other.key_; + value_ = other.value_; + _unknownFields = pb::UnknownFieldSet.Clone(other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public Pair Clone() { + return new Pair(this); + } + + /// Field number for the "key" field. + public const int KeyFieldNumber = 1; + private string key_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Key { + get { return key_; } + set { + key_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + /// Field number for the "value" field. + public const int ValueFieldNumber = 2; + private string value_ = ""; + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public string Value { + get { return value_; } + set { + value_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override bool Equals(object other) { + return Equals(other as Pair); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public bool Equals(Pair other) { + if (ReferenceEquals(other, null)) { + return false; + } + if (ReferenceEquals(other, this)) { + return true; + } + if (Key != other.Key) return false; + if (Value != other.Value) return false; + return Equals(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override int GetHashCode() { + int hash = 1; + if (Key.Length != 0) hash ^= Key.GetHashCode(); + if (Value.Length != 0) hash ^= Value.GetHashCode(); + if (_unknownFields != null) { + hash ^= _unknownFields.GetHashCode(); + } + return hash; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public override string ToString() { + return pb::JsonFormatter.ToDiagnosticString(this); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void WriteTo(pb::CodedOutputStream output) { + if (Key.Length != 0) { + output.WriteRawTag(10); + output.WriteString(Key); + } + if (Value.Length != 0) { + output.WriteRawTag(18); + output.WriteString(Value); + } + if (_unknownFields != null) { + _unknownFields.WriteTo(output); + } + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public int CalculateSize() { + int size = 0; + if (Key.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Key); + } + if (Value.Length != 0) { + size += 1 + pb::CodedOutputStream.ComputeStringSize(Value); + } + if (_unknownFields != null) { + size += _unknownFields.CalculateSize(); + } + return size; + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(Pair other) { + if (other == null) { + return; + } + if (other.Key.Length != 0) { + Key = other.Key; + } + if (other.Value.Length != 0) { + Value = other.Value; + } + _unknownFields = pb::UnknownFieldSet.MergeFrom(_unknownFields, other._unknownFields); + } + + [global::System.Diagnostics.DebuggerNonUserCodeAttribute] + public void MergeFrom(pb::CodedInputStream input) { + uint tag; + while ((tag = input.ReadTag()) != 0) { + switch(tag) { + default: + _unknownFields = pb::UnknownFieldSet.MergeFieldFrom(_unknownFields, input); + break; + case 10: { + Key = input.ReadString(); + break; + } + case 18: { + Value = input.ReadString(); + break; + } } - public bool ShouldSerializeValue() => __pbn__Value != null; - public void ResetValue() => __pbn__Value = null; - private string __pbn__Value; - - } - - [global::ProtoBuf.ProtoContract()] - public enum EntryType - { - [global::ProtoBuf.ProtoEnum(Name = @"TRANSACTIONBEGIN")] - Transactionbegin = 1, - [global::ProtoBuf.ProtoEnum(Name = @"ROWDATA")] - Rowdata = 2, - [global::ProtoBuf.ProtoEnum(Name = @"TRANSACTIONEND")] - Transactionend = 3, - [global::ProtoBuf.ProtoEnum(Name = @"HEARTBEAT")] - Heartbeat = 4, - [global::ProtoBuf.ProtoEnum(Name = @"GTIDLOG")] - Gtidlog = 5, - } - - [global::ProtoBuf.ProtoContract()] - public enum EventType - { - [global::ProtoBuf.ProtoEnum(Name = @"INSERT")] - Insert = 1, - [global::ProtoBuf.ProtoEnum(Name = @"UPDATE")] - Update = 2, - [global::ProtoBuf.ProtoEnum(Name = @"DELETE")] - Delete = 3, - [global::ProtoBuf.ProtoEnum(Name = @"CREATE")] - Create = 4, - [global::ProtoBuf.ProtoEnum(Name = @"ALTER")] - Alter = 5, - [global::ProtoBuf.ProtoEnum(Name = @"ERASE")] - Erase = 6, - [global::ProtoBuf.ProtoEnum(Name = @"QUERY")] - Query = 7, - [global::ProtoBuf.ProtoEnum(Name = @"TRUNCATE")] - Truncate = 8, - [global::ProtoBuf.ProtoEnum(Name = @"RENAME")] - Rename = 9, - [global::ProtoBuf.ProtoEnum(Name = @"CINDEX")] - Cindex = 10, - [global::ProtoBuf.ProtoEnum(Name = @"DINDEX")] - Dindex = 11, - [global::ProtoBuf.ProtoEnum(Name = @"GTID")] - Gtid = 12, - [global::ProtoBuf.ProtoEnum(Name = @"XACOMMIT")] - Xacommit = 13, - [global::ProtoBuf.ProtoEnum(Name = @"XAROLLBACK")] - Xarollback = 14, - [global::ProtoBuf.ProtoEnum(Name = @"MHEARTBEAT")] - Mheartbeat = 15, - } - - [global::ProtoBuf.ProtoContract()] - public enum Type - { - [global::ProtoBuf.ProtoEnum(Name = @"ORACLE")] - Oracle = 1, - [global::ProtoBuf.ProtoEnum(Name = @"MYSQL")] - Mysql = 2, - [global::ProtoBuf.ProtoEnum(Name = @"PGSQL")] - Pgsql = 3, + } } + } + + #endregion + } -#pragma warning restore CS0612, CS1591, CS3021, IDE1006, RCS1036, RCS1057, RCS1085, RCS1192 +#endregion Designer generated code diff --git a/src/Canal.Csharp.Protocol/EntryProtocol.proto b/src/Canal.Csharp.Protocol/EntryProtocol.proto index 5878ecf..01d29c5 100644 --- a/src/Canal.Csharp.Protocol/EntryProtocol.proto +++ b/src/Canal.Csharp.Protocol/EntryProtocol.proto @@ -1,4 +1,4 @@ -syntax = "proto2"; +syntax = "proto3"; package com.alibaba.otter.canal.protocol; option java_package = "com.alibaba.otter.canal.protocol"; @@ -11,88 +11,101 @@ option optimize_for = SPEED; ****************************************************************/ message Entry { /**协议头部信息**/ - optional Header header = 1; - - /**打散后的事件类型**/ - optional EntryType entryType = 2 [default = ROWDATA]; - + Header header = 1; + ///**打散后的事件类型**/ [default = ROWDATA] + oneof entryType_present{ + EntryType entryType = 2; + } + /**传输的二进制数组**/ - optional bytes storeValue = 3; + bytes storeValue = 3; } /**message Header**/ message Header { - /**协议的版本号**/ - optional int32 version = 1 [default = 1]; + /**协议的版本号**/ //[default = 1] + oneof version_present { + int32 version = 1; + } + /**binlog/redolog 文件名**/ - optional string logfileName = 2; + string logfileName = 2; /**binlog/redolog 文件的偏移位置**/ - optional int64 logfileOffset = 3; + int64 logfileOffset = 3; /**服务端serverId**/ - optional int64 serverId = 4; + int64 serverId = 4; /** 变更数据的编码 **/ - optional string serverenCode = 5; + string serverenCode = 5; /**变更数据的执行时间 **/ - optional int64 executeTime = 6; + int64 executeTime = 6; + + /** 变更数据的来源**/ //[default = MYSQL] + oneof sourceType_present { + Type sourceType = 7; + } - /** 变更数据的来源**/ - optional Type sourceType = 7 [default = MYSQL]; /** 变更数据的schemaname**/ - optional string schemaName = 8; + string schemaName = 8; /**变更数据的tablename**/ - optional string tableName = 9; + string tableName = 9; /**每个event的长度**/ - optional int64 eventLength = 10; + int64 eventLength = 10; + + /**数据变更类型**/ // [default = UPDATE] + oneof eventType_present { + EventType eventType = 11; + } - /**数据变更类型**/ - optional EventType eventType = 11 [default = UPDATE]; /**预留扩展**/ repeated Pair props = 12; /**当前事务的gitd**/ - optional string gtid = 13; + string gtid = 13; } /**每个字段的数据结构**/ message Column { /**字段下标**/ - optional int32 index = 1; + int32 index = 1; /**字段java中类型**/ - optional int32 sqlType = 2; + int32 sqlType = 2; /**字段名称(忽略大小写),在mysql中是没有的**/ - optional string name = 3; + string name = 3; /**是否是主键**/ - optional bool isKey = 4; + bool isKey = 4; /**如果EventType=UPDATE,用于标识这个字段值是否有修改**/ - optional bool updated = 5; + bool updated = 5; + + /** 标识是否为空 **/ //[default = false] + oneof isNull_present { + bool isNull = 6; + } - /** 标识是否为空 **/ - optional bool isNull = 6 [default = false]; /**预留扩展**/ repeated Pair props = 7; /** 字段值,timestamp,Datetime是一个时间格式的文本 **/ - optional string value = 8; + string value = 8; /** 对应数据对象原始长度 **/ - optional int32 length = 9; + int32 length = 9; /**字段mysql类型**/ - optional string mysqlType = 10; + string mysqlType = 10; } message RowData { @@ -111,16 +124,23 @@ message RowData { message RowChange { /**tableId,由数据库产生**/ - optional int64 tableId = 1; + int64 tableId = 1; + + + /**数据变更类型**/ //[default = UPDATE] + oneof eventType_present { + EventType eventType = 2; + } + - /**数据变更类型**/ - optional EventType eventType = 2 [default = UPDATE]; + /** 标识是否是ddl语句 **/ // [default = false] + oneof isDdl_present { + bool isDdl = 10; + } - /** 标识是否是ddl语句 **/ - optional bool isDdl = 10 [default = false]; /** ddl/query的sql语句 **/ - optional string sql = 11; + string sql = 11; /** 一次数据库变更可能存在多行 **/ repeated RowData rowDatas = 12; @@ -129,33 +149,33 @@ message RowChange { repeated Pair props = 13; /** ddl/query的schemaName,会存在跨库ddl,需要保留执行ddl的当前schemaName **/ - optional string ddlSchemaName = 14; + string ddlSchemaName = 14; } /**开始事务的一些信息**/ message TransactionBegin{ /**已废弃,请使用header里的executeTime**/ - optional int64 executeTime = 1; + int64 executeTime = 1; /**已废弃,Begin里不提供事务id**/ - optional string transactionId = 2; + string transactionId = 2; /**预留扩展**/ repeated Pair props = 3; /**执行的thread Id**/ - optional int64 threadId = 4; + int64 threadId = 4; } /**结束事务的一些信息**/ message TransactionEnd{ /**已废弃,请使用header里的executeTime**/ - optional int64 executeTime = 1; + int64 executeTime = 1; /**事务号**/ - optional string transactionId = 2; + string transactionId = 2; /**预留扩展**/ repeated Pair props = 3; @@ -163,12 +183,13 @@ message TransactionEnd{ /**预留扩展**/ message Pair{ - optional string key = 1; - optional string value = 2; + string key = 1; + string value = 2; } /**打散后的事件类型,主要用于标识事务的开始,变更数据,结束**/ enum EntryType{ + ENTRYTYPECOMPATIBLEPROTO2 = 0; TRANSACTIONBEGIN = 1; ROWDATA = 2; TRANSACTIONEND = 3; @@ -179,6 +200,7 @@ enum EntryType{ /** 事件类型 **/ enum EventType { + EVENTTYPECOMPATIBLEPROTO2 = 0; INSERT = 1; UPDATE = 2; DELETE = 3; @@ -201,6 +223,7 @@ enum EventType { /**数据库类型**/ enum Type { + TYPECOMPATIBLEPROTO2 = 0; ORACLE = 1; MYSQL = 2; PGSQL = 3; From 3770b0b167e211343b0757a51b3781bb9a7ecfb0 Mon Sep 17 00:00:00 2001 From: WithLin Date: Thu, 13 Sep 2018 19:50:43 +0800 Subject: [PATCH 07/50] fix add interface action --- .../Canal.Csharp.Abstract.csproj | 8 + .../Exception/CanalClientException.cs | 17 ++ src/Canal.Csharp.Abstract/ICanalConnector.cs | 154 ++++++++++++++++++ .../Canal.Csharp.Protocol.csproj | 2 +- src/Canal.Csharp.Protocol/Message.cs | 36 ++++ 5 files changed, 216 insertions(+), 1 deletion(-) create mode 100644 src/Canal.Csharp.Abstract/Exception/CanalClientException.cs create mode 100644 src/Canal.Csharp.Abstract/ICanalConnector.cs create mode 100644 src/Canal.Csharp.Protocol/Message.cs diff --git a/src/Canal.Csharp.Abstract/Canal.Csharp.Abstract.csproj b/src/Canal.Csharp.Abstract/Canal.Csharp.Abstract.csproj index a39e84e..e46a625 100644 --- a/src/Canal.Csharp.Abstract/Canal.Csharp.Abstract.csproj +++ b/src/Canal.Csharp.Abstract/Canal.Csharp.Abstract.csproj @@ -3,5 +3,13 @@ netstandard2.0 + + + + + + ..\..\..\..\..\.nuget\packages\microsoft.testplatform.testhost\15.7.0\lib\netstandard1.5\Microsoft.TestPlatform.CommunicationUtilities.dll + + diff --git a/src/Canal.Csharp.Abstract/Exception/CanalClientException.cs b/src/Canal.Csharp.Abstract/Exception/CanalClientException.cs new file mode 100644 index 0000000..b52922d --- /dev/null +++ b/src/Canal.Csharp.Abstract/Exception/CanalClientException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Canal.Csharp.Abstract.Exception +{ + public class CanalClientException:System.Exception + { + public CanalClientException(string errorCode):base(errorCode) + { + } + + public CanalClientException(string errorCode, System.Exception cause):base(errorCode,cause) + { + } + } +} diff --git a/src/Canal.Csharp.Abstract/ICanalConnector.cs b/src/Canal.Csharp.Abstract/ICanalConnector.cs new file mode 100644 index 0000000..6bbf445 --- /dev/null +++ b/src/Canal.Csharp.Abstract/ICanalConnector.cs @@ -0,0 +1,154 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Canal.Csharp.Abstract.Exception; +using Canal.Csharp.Protocol; + +namespace Canal.Csharp.Abstract +{ + public interface ICanalConnector + { + /** + * 链接对应的canal server + * + * @throws CanalClientException + */ + void Connect(); + + /** + * 释放链接 + * + * @throws CanalClientException + */ + void Disconnect(); + + /** + * 检查下链接是否合法 + * + *
+         * 几种case下链接不合法:
+         * 1. 链接canal server失败,一直没有一个可用的链接,返回false
+         * 2. 当前客户端在进行running抢占的时候,做为备份节点存在,非处于工作节点,返回false
+         * 
+         * 说明:
+         * a. 当前客户端一旦做为备份节点存在,当前所有的对{@linkplain CanalConnector}的操作都会处于阻塞状态,直到转为工作节点
+         * b. 所以业务方最好定时调用checkValid()方法用,比如调用CanalConnector所在线程的interrupt,直接退出CanalConnector,并根据自己的需要退出自己的资源
+         * 
+ * + * @throws CanalClientException + */ + bool CheckValid(); + + /** + * 客户端订阅,重复订阅时会更新对应的filter信息 + * + *
+         * 说明:
+         * a. 如果本次订阅中filter信息为空,则直接使用canal server服务端配置的filter信息
+         * b. 如果本次订阅中filter信息不为空,目前会直接替换canal server服务端配置的filter信息,以本次提交的为准
+         * 
+         * TODO: 后续可以考虑,如果本次提交的filter不为空,在执行过滤时,是对canal server filter + 本次filter的交集处理,达到只取1份binlog数据,多个客户端消费不同的表
+         * 
+ * + * @throws CanalClientException + */ + void Subscribe(string filter); + + /** + * 客户端订阅,不提交客户端filter,以服务端的filter为准 + * + * @throws CanalClientException + */ + void Subscribe(); + + /** + * 取消订阅 + * + * @throws CanalClientException + */ + void UnSubscribe(); + + /** + * 获取数据,自动进行确认,该方法返回的条件:尝试拿batchSize条记录,有多少取多少,不会阻塞等待 + * + * @param batchSize + * @return + * @throws CanalClientException + */ + Message Get(int batchSize); + + /** + * 获取数据,自动进行确认 + * + *
+         * 该方法返回的条件:
+         *  a. 拿够batchSize条记录或者超过timeout时间
+         *  b. 如果timeout=0,则阻塞至拿到batchSize记录才返回
+         * 
+ * + * @param batchSize + * @return + * @throws CanalClientException + */ + Message Get(int batchSize, long timeout, TimeSpan unit); + + /** + * 不指定 position 获取事件,该方法返回的条件: 尝试拿batchSize条记录,有多少取多少,不会阻塞等待
+ * canal 会记住此 client 最新的position。
+ * 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 + * + * @param batchSize + * @throws CanalClientException + */ + Message GetWithoutAck(int batchSize); + + /** + * 不指定 position 获取事件. + * + *
+         * 该方法返回的条件:
+         *  a. 拿够batchSize条记录或者超过timeout时间
+         *  b. 如果timeout=0,则阻塞至拿到batchSize记录才返回
+         * 
+ * + * canal 会记住此 client 最新的position。
+ * 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 + * + * @param batchSize + * @param timeout + * @param unit + * @return + * @throws CanalClientException + */ + Message GetWithoutAck(int batchSize, long timeout, TimeSpan unit); + + /** + * 进行 batch id 的确认。确认之后,小于等于此 batchId 的 Message 都会被确认。 + * + * @param batchId + * @throws CanalClientException + */ + void Ack(long batchId); + + /** + * 回滚到未进行 {@link #ack} 的地方,指定回滚具体的batchId + * + * @throws CanalClientException + */ + void Rollback(long batchId); + + /** + * 回滚到未进行 {@link #ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link #ack} 的地方开始拿 + * + * @throws CanalClientException + */ + void Rollback(); + + /** + * 中断的阻塞,用于优雅停止client + * + * @throws CanalClientException + */ + void StopRunning(); + } +} diff --git a/src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj b/src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj index 049115e..34f7c5c 100644 --- a/src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj +++ b/src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj @@ -5,7 +5,7 @@ - + diff --git a/src/Canal.Csharp.Protocol/Message.cs b/src/Canal.Csharp.Protocol/Message.cs new file mode 100644 index 0000000..93e256e --- /dev/null +++ b/src/Canal.Csharp.Protocol/Message.cs @@ -0,0 +1,36 @@ +using System.Collections.Generic; +using Com.Alibaba.Otter.Canal.Protocol; +using Google.Protobuf; + +namespace Canal.Csharp.Protocol +{ + + public class Message + { + public long Id { get; set; } + public List Entries { get; set; } + + public bool Raw { get; set; } + + public List RawEntries = new List(); + + public Message(long id, List entries) + { + Id = id; + Entries = entries ?? new List(); + Raw = false; + } + public Message(long id, bool raw, object entries) + { + Id = id; + if (raw) + { + RawEntries = (List) (entries ?? new List()); + } + else + { + Entries = (List) (entries ?? new List()); + } + } + } +} From ceb892059a9a78727b0408daa93e8f56dcd47eac Mon Sep 17 00:00:00 2001 From: WithLin Date: Fri, 14 Sep 2018 11:21:01 +0800 Subject: [PATCH 08/50] add position module --- .../Exception/CanalClientException.cs | 17 --- src/Canal.Csharp.Protocol/ClientIdentity.cs | 77 +++++++++++ .../Exception/CanalClientException.cs | 17 +++ src/Canal.Csharp.Protocol/Message.cs | 5 +- .../Position/EntryPosition.cs | 126 ++++++++++++++++++ .../Position/LogIdentity.cs | 54 ++++++++ .../Position/LogPosition.cs | 65 +++++++++ .../Position/MetaqPosition.cs | 20 +++ .../Position/Position.cs | 15 +++ .../Position/PositionRange.cs | 85 ++++++++++++ .../Position/TimePosition.cs | 52 ++++++++ 11 files changed, 514 insertions(+), 19 deletions(-) delete mode 100644 src/Canal.Csharp.Abstract/Exception/CanalClientException.cs create mode 100644 src/Canal.Csharp.Protocol/ClientIdentity.cs create mode 100644 src/Canal.Csharp.Protocol/Exception/CanalClientException.cs create mode 100644 src/Canal.Csharp.Protocol/Position/EntryPosition.cs create mode 100644 src/Canal.Csharp.Protocol/Position/LogIdentity.cs create mode 100644 src/Canal.Csharp.Protocol/Position/LogPosition.cs create mode 100644 src/Canal.Csharp.Protocol/Position/MetaqPosition.cs create mode 100644 src/Canal.Csharp.Protocol/Position/Position.cs create mode 100644 src/Canal.Csharp.Protocol/Position/PositionRange.cs create mode 100644 src/Canal.Csharp.Protocol/Position/TimePosition.cs diff --git a/src/Canal.Csharp.Abstract/Exception/CanalClientException.cs b/src/Canal.Csharp.Abstract/Exception/CanalClientException.cs deleted file mode 100644 index b52922d..0000000 --- a/src/Canal.Csharp.Abstract/Exception/CanalClientException.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Canal.Csharp.Abstract.Exception -{ - public class CanalClientException:System.Exception - { - public CanalClientException(string errorCode):base(errorCode) - { - } - - public CanalClientException(string errorCode, System.Exception cause):base(errorCode,cause) - { - } - } -} diff --git a/src/Canal.Csharp.Protocol/ClientIdentity.cs b/src/Canal.Csharp.Protocol/ClientIdentity.cs new file mode 100644 index 0000000..00c736c --- /dev/null +++ b/src/Canal.Csharp.Protocol/ClientIdentity.cs @@ -0,0 +1,77 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Canal.Csharp.Protocol +{ + [Serializable] + public class ClientIdentity + { + public string Destination { get; set; } + public short ClientId { get; set; } + public string Filter { get; set; } + + public ClientIdentity() + { + + } + + public ClientIdentity(string destination,short clientId) + { + Destination = destination; + ClientId = clientId; + } + public ClientIdentity(string destination, short clientId,string filter) + { + Destination = destination; + ClientId = clientId; + Filter = filter; + } + + public bool HasFilter() + { + return Filter != null && string.IsNullOrEmpty(Filter); + } + + public override int GetHashCode() + { + const int prime = 31; + var result = 1; + result = prime * result + ClientId; + result = prime * result + ((Destination == null) ? 0 : Destination.GetHashCode()); + return result; + } + + public override bool Equals(object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (!(obj is ClientIdentity)) { + return false; + } + var other = (ClientIdentity)obj; + if (ClientId != other.ClientId) + { + return false; + } + if (Destination == null) + { + if (other.Destination != null) + { + return false; + } + } + else if (!Destination.Equals(other.Destination)) + { + return false; + } + return true; + } + } +} diff --git a/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs b/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs new file mode 100644 index 0000000..33d725d --- /dev/null +++ b/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Canal.Csharp.Protocol.Exception +{ + public class CanalClientException : System.Exception + { + public CanalClientException(string errorCode) : base(errorCode) + { + } + + public CanalClientException(string errorCode, System.Exception cause) : base(errorCode, cause) + { + } + } +} diff --git a/src/Canal.Csharp.Protocol/Message.cs b/src/Canal.Csharp.Protocol/Message.cs index 93e256e..4255861 100644 --- a/src/Canal.Csharp.Protocol/Message.cs +++ b/src/Canal.Csharp.Protocol/Message.cs @@ -1,10 +1,11 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using Com.Alibaba.Otter.Canal.Protocol; using Google.Protobuf; namespace Canal.Csharp.Protocol { - + [Serializable] public class Message { public long Id { get; set; } diff --git a/src/Canal.Csharp.Protocol/Position/EntryPosition.cs b/src/Canal.Csharp.Protocol/Position/EntryPosition.cs new file mode 100644 index 0000000..661a926 --- /dev/null +++ b/src/Canal.Csharp.Protocol/Position/EntryPosition.cs @@ -0,0 +1,126 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Canal.Csharp.Protocol.Position +{ + public class EntryPosition:TimePosition + { + public static int EVENTIDENTITY_SEGMENT = 3; + public static char EVENTIDENTITY_SPLIT = (char)5; + + public bool Included => false; + + public string JournalName { get; set; } + public long? Position { get; set; } + + //// 记录一下位点对应的serverId + public long? ServerId { get; set; } + + public string Gtid = null; + + + public EntryPosition() : base(null) + { + + } + + public EntryPosition(long? timestamp):this(null,null,timestamp) + { + } + + public EntryPosition(string journalName, long? position):this(journalName,position,null) + { + } + + public EntryPosition(string journalName, long? position, long? timestamp):base(timestamp) + { + JournalName = journalName; + Position = position; + } + + public EntryPosition(string journalName, long position, long timestamp, long? serverId):this(journalName, position, timestamp) + { + ServerId = serverId; + } + + public override int GetHashCode() + { + const int prime = 31; + var result = base.GetHashCode(); + result = prime * result + ((JournalName == null) ? 0 : JournalName.GetHashCode()); + result = prime * result + ((Position == null) ? 0 : Position.GetHashCode()); + // 手写equals,自动生成时需注意 + result = prime * result + ((Timestamp == null) ? 0 : Timestamp.GetHashCode()); + return result; + } + + public override bool Equals(object obj) + { + if (this == obj) + { + return true; + } + if (!base.Equals(obj)) + { + return false; + } + if (!(obj is EntryPosition)) { + return false; + } + var other = (EntryPosition)obj; + if (JournalName == null) + { + if (other.JournalName != null) + { + return false; + } + } + else if (!JournalName.Equals(other.JournalName)) + { + return false; + } + if (Position == null) + { + if (other.Position != null) + { + return false; + } + } + else if (!Position.Equals(other.Position)) + { + return false; + } + // 手写equals,自动生成时需注意 + if (Timestamp == null) + { + if (other.Timestamp != null) + { + return false; + } + } + else if (!Timestamp.Equals(other.Timestamp)) + { + return false; + } + return true; + } + + /** + * {@inheritDoc} + * + * @see java.lang.Comparable#compareTo(java.lang.Object) + */ + public int CompareTo(EntryPosition o) + { + var val = string.Compare(JournalName, o.JournalName, StringComparison.Ordinal); + + if (val != 0) return val; + if (Position != null) + { + return (int) (Position - o.Position); + } + return val; + } + } +} diff --git a/src/Canal.Csharp.Protocol/Position/LogIdentity.cs b/src/Canal.Csharp.Protocol/Position/LogIdentity.cs new file mode 100644 index 0000000..db8b646 --- /dev/null +++ b/src/Canal.Csharp.Protocol/Position/LogIdentity.cs @@ -0,0 +1,54 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Text; + +namespace Canal.Csharp.Protocol.Position +{ + public class LogIdentity:Position + { + // 链接服务器的地址 + public IPAddress SourceAddress { get; set; } + // 对应的slaveId + public long? SlaveId { get; set; } + + public LogIdentity() + { + + } + + public LogIdentity(IPAddress sourceAddress,long slaveId) + { + SourceAddress = sourceAddress; + SlaveId = slaveId; + } + + public override int GetHashCode() + { + const int prime = 31; + var result = 1; + result = prime * result + ((SlaveId == null) ? 0 : SlaveId.GetHashCode()); + result = prime * result + ((SourceAddress == null) ? 0 : SourceAddress.GetHashCode()); + return result; + } + + public override bool Equals(object obj) + { + if (this == obj) return true; + if (obj == null) return false; + if (this != obj) return false; + var other = (LogIdentity)obj; + if (SlaveId == null) + { + if (other.SlaveId != null) return false; + } + else if (SlaveId != (other.SlaveId)) return false; + if (SourceAddress == null) + { + if (other.SourceAddress != null) return false; + } + else if (!SourceAddress.Equals(other.SourceAddress)) return false; + return true; + } + } +} diff --git a/src/Canal.Csharp.Protocol/Position/LogPosition.cs b/src/Canal.Csharp.Protocol/Position/LogPosition.cs new file mode 100644 index 0000000..2b573d7 --- /dev/null +++ b/src/Canal.Csharp.Protocol/Position/LogPosition.cs @@ -0,0 +1,65 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Canal.Csharp.Protocol.Position +{ + public class LogPosition: Position + { + public LogIdentity Identity { get; set; } + private EntryPosition Postion { get; set; } + + public override int GetHashCode() + { + const int prime = 31; + var result = 1; + result = prime * result + ((Identity == null) ? 0 : Identity.GetHashCode()); + result = prime * result + ((Postion == null) ? 0 : Postion.GetHashCode()); + return result; + } + + public override bool Equals(object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (!(obj is LogPosition)) { + return false; + } + var other = (LogPosition)obj; + if (Identity == null) + { + if (other.Identity != null) + { + return false; + } + } + else if (!Identity.Equals(other.Identity)) + { + return false; + } + if (Postion == null) + { + if (other.Postion != null) + { + return false; + } + } + else if (!Postion.Equals(other.Postion)) + { + return false; + } + return true; + } + + public boolean equals(Object obj) + { + + } + } +} diff --git a/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs b/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs new file mode 100644 index 0000000..8c4369d --- /dev/null +++ b/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Canal.Csharp.Protocol.Position +{ + public class MetaqPosition:Position + { + public string Topic { get; set; } + public string MsgNewId { get; set; } + public long Offset { get; set; } + + public MetaqPosition(string topic, string msgNewId, long offset) + { + Topic = topic; + MsgNewId = msgNewId; + Offset = offset; + } + } +} diff --git a/src/Canal.Csharp.Protocol/Position/Position.cs b/src/Canal.Csharp.Protocol/Position/Position.cs new file mode 100644 index 0000000..6cb8dac --- /dev/null +++ b/src/Canal.Csharp.Protocol/Position/Position.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Canal.Csharp.Protocol.Position +{ + /** + * 事件唯一标示 + */ + [Serializable] + public abstract class Position + { + + } +} diff --git a/src/Canal.Csharp.Protocol/Position/PositionRange.cs b/src/Canal.Csharp.Protocol/Position/PositionRange.cs new file mode 100644 index 0000000..7e948d2 --- /dev/null +++ b/src/Canal.Csharp.Protocol/Position/PositionRange.cs @@ -0,0 +1,85 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Canal.Csharp.Protocol.Position +{ + [Serializable] + public class PositionRange where T:Position + { + public T Start { get; set; } + // add by ljh at 2012-09-05,用于记录一个可被ack的位置,保证每次提交到cursor中的位置是一个完整事务的结束 + public T Ack { get; set; } + public T End { get; set; } + + public PositionRange() + { + } + + public PositionRange(T start, T end) + { + Start = start; + End = end; + } + + public override int GetHashCode() + { + const int prime = 31; + var result = 1; + result = prime * result + ((Ack == null) ? 0 : Ack.GetHashCode()); + result = prime * result + ((End == null) ? 0 : End.GetHashCode()); + result = prime * result + ((Start == null) ? 0 : Start.GetHashCode()); + return result; + } + + public override bool Equals(object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (!(obj is PositionRange)) { + return false; + } + var other = (PositionRange)obj; + if (Ack == null) + { + if (other.Ack != null) + { + return false; + } + } + else if (!Ack.Equals(other.Ack)) + { + return false; + } + if (End == null) + { + if (other.End != null) + { + return false; + } + } + else if (!End.Equals(other.End)) + { + return false; + } + if (Start == null) + { + if (other.Start != null) + { + return false; + } + } + else if (!Start.Equals(other.Start)) + { + return false; + } + return true; + } + } +} diff --git a/src/Canal.Csharp.Protocol/Position/TimePosition.cs b/src/Canal.Csharp.Protocol/Position/TimePosition.cs new file mode 100644 index 0000000..c5940bc --- /dev/null +++ b/src/Canal.Csharp.Protocol/Position/TimePosition.cs @@ -0,0 +1,52 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace Canal.Csharp.Protocol.Position +{ + public class TimePosition: Position + { + protected long? Timestamp { get; set; } + + public TimePosition(long? timestamp) + { + Timestamp = timestamp; + } + + public override int GetHashCode() + { + const int prime = 31; + var result = 1; + result = prime * result + ((Timestamp == null) ? 0 : Timestamp.GetHashCode()); + return result; + } + + public override bool Equals(object obj) + { + if (this == obj) + { + return true; + } + if (obj == null) + { + return false; + } + if (!(obj is TimePosition)) { + return false; + } + var other = (TimePosition)obj; + if (Timestamp == null) + { + if (other.Timestamp != null) + { + return false; + } + } + else if (!Timestamp.Equals(other.Timestamp)) + { + return false; + } + return true; + } + } +} From 2663a123d9e4fdd7b0d325c6e7e37023f2666b12 Mon Sep 17 00:00:00 2001 From: WithLin Date: Fri, 14 Sep 2018 11:23:19 +0800 Subject: [PATCH 09/50] fix code style --- src/Canal.Csharp.Abstract/ICanalConnector.cs | 3 --- .../Exception/CanalClientException.cs | 6 +----- src/Canal.Csharp.Protocol/Position/EntryPosition.cs | 2 -- src/Canal.Csharp.Protocol/Position/LogIdentity.cs | 5 +---- src/Canal.Csharp.Protocol/Position/LogPosition.cs | 11 +---------- src/Canal.Csharp.Protocol/Position/MetaqPosition.cs | 6 +----- src/Canal.Csharp.Protocol/Position/Position.cs | 2 -- src/Canal.Csharp.Protocol/Position/PositionRange.cs | 2 -- src/Canal.Csharp.Protocol/Position/TimePosition.cs | 6 +----- 9 files changed, 5 insertions(+), 38 deletions(-) diff --git a/src/Canal.Csharp.Abstract/ICanalConnector.cs b/src/Canal.Csharp.Abstract/ICanalConnector.cs index 6bbf445..e8b0da6 100644 --- a/src/Canal.Csharp.Abstract/ICanalConnector.cs +++ b/src/Canal.Csharp.Abstract/ICanalConnector.cs @@ -1,7 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; -using Canal.Csharp.Abstract.Exception; using Canal.Csharp.Protocol; namespace Canal.Csharp.Abstract diff --git a/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs b/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs index 33d725d..d4224e5 100644 --- a/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs +++ b/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Canal.Csharp.Protocol.Exception +namespace Canal.Csharp.Protocol.Exception { public class CanalClientException : System.Exception { diff --git a/src/Canal.Csharp.Protocol/Position/EntryPosition.cs b/src/Canal.Csharp.Protocol/Position/EntryPosition.cs index 661a926..2d3b366 100644 --- a/src/Canal.Csharp.Protocol/Position/EntryPosition.cs +++ b/src/Canal.Csharp.Protocol/Position/EntryPosition.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Canal.Csharp.Protocol.Position { diff --git a/src/Canal.Csharp.Protocol/Position/LogIdentity.cs b/src/Canal.Csharp.Protocol/Position/LogIdentity.cs index db8b646..b5b75cc 100644 --- a/src/Canal.Csharp.Protocol/Position/LogIdentity.cs +++ b/src/Canal.Csharp.Protocol/Position/LogIdentity.cs @@ -1,7 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Text; +using System.Net; namespace Canal.Csharp.Protocol.Position { diff --git a/src/Canal.Csharp.Protocol/Position/LogPosition.cs b/src/Canal.Csharp.Protocol/Position/LogPosition.cs index 2b573d7..0ba87f4 100644 --- a/src/Canal.Csharp.Protocol/Position/LogPosition.cs +++ b/src/Canal.Csharp.Protocol/Position/LogPosition.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Canal.Csharp.Protocol.Position +namespace Canal.Csharp.Protocol.Position { public class LogPosition: Position { @@ -56,10 +52,5 @@ public override bool Equals(object obj) } return true; } - - public boolean equals(Object obj) - { - - } } } diff --git a/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs b/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs index 8c4369d..a37ef32 100644 --- a/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs +++ b/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Canal.Csharp.Protocol.Position +namespace Canal.Csharp.Protocol.Position { public class MetaqPosition:Position { diff --git a/src/Canal.Csharp.Protocol/Position/Position.cs b/src/Canal.Csharp.Protocol/Position/Position.cs index 6cb8dac..c7ddb9b 100644 --- a/src/Canal.Csharp.Protocol/Position/Position.cs +++ b/src/Canal.Csharp.Protocol/Position/Position.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Canal.Csharp.Protocol.Position { diff --git a/src/Canal.Csharp.Protocol/Position/PositionRange.cs b/src/Canal.Csharp.Protocol/Position/PositionRange.cs index 7e948d2..315709f 100644 --- a/src/Canal.Csharp.Protocol/Position/PositionRange.cs +++ b/src/Canal.Csharp.Protocol/Position/PositionRange.cs @@ -1,6 +1,4 @@ using System; -using System.Collections.Generic; -using System.Text; namespace Canal.Csharp.Protocol.Position { diff --git a/src/Canal.Csharp.Protocol/Position/TimePosition.cs b/src/Canal.Csharp.Protocol/Position/TimePosition.cs index c5940bc..c263525 100644 --- a/src/Canal.Csharp.Protocol/Position/TimePosition.cs +++ b/src/Canal.Csharp.Protocol/Position/TimePosition.cs @@ -1,8 +1,4 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace Canal.Csharp.Protocol.Position +namespace Canal.Csharp.Protocol.Position { public class TimePosition: Position { From 93f184df52643365c11f9359eb7056d5c44b9354 Mon Sep 17 00:00:00 2001 From: WithLin Date: Fri, 14 Sep 2018 11:26:10 +0800 Subject: [PATCH 10/50] Fix socket of type bug --- .../ICanalNodeAccessStrategy.cs | 14 ++++++++++++++ src/Canal.Csharp.Protocol/Position/LogIdentity.cs | 4 ++-- 2 files changed, 16 insertions(+), 2 deletions(-) create mode 100644 src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs diff --git a/src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs b/src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs new file mode 100644 index 0000000..fdbc488 --- /dev/null +++ b/src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Text; + +namespace Canal.Csharp.Abstract +{ + public interface ICanalNodeAccessStrategy + { + SocketAddress CurrentNode(); + + SocketAddress NextNode(); + } +} diff --git a/src/Canal.Csharp.Protocol/Position/LogIdentity.cs b/src/Canal.Csharp.Protocol/Position/LogIdentity.cs index b5b75cc..78ece65 100644 --- a/src/Canal.Csharp.Protocol/Position/LogIdentity.cs +++ b/src/Canal.Csharp.Protocol/Position/LogIdentity.cs @@ -5,7 +5,7 @@ namespace Canal.Csharp.Protocol.Position public class LogIdentity:Position { // 链接服务器的地址 - public IPAddress SourceAddress { get; set; } + public SocketAddress SourceAddress { get; set; } // 对应的slaveId public long? SlaveId { get; set; } @@ -14,7 +14,7 @@ public LogIdentity() } - public LogIdentity(IPAddress sourceAddress,long slaveId) + public LogIdentity(SocketAddress sourceAddress,long slaveId) { SourceAddress = sourceAddress; SlaveId = slaveId; From 3b0f50078b26c47a9233c89dae79e00efc0d1f7a Mon Sep 17 00:00:00 2001 From: stulzq Date: Fri, 14 Sep 2018 21:18:19 +0800 Subject: [PATCH 11/50] change project name Canal.Csharp->CanalSharp --- canal-client-csharp.sln => CanalSharp.sln | 0 .../{Canal.Csharp.Abstract.csproj => CanalSharp.Abstract.csproj} | 0 .../{Canal.Csharp.Core.csproj => CanalSharp.Core.csproj} | 0 .../{Canal.Csharp.Protocol.csproj => CanalSharp.Protocol.csproj} | 0 .../{Canal4Net.UnitTests.csproj => CanalSharp.UnitTests.csproj} | 0 5 files changed, 0 insertions(+), 0 deletions(-) rename canal-client-csharp.sln => CanalSharp.sln (100%) rename src/Canal.Csharp.Abstract/{Canal.Csharp.Abstract.csproj => CanalSharp.Abstract.csproj} (100%) rename src/Canal.Csharp.Core/{Canal.Csharp.Core.csproj => CanalSharp.Core.csproj} (100%) rename src/Canal.Csharp.Protocol/{Canal.Csharp.Protocol.csproj => CanalSharp.Protocol.csproj} (100%) rename test/Canal4Net.UnitTests/{Canal4Net.UnitTests.csproj => CanalSharp.UnitTests.csproj} (100%) diff --git a/canal-client-csharp.sln b/CanalSharp.sln similarity index 100% rename from canal-client-csharp.sln rename to CanalSharp.sln diff --git a/src/Canal.Csharp.Abstract/Canal.Csharp.Abstract.csproj b/src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj similarity index 100% rename from src/Canal.Csharp.Abstract/Canal.Csharp.Abstract.csproj rename to src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj diff --git a/src/Canal.Csharp.Core/Canal.Csharp.Core.csproj b/src/Canal.Csharp.Core/CanalSharp.Core.csproj similarity index 100% rename from src/Canal.Csharp.Core/Canal.Csharp.Core.csproj rename to src/Canal.Csharp.Core/CanalSharp.Core.csproj diff --git a/src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj b/src/Canal.Csharp.Protocol/CanalSharp.Protocol.csproj similarity index 100% rename from src/Canal.Csharp.Protocol/Canal.Csharp.Protocol.csproj rename to src/Canal.Csharp.Protocol/CanalSharp.Protocol.csproj diff --git a/test/Canal4Net.UnitTests/Canal4Net.UnitTests.csproj b/test/Canal4Net.UnitTests/CanalSharp.UnitTests.csproj similarity index 100% rename from test/Canal4Net.UnitTests/Canal4Net.UnitTests.csproj rename to test/Canal4Net.UnitTests/CanalSharp.UnitTests.csproj From d23778d7df0d3b851bcc684a34d2789f8d3aa282 Mon Sep 17 00:00:00 2001 From: stulzq Date: Fri, 14 Sep 2018 21:20:54 +0800 Subject: [PATCH 12/50] change namespace Canal.Csharp->CanalSharp --- CanalSharp.sln | 8 ++++---- src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj | 2 +- src/Canal.Csharp.Abstract/ICanalConnector.cs | 4 ++-- src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs | 2 +- .../Exception/CanalClientException.cs | 2 +- src/Canal.Csharp.Protocol/Position/EntryPosition.cs | 2 +- src/Canal.Csharp.Protocol/Position/LogIdentity.cs | 2 +- src/Canal.Csharp.Protocol/Position/LogPosition.cs | 2 +- src/Canal.Csharp.Protocol/Position/MetaqPosition.cs | 2 +- src/Canal.Csharp.Protocol/Position/Position.cs | 2 +- src/Canal.Csharp.Protocol/Position/PositionRange.cs | 2 +- src/Canal.Csharp.Protocol/Position/TimePosition.cs | 2 +- 12 files changed, 16 insertions(+), 16 deletions(-) diff --git a/CanalSharp.sln b/CanalSharp.sln index 6c97223..505ba4d 100644 --- a/CanalSharp.sln +++ b/CanalSharp.sln @@ -16,13 +16,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{BD70CDB7-9 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal4Net.UnitTests", "test\Canal4Net.UnitTests\Canal4Net.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.UnitTests", "test\Canal4Net.UnitTests\CanalSharp.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal.Csharp.Abstract", "src\Canal.Csharp.Abstract\Canal.Csharp.Abstract.csproj", "{C61A468E-66C4-4915-9C2C-91936EB99F2A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Abstract", "src\Canal.Csharp.Abstract\CanalSharp.Abstract.csproj", "{C61A468E-66C4-4915-9C2C-91936EB99F2A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal.Csharp.Core", "src\Canal.Csharp.Core\Canal.Csharp.Core.csproj", "{E33BCF38-D450-4AFE-B409-E6E7C0251479}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Core", "src\Canal.Csharp.Core\CanalSharp.Core.csproj", "{E33BCF38-D450-4AFE-B409-E6E7C0251479}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Canal.Csharp.Protocol", "src\Canal.Csharp.Protocol\Canal.Csharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Protocol", "src\Canal.Csharp.Protocol\CanalSharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj b/src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj index e46a625..f47bd05 100644 --- a/src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj +++ b/src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj @@ -4,7 +4,7 @@ netstandard2.0 - + diff --git a/src/Canal.Csharp.Abstract/ICanalConnector.cs b/src/Canal.Csharp.Abstract/ICanalConnector.cs index e8b0da6..b02751f 100644 --- a/src/Canal.Csharp.Abstract/ICanalConnector.cs +++ b/src/Canal.Csharp.Abstract/ICanalConnector.cs @@ -1,7 +1,7 @@ using System; -using Canal.Csharp.Protocol; +using CanalSharp.Protocol; -namespace Canal.Csharp.Abstract +namespace CanalSharp.Abstract { public interface ICanalConnector { diff --git a/src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs b/src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs index fdbc488..d83a9ce 100644 --- a/src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs +++ b/src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs @@ -3,7 +3,7 @@ using System.Net; using System.Text; -namespace Canal.Csharp.Abstract +namespace CanalSharp.Abstract { public interface ICanalNodeAccessStrategy { diff --git a/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs b/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs index d4224e5..3da8ba0 100644 --- a/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs +++ b/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs @@ -1,4 +1,4 @@ -namespace Canal.Csharp.Protocol.Exception +namespace CanalSharp.Protocol.Exception { public class CanalClientException : System.Exception { diff --git a/src/Canal.Csharp.Protocol/Position/EntryPosition.cs b/src/Canal.Csharp.Protocol/Position/EntryPosition.cs index 2d3b366..ff94a5b 100644 --- a/src/Canal.Csharp.Protocol/Position/EntryPosition.cs +++ b/src/Canal.Csharp.Protocol/Position/EntryPosition.cs @@ -1,6 +1,6 @@ using System; -namespace Canal.Csharp.Protocol.Position +namespace CanalSharp.Protocol.Position { public class EntryPosition:TimePosition { diff --git a/src/Canal.Csharp.Protocol/Position/LogIdentity.cs b/src/Canal.Csharp.Protocol/Position/LogIdentity.cs index 78ece65..bfaf960 100644 --- a/src/Canal.Csharp.Protocol/Position/LogIdentity.cs +++ b/src/Canal.Csharp.Protocol/Position/LogIdentity.cs @@ -1,6 +1,6 @@ using System.Net; -namespace Canal.Csharp.Protocol.Position +namespace CanalSharp.Protocol.Position { public class LogIdentity:Position { diff --git a/src/Canal.Csharp.Protocol/Position/LogPosition.cs b/src/Canal.Csharp.Protocol/Position/LogPosition.cs index 0ba87f4..1ab3825 100644 --- a/src/Canal.Csharp.Protocol/Position/LogPosition.cs +++ b/src/Canal.Csharp.Protocol/Position/LogPosition.cs @@ -1,4 +1,4 @@ -namespace Canal.Csharp.Protocol.Position +namespace CanalSharp.Protocol.Position { public class LogPosition: Position { diff --git a/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs b/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs index a37ef32..1f17333 100644 --- a/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs +++ b/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs @@ -1,4 +1,4 @@ -namespace Canal.Csharp.Protocol.Position +namespace CanalSharp.Protocol.Position { public class MetaqPosition:Position { diff --git a/src/Canal.Csharp.Protocol/Position/Position.cs b/src/Canal.Csharp.Protocol/Position/Position.cs index c7ddb9b..520d553 100644 --- a/src/Canal.Csharp.Protocol/Position/Position.cs +++ b/src/Canal.Csharp.Protocol/Position/Position.cs @@ -1,6 +1,6 @@ using System; -namespace Canal.Csharp.Protocol.Position +namespace CanalSharp.Protocol.Position { /** * 事件唯一标示 diff --git a/src/Canal.Csharp.Protocol/Position/PositionRange.cs b/src/Canal.Csharp.Protocol/Position/PositionRange.cs index 315709f..cce3332 100644 --- a/src/Canal.Csharp.Protocol/Position/PositionRange.cs +++ b/src/Canal.Csharp.Protocol/Position/PositionRange.cs @@ -1,6 +1,6 @@ using System; -namespace Canal.Csharp.Protocol.Position +namespace CanalSharp.Protocol.Position { [Serializable] public class PositionRange where T:Position diff --git a/src/Canal.Csharp.Protocol/Position/TimePosition.cs b/src/Canal.Csharp.Protocol/Position/TimePosition.cs index c263525..0ea62c7 100644 --- a/src/Canal.Csharp.Protocol/Position/TimePosition.cs +++ b/src/Canal.Csharp.Protocol/Position/TimePosition.cs @@ -1,4 +1,4 @@ -namespace Canal.Csharp.Protocol.Position +namespace CanalSharp.Protocol.Position { public class TimePosition: Position { From 6a23ce38fbb9cdb50c85c4a51cbf238253c8696d Mon Sep 17 00:00:00 2001 From: stulzq Date: Fri, 14 Sep 2018 21:30:13 +0800 Subject: [PATCH 13/50] CanalSharp.Core -> CanalSharp.Client --- CanalSharp.sln | 2 +- src/Canal.Csharp.Abstract/ICanalConnector.cs | 1 + .../{CanalSharp.Core.csproj => CanalSharp.Client.csproj} | 0 3 files changed, 2 insertions(+), 1 deletion(-) rename src/Canal.Csharp.Core/{CanalSharp.Core.csproj => CanalSharp.Client.csproj} (100%) diff --git a/CanalSharp.sln b/CanalSharp.sln index 505ba4d..767e34a 100644 --- a/CanalSharp.sln +++ b/CanalSharp.sln @@ -20,7 +20,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.UnitTests", "tes EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Abstract", "src\Canal.Csharp.Abstract\CanalSharp.Abstract.csproj", "{C61A468E-66C4-4915-9C2C-91936EB99F2A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Core", "src\Canal.Csharp.Core\CanalSharp.Core.csproj", "{E33BCF38-D450-4AFE-B409-E6E7C0251479}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Client", "src\Canal.Csharp.Core\CanalSharp.Client.csproj", "{E33BCF38-D450-4AFE-B409-E6E7C0251479}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Protocol", "src\Canal.Csharp.Protocol\CanalSharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}" EndProject diff --git a/src/Canal.Csharp.Abstract/ICanalConnector.cs b/src/Canal.Csharp.Abstract/ICanalConnector.cs index b02751f..f2e0555 100644 --- a/src/Canal.Csharp.Abstract/ICanalConnector.cs +++ b/src/Canal.Csharp.Abstract/ICanalConnector.cs @@ -1,4 +1,5 @@ using System; +using Canal.Csharp.Protocol; using CanalSharp.Protocol; namespace CanalSharp.Abstract diff --git a/src/Canal.Csharp.Core/CanalSharp.Core.csproj b/src/Canal.Csharp.Core/CanalSharp.Client.csproj similarity index 100% rename from src/Canal.Csharp.Core/CanalSharp.Core.csproj rename to src/Canal.Csharp.Core/CanalSharp.Client.csproj From c50e0218a9fc39e62f7acd20fdb6d968644f39a6 Mon Sep 17 00:00:00 2001 From: stulzq Date: Fri, 14 Sep 2018 21:34:06 +0800 Subject: [PATCH 14/50] change folder name --- CanalSharp.sln | 8 ++++---- .../CanalSharp.Abstract.csproj | 2 +- .../ICanalConnector.cs | 0 .../ICanalNodeAccessStrategy.cs | 0 .../CanalSharp.Client.csproj | 0 .../CanalProtocol.cs | 0 .../CanalProtocol.proto | 0 .../CanalSharp.Protocol.csproj | 0 .../ClientIdentity.cs | 0 .../EntryProtocol.cs | 0 .../EntryProtocol.proto | 0 .../Exception/CanalClientException.cs | 0 .../Message.cs | 0 .../Position/EntryPosition.cs | 0 .../Position/LogIdentity.cs | 0 .../Position/LogPosition.cs | 0 .../Position/MetaqPosition.cs | 0 .../Position/Position.cs | 0 .../Position/PositionRange.cs | 0 .../Position/TimePosition.cs | 0 .../CanalSharp.UnitTests.csproj | 0 .../UnitTest1.cs | 0 22 files changed, 5 insertions(+), 5 deletions(-) rename src/{Canal.Csharp.Abstract => CanalSharp.Abstract}/CanalSharp.Abstract.csproj (85%) rename src/{Canal.Csharp.Abstract => CanalSharp.Abstract}/ICanalConnector.cs (100%) rename src/{Canal.Csharp.Abstract => CanalSharp.Abstract}/ICanalNodeAccessStrategy.cs (100%) rename src/{Canal.Csharp.Core => CanalSharp.Client}/CanalSharp.Client.csproj (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/CanalProtocol.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/CanalProtocol.proto (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/CanalSharp.Protocol.csproj (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/ClientIdentity.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/EntryProtocol.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/EntryProtocol.proto (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/Exception/CanalClientException.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/Message.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/Position/EntryPosition.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/Position/LogIdentity.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/Position/LogPosition.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/Position/MetaqPosition.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/Position/Position.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/Position/PositionRange.cs (100%) rename src/{Canal.Csharp.Protocol => CanalSharp.Protocol}/Position/TimePosition.cs (100%) rename test/{Canal4Net.UnitTests => CanalSharp.UnitTests}/CanalSharp.UnitTests.csproj (100%) rename test/{Canal4Net.UnitTests => CanalSharp.UnitTests}/UnitTest1.cs (100%) diff --git a/CanalSharp.sln b/CanalSharp.sln index 767e34a..41d5ad4 100644 --- a/CanalSharp.sln +++ b/CanalSharp.sln @@ -16,13 +16,13 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{BD70CDB7-9 EndProject Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.UnitTests", "test\Canal4Net.UnitTests\CanalSharp.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.UnitTests", "test\CanalSharp.UnitTests\CanalSharp.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Abstract", "src\Canal.Csharp.Abstract\CanalSharp.Abstract.csproj", "{C61A468E-66C4-4915-9C2C-91936EB99F2A}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Abstract", "src\CanalSharp.Abstract\CanalSharp.Abstract.csproj", "{C61A468E-66C4-4915-9C2C-91936EB99F2A}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Client", "src\Canal.Csharp.Core\CanalSharp.Client.csproj", "{E33BCF38-D450-4AFE-B409-E6E7C0251479}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Client", "src\CanalSharp.Client\CanalSharp.Client.csproj", "{E33BCF38-D450-4AFE-B409-E6E7C0251479}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Protocol", "src\Canal.Csharp.Protocol\CanalSharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Protocol", "src\CanalSharp.Protocol\CanalSharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution diff --git a/src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj b/src/CanalSharp.Abstract/CanalSharp.Abstract.csproj similarity index 85% rename from src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj rename to src/CanalSharp.Abstract/CanalSharp.Abstract.csproj index f47bd05..8d09261 100644 --- a/src/Canal.Csharp.Abstract/CanalSharp.Abstract.csproj +++ b/src/CanalSharp.Abstract/CanalSharp.Abstract.csproj @@ -4,7 +4,7 @@ netstandard2.0 - + diff --git a/src/Canal.Csharp.Abstract/ICanalConnector.cs b/src/CanalSharp.Abstract/ICanalConnector.cs similarity index 100% rename from src/Canal.Csharp.Abstract/ICanalConnector.cs rename to src/CanalSharp.Abstract/ICanalConnector.cs diff --git a/src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs b/src/CanalSharp.Abstract/ICanalNodeAccessStrategy.cs similarity index 100% rename from src/Canal.Csharp.Abstract/ICanalNodeAccessStrategy.cs rename to src/CanalSharp.Abstract/ICanalNodeAccessStrategy.cs diff --git a/src/Canal.Csharp.Core/CanalSharp.Client.csproj b/src/CanalSharp.Client/CanalSharp.Client.csproj similarity index 100% rename from src/Canal.Csharp.Core/CanalSharp.Client.csproj rename to src/CanalSharp.Client/CanalSharp.Client.csproj diff --git a/src/Canal.Csharp.Protocol/CanalProtocol.cs b/src/CanalSharp.Protocol/CanalProtocol.cs similarity index 100% rename from src/Canal.Csharp.Protocol/CanalProtocol.cs rename to src/CanalSharp.Protocol/CanalProtocol.cs diff --git a/src/Canal.Csharp.Protocol/CanalProtocol.proto b/src/CanalSharp.Protocol/CanalProtocol.proto similarity index 100% rename from src/Canal.Csharp.Protocol/CanalProtocol.proto rename to src/CanalSharp.Protocol/CanalProtocol.proto diff --git a/src/Canal.Csharp.Protocol/CanalSharp.Protocol.csproj b/src/CanalSharp.Protocol/CanalSharp.Protocol.csproj similarity index 100% rename from src/Canal.Csharp.Protocol/CanalSharp.Protocol.csproj rename to src/CanalSharp.Protocol/CanalSharp.Protocol.csproj diff --git a/src/Canal.Csharp.Protocol/ClientIdentity.cs b/src/CanalSharp.Protocol/ClientIdentity.cs similarity index 100% rename from src/Canal.Csharp.Protocol/ClientIdentity.cs rename to src/CanalSharp.Protocol/ClientIdentity.cs diff --git a/src/Canal.Csharp.Protocol/EntryProtocol.cs b/src/CanalSharp.Protocol/EntryProtocol.cs similarity index 100% rename from src/Canal.Csharp.Protocol/EntryProtocol.cs rename to src/CanalSharp.Protocol/EntryProtocol.cs diff --git a/src/Canal.Csharp.Protocol/EntryProtocol.proto b/src/CanalSharp.Protocol/EntryProtocol.proto similarity index 100% rename from src/Canal.Csharp.Protocol/EntryProtocol.proto rename to src/CanalSharp.Protocol/EntryProtocol.proto diff --git a/src/Canal.Csharp.Protocol/Exception/CanalClientException.cs b/src/CanalSharp.Protocol/Exception/CanalClientException.cs similarity index 100% rename from src/Canal.Csharp.Protocol/Exception/CanalClientException.cs rename to src/CanalSharp.Protocol/Exception/CanalClientException.cs diff --git a/src/Canal.Csharp.Protocol/Message.cs b/src/CanalSharp.Protocol/Message.cs similarity index 100% rename from src/Canal.Csharp.Protocol/Message.cs rename to src/CanalSharp.Protocol/Message.cs diff --git a/src/Canal.Csharp.Protocol/Position/EntryPosition.cs b/src/CanalSharp.Protocol/Position/EntryPosition.cs similarity index 100% rename from src/Canal.Csharp.Protocol/Position/EntryPosition.cs rename to src/CanalSharp.Protocol/Position/EntryPosition.cs diff --git a/src/Canal.Csharp.Protocol/Position/LogIdentity.cs b/src/CanalSharp.Protocol/Position/LogIdentity.cs similarity index 100% rename from src/Canal.Csharp.Protocol/Position/LogIdentity.cs rename to src/CanalSharp.Protocol/Position/LogIdentity.cs diff --git a/src/Canal.Csharp.Protocol/Position/LogPosition.cs b/src/CanalSharp.Protocol/Position/LogPosition.cs similarity index 100% rename from src/Canal.Csharp.Protocol/Position/LogPosition.cs rename to src/CanalSharp.Protocol/Position/LogPosition.cs diff --git a/src/Canal.Csharp.Protocol/Position/MetaqPosition.cs b/src/CanalSharp.Protocol/Position/MetaqPosition.cs similarity index 100% rename from src/Canal.Csharp.Protocol/Position/MetaqPosition.cs rename to src/CanalSharp.Protocol/Position/MetaqPosition.cs diff --git a/src/Canal.Csharp.Protocol/Position/Position.cs b/src/CanalSharp.Protocol/Position/Position.cs similarity index 100% rename from src/Canal.Csharp.Protocol/Position/Position.cs rename to src/CanalSharp.Protocol/Position/Position.cs diff --git a/src/Canal.Csharp.Protocol/Position/PositionRange.cs b/src/CanalSharp.Protocol/Position/PositionRange.cs similarity index 100% rename from src/Canal.Csharp.Protocol/Position/PositionRange.cs rename to src/CanalSharp.Protocol/Position/PositionRange.cs diff --git a/src/Canal.Csharp.Protocol/Position/TimePosition.cs b/src/CanalSharp.Protocol/Position/TimePosition.cs similarity index 100% rename from src/Canal.Csharp.Protocol/Position/TimePosition.cs rename to src/CanalSharp.Protocol/Position/TimePosition.cs diff --git a/test/Canal4Net.UnitTests/CanalSharp.UnitTests.csproj b/test/CanalSharp.UnitTests/CanalSharp.UnitTests.csproj similarity index 100% rename from test/Canal4Net.UnitTests/CanalSharp.UnitTests.csproj rename to test/CanalSharp.UnitTests/CanalSharp.UnitTests.csproj diff --git a/test/Canal4Net.UnitTests/UnitTest1.cs b/test/CanalSharp.UnitTests/UnitTest1.cs similarity index 100% rename from test/Canal4Net.UnitTests/UnitTest1.cs rename to test/CanalSharp.UnitTests/UnitTest1.cs From 599bbcd251991d28c5f61db71f49a1bd80b7b780 Mon Sep 17 00:00:00 2001 From: stulzq Date: Fri, 14 Sep 2018 22:37:46 +0800 Subject: [PATCH 15/50] add client some impl --- CanalSharp.sln | 7 + .../CanalSharp.Client.csproj | 8 + src/CanalSharp.Client/ICanalConnector.cs | 151 ++++++++++++++++++ .../ICanalNodeAccessStrategy.cs | 14 ++ .../Impl/Running/ClientRunningData.cs | 20 +++ .../Impl/Running/IClientRunningListener.cs | 24 +++ .../Impl/SimpleCanalConnector.cs | 87 ++++++++++ .../Impl/SimpleNodeAccessStrategy.cs | 45 ++++++ .../AbstractCanalLifeCycle.cs | 38 +++++ .../CanalSharp.Common.csproj | 7 + .../Exception/CanalException.cs | 13 ++ src/CanalSharp.Common/ICanalLifeCycle.cs | 13 ++ src/CanalSharp.Protocol/ClientIdentity.cs | 4 +- src/CanalSharp.Protocol/Message.cs | 2 +- 14 files changed, 429 insertions(+), 4 deletions(-) create mode 100644 src/CanalSharp.Client/ICanalConnector.cs create mode 100644 src/CanalSharp.Client/ICanalNodeAccessStrategy.cs create mode 100644 src/CanalSharp.Client/Impl/Running/ClientRunningData.cs create mode 100644 src/CanalSharp.Client/Impl/Running/IClientRunningListener.cs create mode 100644 src/CanalSharp.Client/Impl/SimpleCanalConnector.cs create mode 100644 src/CanalSharp.Client/Impl/SimpleNodeAccessStrategy.cs create mode 100644 src/CanalSharp.Common/AbstractCanalLifeCycle.cs create mode 100644 src/CanalSharp.Common/CanalSharp.Common.csproj create mode 100644 src/CanalSharp.Common/Exception/CanalException.cs create mode 100644 src/CanalSharp.Common/ICanalLifeCycle.cs diff --git a/CanalSharp.sln b/CanalSharp.sln index 41d5ad4..cd99e06 100644 --- a/CanalSharp.sln +++ b/CanalSharp.sln @@ -24,6 +24,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Client", "src\Ca EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Protocol", "src\CanalSharp.Protocol\CanalSharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CanalSharp.Common", "src\CanalSharp.Common\CanalSharp.Common.csproj", "{B583684C-4E2F-42A5-8F08-1E3C4EE4C586}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -46,6 +48,10 @@ Global {B9782080-16BD-4328-A394-3EC8D9B49326}.Debug|Any CPU.Build.0 = Debug|Any CPU {B9782080-16BD-4328-A394-3EC8D9B49326}.Release|Any CPU.ActiveCfg = Release|Any CPU {B9782080-16BD-4328-A394-3EC8D9B49326}.Release|Any CPU.Build.0 = Release|Any CPU + {B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -55,6 +61,7 @@ Global {C61A468E-66C4-4915-9C2C-91936EB99F2A} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} {E33BCF38-D450-4AFE-B409-E6E7C0251479} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} {B9782080-16BD-4328-A394-3EC8D9B49326} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} + {B583684C-4E2F-42A5-8F08-1E3C4EE4C586} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FD9B9146-8418-4F80-A666-9B47BE4F9C9C} diff --git a/src/CanalSharp.Client/CanalSharp.Client.csproj b/src/CanalSharp.Client/CanalSharp.Client.csproj index 9f5c4f4..2a0a970 100644 --- a/src/CanalSharp.Client/CanalSharp.Client.csproj +++ b/src/CanalSharp.Client/CanalSharp.Client.csproj @@ -4,4 +4,12 @@ netstandard2.0 + + + + + + + + diff --git a/src/CanalSharp.Client/ICanalConnector.cs b/src/CanalSharp.Client/ICanalConnector.cs new file mode 100644 index 0000000..4d3fee4 --- /dev/null +++ b/src/CanalSharp.Client/ICanalConnector.cs @@ -0,0 +1,151 @@ +using System; +using CanalSharp.Protocol; + +namespace CanalSharp.Client +{ + public interface ICanalConnector + { + /** + * 链接对应的canal server + * + * @throws CanalClientException + */ + void Connect(); + + /** + * 释放链接 + * + * @throws CanalClientException + */ + void Disconnect(); + + /** + * 检查下链接是否合法 + * + *
+         * 几种case下链接不合法:
+         * 1. 链接canal server失败,一直没有一个可用的链接,返回false
+         * 2. 当前客户端在进行running抢占的时候,做为备份节点存在,非处于工作节点,返回false
+         * 
+         * 说明:
+         * a. 当前客户端一旦做为备份节点存在,当前所有的对{@linkplain CanalConnector}的操作都会处于阻塞状态,直到转为工作节点
+         * b. 所以业务方最好定时调用checkValid()方法用,比如调用CanalConnector所在线程的interrupt,直接退出CanalConnector,并根据自己的需要退出自己的资源
+         * 
+ * + * @throws CanalClientException + */ + bool CheckValid(); + + /** + * 客户端订阅,重复订阅时会更新对应的filter信息 + * + *
+         * 说明:
+         * a. 如果本次订阅中filter信息为空,则直接使用canal server服务端配置的filter信息
+         * b. 如果本次订阅中filter信息不为空,目前会直接替换canal server服务端配置的filter信息,以本次提交的为准
+         * 
+         * TODO: 后续可以考虑,如果本次提交的filter不为空,在执行过滤时,是对canal server filter + 本次filter的交集处理,达到只取1份binlog数据,多个客户端消费不同的表
+         * 
+ * + * @throws CanalClientException + */ + void Subscribe(string filter); + + /** + * 客户端订阅,不提交客户端filter,以服务端的filter为准 + * + * @throws CanalClientException + */ + void Subscribe(); + + /** + * 取消订阅 + * + * @throws CanalClientException + */ + void UnSubscribe(); + + /** + * 获取数据,自动进行确认,该方法返回的条件:尝试拿batchSize条记录,有多少取多少,不会阻塞等待 + * + * @param batchSize + * @return + * @throws CanalClientException + */ + Message Get(int batchSize); + + /** + * 获取数据,自动进行确认 + * + *
+         * 该方法返回的条件:
+         *  a. 拿够batchSize条记录或者超过timeout时间
+         *  b. 如果timeout=0,则阻塞至拿到batchSize记录才返回
+         * 
+ * + * @param batchSize + * @return + * @throws CanalClientException + */ + Message Get(int batchSize, long timeout, TimeSpan unit); + + /** + * 不指定 position 获取事件,该方法返回的条件: 尝试拿batchSize条记录,有多少取多少,不会阻塞等待
+ * canal 会记住此 client 最新的position。
+ * 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 + * + * @param batchSize + * @throws CanalClientException + */ + Message GetWithoutAck(int batchSize); + + /** + * 不指定 position 获取事件. + * + *
+         * 该方法返回的条件:
+         *  a. 拿够batchSize条记录或者超过timeout时间
+         *  b. 如果timeout=0,则阻塞至拿到batchSize记录才返回
+         * 
+ * + * canal 会记住此 client 最新的position。
+ * 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 + * + * @param batchSize + * @param timeout + * @param unit + * @return + * @throws CanalClientException + */ + Message GetWithoutAck(int batchSize, long timeout, TimeSpan unit); + + /** + * 进行 batch id 的确认。确认之后,小于等于此 batchId 的 Message 都会被确认。 + * + * @param batchId + * @throws CanalClientException + */ + void Ack(long batchId); + + /** + * 回滚到未进行 {@link #ack} 的地方,指定回滚具体的batchId + * + * @throws CanalClientException + */ + void Rollback(long batchId); + + /** + * 回滚到未进行 {@link #ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link #ack} 的地方开始拿 + * + * @throws CanalClientException + */ + void Rollback(); + + /** + * 中断的阻塞,用于优雅停止client + * + * @throws CanalClientException + */ + void StopRunning(); + } +} diff --git a/src/CanalSharp.Client/ICanalNodeAccessStrategy.cs b/src/CanalSharp.Client/ICanalNodeAccessStrategy.cs new file mode 100644 index 0000000..d83a9ce --- /dev/null +++ b/src/CanalSharp.Client/ICanalNodeAccessStrategy.cs @@ -0,0 +1,14 @@ +using System; +using System.Collections.Generic; +using System.Net; +using System.Text; + +namespace CanalSharp.Abstract +{ + public interface ICanalNodeAccessStrategy + { + SocketAddress CurrentNode(); + + SocketAddress NextNode(); + } +} diff --git a/src/CanalSharp.Client/Impl/Running/ClientRunningData.cs b/src/CanalSharp.Client/Impl/Running/ClientRunningData.cs new file mode 100644 index 0000000..ce39018 --- /dev/null +++ b/src/CanalSharp.Client/Impl/Running/ClientRunningData.cs @@ -0,0 +1,20 @@ + +using System; + +namespace CanalSharp.Client.Impl.Running +{ + /// + /// client running状态信息 + /// + public class ClientRunningData + { + private short ClientId { get; set; } + public string Address { get; } + public bool Active { get; } = true; + + public bool IsActive() + { + return Active; + } + } +} \ No newline at end of file diff --git a/src/CanalSharp.Client/Impl/Running/IClientRunningListener.cs b/src/CanalSharp.Client/Impl/Running/IClientRunningListener.cs new file mode 100644 index 0000000..f030d11 --- /dev/null +++ b/src/CanalSharp.Client/Impl/Running/IClientRunningListener.cs @@ -0,0 +1,24 @@ + + +using System.Net; + +namespace CanalSharp.Client.Impl.Running +{ + + /// + /// 触发一下mainstem发生切换 + /// + public interface IClientRunningListener + { + /// + /// 触发现在轮到自己做为active,需要载入上一个active的上下文数据 + /// + /// + SocketAddress ProcessActiveEnter(); + + /// + /// 触发一下当前active模式失败 + /// + void ProcessActiveExit(); + } +} \ No newline at end of file diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs new file mode 100644 index 0000000..4c65c8e --- /dev/null +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -0,0 +1,87 @@ + +using System; +using CanalSharp.Protocol; +using Microsoft.Extensions.Logging; +namespace CanalSharp.Client.Impl +{ + public class SimpleCanalConnector: ICanalConnector + { + private ILogger _logger; + + public SimpleCanalConnector(ILogger logger) + { + _logger = logger; + } + + public void Connect() + { + + throw new NotImplementedException(); + } + + public void Disconnect() + { + throw new NotImplementedException(); + } + + public bool CheckValid() + { + throw new NotImplementedException(); + } + + public void Subscribe(string filter) + { + throw new NotImplementedException(); + } + + public void Subscribe() + { + throw new NotImplementedException(); + } + + public void UnSubscribe() + { + throw new NotImplementedException(); + } + + public Message Get(int batchSize) + { + throw new NotImplementedException(); + } + + public Message Get(int batchSize, long timeout, TimeSpan unit) + { + throw new NotImplementedException(); + } + + public Message GetWithoutAck(int batchSize) + { + throw new NotImplementedException(); + } + + public Message GetWithoutAck(int batchSize, long timeout, TimeSpan unit) + { + throw new NotImplementedException(); + } + + public void Ack(long batchId) + { + throw new NotImplementedException(); + } + + public void Rollback(long batchId) + { + throw new NotImplementedException(); + } + + public void Rollback() + { + throw new NotImplementedException(); + } + + public void StopRunning() + { + throw new NotImplementedException(); + } + } +} \ No newline at end of file diff --git a/src/CanalSharp.Client/Impl/SimpleNodeAccessStrategy.cs b/src/CanalSharp.Client/Impl/SimpleNodeAccessStrategy.cs new file mode 100644 index 0000000..1aeeac7 --- /dev/null +++ b/src/CanalSharp.Client/Impl/SimpleNodeAccessStrategy.cs @@ -0,0 +1,45 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Net; +using CanalSharp.Abstract; + +namespace CanalSharp.Client.Impl +{ + + /// + /// 简单版本的node访问实现 + /// + public class SimpleNodeAccessStrategy : ICanalNodeAccessStrategy + { + private readonly List _nodes = new List(); + private int _index = 0; + + public SimpleNodeAccessStrategy(List nodes) + { + if (nodes == null || !nodes.Any()) + { + throw new ArgumentException("at least 1 node required.", nameof(nodes)); + } + + this._nodes.AddRange(nodes); + } + + public SocketAddress NextNode() + { + try + { + return _nodes[_index]; + } + finally + { + _index = (_index + 1) % _nodes.Count(); + } + } + + public SocketAddress CurrentNode() + { + return _nodes[_index]; + } + } +} \ No newline at end of file diff --git a/src/CanalSharp.Common/AbstractCanalLifeCycle.cs b/src/CanalSharp.Common/AbstractCanalLifeCycle.cs new file mode 100644 index 0000000..28ea9a9 --- /dev/null +++ b/src/CanalSharp.Common/AbstractCanalLifeCycle.cs @@ -0,0 +1,38 @@ +// #region File Annotation +// + + +using CanalSharp.Common.Exception; + +namespace CanalSharp.Common +{ + public abstract class AbstractCanalLifeCycle : ICanalLifeCycle + { + protected volatile bool Running = false; // 是否处于运行中 + + public bool IsStart() + { + return Running; + } + + public virtual void Start() + { + if (Running) + { + throw new CanalException(this.GetType().Name + " has startup , don't repeat start"); + } + + Running = true; + } + + public virtual void Stop() + { + if (!Running) + { + throw new CanalException(this.GetType().Name + " isn't start , please check"); + } + + Running = false; + } + } +} \ No newline at end of file diff --git a/src/CanalSharp.Common/CanalSharp.Common.csproj b/src/CanalSharp.Common/CanalSharp.Common.csproj new file mode 100644 index 0000000..9f5c4f4 --- /dev/null +++ b/src/CanalSharp.Common/CanalSharp.Common.csproj @@ -0,0 +1,7 @@ + + + + netstandard2.0 + + + diff --git a/src/CanalSharp.Common/Exception/CanalException.cs b/src/CanalSharp.Common/Exception/CanalException.cs new file mode 100644 index 0000000..3d0d840 --- /dev/null +++ b/src/CanalSharp.Common/Exception/CanalException.cs @@ -0,0 +1,13 @@ +namespace CanalSharp.Common.Exception +{ + public class CanalException : System.Exception + { + public CanalException(string errorCode) : base(errorCode) + { + } + + public CanalException(string errorCode, System.Exception cause) : base(errorCode, cause) + { + } + } +} diff --git a/src/CanalSharp.Common/ICanalLifeCycle.cs b/src/CanalSharp.Common/ICanalLifeCycle.cs new file mode 100644 index 0000000..8993491 --- /dev/null +++ b/src/CanalSharp.Common/ICanalLifeCycle.cs @@ -0,0 +1,13 @@ +using System; + +namespace CanalSharp.Common +{ + public interface ICanalLifeCycle + { + void Start(); + + void Stop(); + + bool IsStart(); + } +} diff --git a/src/CanalSharp.Protocol/ClientIdentity.cs b/src/CanalSharp.Protocol/ClientIdentity.cs index 00c736c..752bdf4 100644 --- a/src/CanalSharp.Protocol/ClientIdentity.cs +++ b/src/CanalSharp.Protocol/ClientIdentity.cs @@ -1,8 +1,6 @@ using System; -using System.Collections.Generic; -using System.Text; -namespace Canal.Csharp.Protocol +namespace CanalSharp.Protocol { [Serializable] public class ClientIdentity diff --git a/src/CanalSharp.Protocol/Message.cs b/src/CanalSharp.Protocol/Message.cs index 4255861..e1d0d92 100644 --- a/src/CanalSharp.Protocol/Message.cs +++ b/src/CanalSharp.Protocol/Message.cs @@ -3,7 +3,7 @@ using Com.Alibaba.Otter.Canal.Protocol; using Google.Protobuf; -namespace Canal.Csharp.Protocol +namespace CanalSharp.Protocol { [Serializable] public class Message From 6f279870338ba1fc5993cec74e155564858655d7 Mon Sep 17 00:00:00 2001 From: stulzq Date: Fri, 14 Sep 2018 22:37:51 +0800 Subject: [PATCH 16/50] remove CanalSharp.Abstract --- .../CanalSharp.Abstract.csproj | 15 -- src/CanalSharp.Abstract/ICanalConnector.cs | 152 ------------------ .../ICanalNodeAccessStrategy.cs | 14 -- 3 files changed, 181 deletions(-) delete mode 100644 src/CanalSharp.Abstract/CanalSharp.Abstract.csproj delete mode 100644 src/CanalSharp.Abstract/ICanalConnector.cs delete mode 100644 src/CanalSharp.Abstract/ICanalNodeAccessStrategy.cs diff --git a/src/CanalSharp.Abstract/CanalSharp.Abstract.csproj b/src/CanalSharp.Abstract/CanalSharp.Abstract.csproj deleted file mode 100644 index 8d09261..0000000 --- a/src/CanalSharp.Abstract/CanalSharp.Abstract.csproj +++ /dev/null @@ -1,15 +0,0 @@ - - - - netstandard2.0 - - - - - - - ..\..\..\..\..\.nuget\packages\microsoft.testplatform.testhost\15.7.0\lib\netstandard1.5\Microsoft.TestPlatform.CommunicationUtilities.dll - - - - diff --git a/src/CanalSharp.Abstract/ICanalConnector.cs b/src/CanalSharp.Abstract/ICanalConnector.cs deleted file mode 100644 index f2e0555..0000000 --- a/src/CanalSharp.Abstract/ICanalConnector.cs +++ /dev/null @@ -1,152 +0,0 @@ -using System; -using Canal.Csharp.Protocol; -using CanalSharp.Protocol; - -namespace CanalSharp.Abstract -{ - public interface ICanalConnector - { - /** - * 链接对应的canal server - * - * @throws CanalClientException - */ - void Connect(); - - /** - * 释放链接 - * - * @throws CanalClientException - */ - void Disconnect(); - - /** - * 检查下链接是否合法 - * - *
-         * 几种case下链接不合法:
-         * 1. 链接canal server失败,一直没有一个可用的链接,返回false
-         * 2. 当前客户端在进行running抢占的时候,做为备份节点存在,非处于工作节点,返回false
-         * 
-         * 说明:
-         * a. 当前客户端一旦做为备份节点存在,当前所有的对{@linkplain CanalConnector}的操作都会处于阻塞状态,直到转为工作节点
-         * b. 所以业务方最好定时调用checkValid()方法用,比如调用CanalConnector所在线程的interrupt,直接退出CanalConnector,并根据自己的需要退出自己的资源
-         * 
- * - * @throws CanalClientException - */ - bool CheckValid(); - - /** - * 客户端订阅,重复订阅时会更新对应的filter信息 - * - *
-         * 说明:
-         * a. 如果本次订阅中filter信息为空,则直接使用canal server服务端配置的filter信息
-         * b. 如果本次订阅中filter信息不为空,目前会直接替换canal server服务端配置的filter信息,以本次提交的为准
-         * 
-         * TODO: 后续可以考虑,如果本次提交的filter不为空,在执行过滤时,是对canal server filter + 本次filter的交集处理,达到只取1份binlog数据,多个客户端消费不同的表
-         * 
- * - * @throws CanalClientException - */ - void Subscribe(string filter); - - /** - * 客户端订阅,不提交客户端filter,以服务端的filter为准 - * - * @throws CanalClientException - */ - void Subscribe(); - - /** - * 取消订阅 - * - * @throws CanalClientException - */ - void UnSubscribe(); - - /** - * 获取数据,自动进行确认,该方法返回的条件:尝试拿batchSize条记录,有多少取多少,不会阻塞等待 - * - * @param batchSize - * @return - * @throws CanalClientException - */ - Message Get(int batchSize); - - /** - * 获取数据,自动进行确认 - * - *
-         * 该方法返回的条件:
-         *  a. 拿够batchSize条记录或者超过timeout时间
-         *  b. 如果timeout=0,则阻塞至拿到batchSize记录才返回
-         * 
- * - * @param batchSize - * @return - * @throws CanalClientException - */ - Message Get(int batchSize, long timeout, TimeSpan unit); - - /** - * 不指定 position 获取事件,该方法返回的条件: 尝试拿batchSize条记录,有多少取多少,不会阻塞等待
- * canal 会记住此 client 最新的position。
- * 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 - * - * @param batchSize - * @throws CanalClientException - */ - Message GetWithoutAck(int batchSize); - - /** - * 不指定 position 获取事件. - * - *
-         * 该方法返回的条件:
-         *  a. 拿够batchSize条记录或者超过timeout时间
-         *  b. 如果timeout=0,则阻塞至拿到batchSize记录才返回
-         * 
- * - * canal 会记住此 client 最新的position。
- * 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 - * - * @param batchSize - * @param timeout - * @param unit - * @return - * @throws CanalClientException - */ - Message GetWithoutAck(int batchSize, long timeout, TimeSpan unit); - - /** - * 进行 batch id 的确认。确认之后,小于等于此 batchId 的 Message 都会被确认。 - * - * @param batchId - * @throws CanalClientException - */ - void Ack(long batchId); - - /** - * 回滚到未进行 {@link #ack} 的地方,指定回滚具体的batchId - * - * @throws CanalClientException - */ - void Rollback(long batchId); - - /** - * 回滚到未进行 {@link #ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link #ack} 的地方开始拿 - * - * @throws CanalClientException - */ - void Rollback(); - - /** - * 中断的阻塞,用于优雅停止client - * - * @throws CanalClientException - */ - void StopRunning(); - } -} diff --git a/src/CanalSharp.Abstract/ICanalNodeAccessStrategy.cs b/src/CanalSharp.Abstract/ICanalNodeAccessStrategy.cs deleted file mode 100644 index d83a9ce..0000000 --- a/src/CanalSharp.Abstract/ICanalNodeAccessStrategy.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Text; - -namespace CanalSharp.Abstract -{ - public interface ICanalNodeAccessStrategy - { - SocketAddress CurrentNode(); - - SocketAddress NextNode(); - } -} From bcee772301abd8c9d5166f7d2a4a6c45b25c08ff Mon Sep 17 00:00:00 2001 From: stulzq Date: Fri, 14 Sep 2018 23:44:14 +0800 Subject: [PATCH 17/50] update sln --- CanalSharp.sln | 7 ------- src/CanalSharp.Client/CanalSharp.Client.csproj | 1 + 2 files changed, 1 insertion(+), 7 deletions(-) diff --git a/CanalSharp.sln b/CanalSharp.sln index cd99e06..436f9a4 100644 --- a/CanalSharp.sln +++ b/CanalSharp.sln @@ -18,8 +18,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4B78B79B-7EB EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.UnitTests", "test\CanalSharp.UnitTests\CanalSharp.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}" EndProject -Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Abstract", "src\CanalSharp.Abstract\CanalSharp.Abstract.csproj", "{C61A468E-66C4-4915-9C2C-91936EB99F2A}" -EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Client", "src\CanalSharp.Client\CanalSharp.Client.csproj", "{E33BCF38-D450-4AFE-B409-E6E7C0251479}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Protocol", "src\CanalSharp.Protocol\CanalSharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}" @@ -36,10 +34,6 @@ Global {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Debug|Any CPU.Build.0 = Debug|Any CPU {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Release|Any CPU.ActiveCfg = Release|Any CPU {83F407DD-5810-422F-8AF6-4E9BA75AC678}.Release|Any CPU.Build.0 = Release|Any CPU - {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Debug|Any CPU.Build.0 = Debug|Any CPU - {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Release|Any CPU.ActiveCfg = Release|Any CPU - {C61A468E-66C4-4915-9C2C-91936EB99F2A}.Release|Any CPU.Build.0 = Release|Any CPU {E33BCF38-D450-4AFE-B409-E6E7C0251479}.Debug|Any CPU.ActiveCfg = Debug|Any CPU {E33BCF38-D450-4AFE-B409-E6E7C0251479}.Debug|Any CPU.Build.0 = Debug|Any CPU {E33BCF38-D450-4AFE-B409-E6E7C0251479}.Release|Any CPU.ActiveCfg = Release|Any CPU @@ -58,7 +52,6 @@ Global EndGlobalSection GlobalSection(NestedProjects) = preSolution {83F407DD-5810-422F-8AF6-4E9BA75AC678} = {BD70CDB7-94E9-4621-B702-DC04DB9D59EF} - {C61A468E-66C4-4915-9C2C-91936EB99F2A} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} {E33BCF38-D450-4AFE-B409-E6E7C0251479} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} {B9782080-16BD-4328-A394-3EC8D9B49326} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} {B583684C-4E2F-42A5-8F08-1E3C4EE4C586} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} diff --git a/src/CanalSharp.Client/CanalSharp.Client.csproj b/src/CanalSharp.Client/CanalSharp.Client.csproj index 2a0a970..87cb9be 100644 --- a/src/CanalSharp.Client/CanalSharp.Client.csproj +++ b/src/CanalSharp.Client/CanalSharp.Client.csproj @@ -9,6 +9,7 @@
+ From 3d0f0ab2c7e3aff88fcf60eeb4c5b9cc8f9b98d5 Mon Sep 17 00:00:00 2001 From: WithLin Date: Sat, 15 Sep 2018 09:31:48 +0800 Subject: [PATCH 18/50] fix code style --- src/CanalSharp.Client/ICanalConnector.cs | 194 +++++++++-------------- 1 file changed, 77 insertions(+), 117 deletions(-) diff --git a/src/CanalSharp.Client/ICanalConnector.cs b/src/CanalSharp.Client/ICanalConnector.cs index 4d3fee4..250e179 100644 --- a/src/CanalSharp.Client/ICanalConnector.cs +++ b/src/CanalSharp.Client/ICanalConnector.cs @@ -3,149 +3,109 @@ namespace CanalSharp.Client { - public interface ICanalConnector + public interface ICanalConnector { - /** - * 链接对应的canal server - * - * @throws CanalClientException - */ + /// + /// 链接对应的canal server + /// void Connect(); - /** - * 释放链接 - * - * @throws CanalClientException - */ + /// + /// 释放链接 + /// void Disconnect(); - /** - * 检查下链接是否合法 - * - *
-         * 几种case下链接不合法:
-         * 1. 链接canal server失败,一直没有一个可用的链接,返回false
-         * 2. 当前客户端在进行running抢占的时候,做为备份节点存在,非处于工作节点,返回false
-         * 
-         * 说明:
-         * a. 当前客户端一旦做为备份节点存在,当前所有的对{@linkplain CanalConnector}的操作都会处于阻塞状态,直到转为工作节点
-         * b. 所以业务方最好定时调用checkValid()方法用,比如调用CanalConnector所在线程的interrupt,直接退出CanalConnector,并根据自己的需要退出自己的资源
-         * 
- * - * @throws CanalClientException - */ + /// + /// 检查下链接是否合法 + /// 几种case下链接不合法: + /// 1. 链接canal server失败,一直没有一个可用的链接,返回false + /// 2. 当前客户端在进行running抢占的时候,做为备份节点存在,非处于工作节点,返回false + /// 说明: + /// a. 当前客户端一旦做为备份节点存在,当前所有的对{@linkplain CanalConnector}的操作都会处于阻塞状态,直到转为工作节点 + /// b. 所以业务方最好定时调用checkValid()方法用,比如调用CanalConnector所在线程的interrupt,直接退出CanalConnector,并根据自己的需要退出自己的资源 + /// + /// bool CheckValid(); - /** - * 客户端订阅,重复订阅时会更新对应的filter信息 - * - *
-         * 说明:
-         * a. 如果本次订阅中filter信息为空,则直接使用canal server服务端配置的filter信息
-         * b. 如果本次订阅中filter信息不为空,目前会直接替换canal server服务端配置的filter信息,以本次提交的为准
-         * 
-         * TODO: 后续可以考虑,如果本次提交的filter不为空,在执行过滤时,是对canal server filter + 本次filter的交集处理,达到只取1份binlog数据,多个客户端消费不同的表
-         * 
- * - * @throws CanalClientException - */ + /// + /// 客户端订阅,重复订阅时会更新对应的filter信息 + /// a. 如果本次订阅中filter信息为空,则直接使用canal server服务端配置的filter信息 + /// b. 如果本次订阅中filter信息不为空,目前会直接替换canal server服务端配置的filter信息,以本次提交的为准 + /// + /// + /// TODO: 后续可以考虑,如果本次提交的filter不为空,在执行过滤时,是对canal server filter + 本次filter的交集处理,达到只取1份binlog数据,多个客户端消费不同的表 void Subscribe(string filter); - /** - * 客户端订阅,不提交客户端filter,以服务端的filter为准 - * - * @throws CanalClientException - */ + /// + /// 客户端订阅,不提交客户端filter,以服务端的filter为准 + /// void Subscribe(); - /** - * 取消订阅 - * - * @throws CanalClientException - */ + /// + /// 取消订阅 + /// void UnSubscribe(); - /** - * 获取数据,自动进行确认,该方法返回的条件:尝试拿batchSize条记录,有多少取多少,不会阻塞等待 - * - * @param batchSize - * @return - * @throws CanalClientException - */ + /// + /// 获取数据,自动进行确认,该方法返回的条件:尝试拿batchSize条记录,有多少取多少,不会阻塞等待 + /// + /// + /// Message Get(int batchSize); - - /** - * 获取数据,自动进行确认 - * - *
-         * 该方法返回的条件:
-         *  a. 拿够batchSize条记录或者超过timeout时间
-         *  b. 如果timeout=0,则阻塞至拿到batchSize记录才返回
-         * 
- * - * @param batchSize - * @return - * @throws CanalClientException - */ + /// + /// 获取数据,自动进行确认 + /// 该方法返回的条件: + /// a. 拿够batchSize条记录或者超过timeout时间 + /// b. 如果timeout=0,则阻塞至拿到batchSize记录才返回 + /// + /// + /// + /// + /// Message Get(int batchSize, long timeout, TimeSpan unit); - /** - * 不指定 position 获取事件,该方法返回的条件: 尝试拿batchSize条记录,有多少取多少,不会阻塞等待
- * canal 会记住此 client 最新的position。
- * 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 - * - * @param batchSize - * @throws CanalClientException - */ + /// + /// 不指定 position 获取事件,该方法返回的条件: 尝试拿batchSize条记录,有多少取多少,不会阻塞等待 + /// canal 会记住此 client 最新的position + /// 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 + /// + /// + /// Message GetWithoutAck(int batchSize); - /** - * 不指定 position 获取事件. - * - *
-         * 该方法返回的条件:
-         *  a. 拿够batchSize条记录或者超过timeout时间
-         *  b. 如果timeout=0,则阻塞至拿到batchSize记录才返回
-         * 
- * - * canal 会记住此 client 最新的position。
- * 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 - * - * @param batchSize - * @param timeout - * @param unit - * @return - * @throws CanalClientException - */ + /// + /// 该方法返回的条件: + /// a. 拿够batchSize条记录或者超过timeout时间 + /// b. 如果timeout=0,则阻塞至拿到batchSize记录才返回 + /// canal 会记住此 client 最新的position。 + /// 如果是第一次 fetch,则会从 canal 中保存的最老一条数据开始输出。 + /// + /// + /// + /// + /// Message GetWithoutAck(int batchSize, long timeout, TimeSpan unit); - /** - * 进行 batch id 的确认。确认之后,小于等于此 batchId 的 Message 都会被确认。 - * - * @param batchId - * @throws CanalClientException - */ + /// + /// 进行 batch id 的确认。确认之后,小于等于此 batchId 的 Message 都会被确认。 + /// + /// void Ack(long batchId); - /** - * 回滚到未进行 {@link #ack} 的地方,指定回滚具体的batchId - * - * @throws CanalClientException - */ + /// + /// 回滚到未进行 {@link #ack} 的地方,指定回滚具体的batchId + /// + /// void Rollback(long batchId); - /** - * 回滚到未进行 {@link #ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link #ack} 的地方开始拿 - * - * @throws CanalClientException - */ + /// + /// 回滚到未进行 {@link #ack} 的地方,下次fetch的时候,可以从最后一个没有 {@link #ack} 的地方开始拿 + /// void Rollback(); - /** - * 中断的阻塞,用于优雅停止client - * - * @throws CanalClientException - */ + /// + /// 中断的阻塞,用于优雅停止client + /// void StopRunning(); } } From 270f12354e5c787653b111ac7d02efc17631ae4f Mon Sep 17 00:00:00 2001 From: WithLin Date: Sat, 15 Sep 2018 09:38:26 +0800 Subject: [PATCH 19/50] Fix add Alarm module --- src/CanalSharp.Common/Alarm/ICanalAlarmHandler.cs | 10 ++++++++++ .../Alarm/Impl/LogAlarmHandler.cs | 15 +++++++++++++++ 2 files changed, 25 insertions(+) create mode 100644 src/CanalSharp.Common/Alarm/ICanalAlarmHandler.cs create mode 100644 src/CanalSharp.Common/Alarm/Impl/LogAlarmHandler.cs diff --git a/src/CanalSharp.Common/Alarm/ICanalAlarmHandler.cs b/src/CanalSharp.Common/Alarm/ICanalAlarmHandler.cs new file mode 100644 index 0000000..1415a5a --- /dev/null +++ b/src/CanalSharp.Common/Alarm/ICanalAlarmHandler.cs @@ -0,0 +1,10 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CanalSharp.Common.Alarm +{ + interface ICanalAlarmHandler + { + } +} diff --git a/src/CanalSharp.Common/Alarm/Impl/LogAlarmHandler.cs b/src/CanalSharp.Common/Alarm/Impl/LogAlarmHandler.cs new file mode 100644 index 0000000..7058690 --- /dev/null +++ b/src/CanalSharp.Common/Alarm/Impl/LogAlarmHandler.cs @@ -0,0 +1,15 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace CanalSharp.Common.Alarm.Impl +{ + public class LogAlarmHandler : ICanalAlarmHandler + { + private readonly ILogger _logger = LogManager.GetLogger(typeof(LogAlarmHandler)); + public void SendAlarm(string destination, string msg) + { + _logger.Warning($"destination:{destination}[{msg}]"); + } + } +} From a5a95ffcf468701d5452d4f4fea74b83cc9ee59b Mon Sep 17 00:00:00 2001 From: WithLin Date: Sat, 15 Sep 2018 09:39:20 +0800 Subject: [PATCH 20/50] Fix add Log Module --- src/CanalSharp.Common/Logging/ILogger.cs | 17 ++++++++++++ .../Logging/ILoggerFactory.cs | 9 +++++++ src/CanalSharp.Common/Logging/LogManager.cs | 27 +++++++++++++++++++ src/CanalSharp.Common/Logging/NullLogger.cs | 27 +++++++++++++++++++ .../Logging/NullLoggerFactory.cs | 12 +++++++++ 5 files changed, 92 insertions(+) create mode 100644 src/CanalSharp.Common/Logging/ILogger.cs create mode 100644 src/CanalSharp.Common/Logging/ILoggerFactory.cs create mode 100644 src/CanalSharp.Common/Logging/LogManager.cs create mode 100644 src/CanalSharp.Common/Logging/NullLogger.cs create mode 100644 src/CanalSharp.Common/Logging/NullLoggerFactory.cs diff --git a/src/CanalSharp.Common/Logging/ILogger.cs b/src/CanalSharp.Common/Logging/ILogger.cs new file mode 100644 index 0000000..eb88aa1 --- /dev/null +++ b/src/CanalSharp.Common/Logging/ILogger.cs @@ -0,0 +1,17 @@ +using System; + +namespace Canal.Csharp.Abstract.Logging +{ + public interface ILogger + { + void Debug(String message); + + void Info(String message); + + void Warning(String message); + + void Error(String message, Exception exception); + + void Trace(String message); + } +} \ No newline at end of file diff --git a/src/CanalSharp.Common/Logging/ILoggerFactory.cs b/src/CanalSharp.Common/Logging/ILoggerFactory.cs new file mode 100644 index 0000000..1549e49 --- /dev/null +++ b/src/CanalSharp.Common/Logging/ILoggerFactory.cs @@ -0,0 +1,9 @@ +using System; + +namespace Canal.Csharp.Abstract.Logging +{ + public interface ILoggerFactory + { + ILogger CreateLogger(Type type); + } +} \ No newline at end of file diff --git a/src/CanalSharp.Common/Logging/LogManager.cs b/src/CanalSharp.Common/Logging/LogManager.cs new file mode 100644 index 0000000..e93db62 --- /dev/null +++ b/src/CanalSharp.Common/Logging/LogManager.cs @@ -0,0 +1,27 @@ +using System; +using Servicecomb.Saga.Omega.Abstractions.Logging; + +namespace Canal.Csharp.Abstract.Logging +{ + public static class LogManager + { + private static readonly ILoggerFactory defaultLoggerFactory = new NullLoggerFactory(); + private static ILoggerFactory _loggerFactory; + + public static ILogger GetLogger(Type type) + { + var loggerFactory = _loggerFactory ?? defaultLoggerFactory; + return loggerFactory.CreateLogger(type); + } + + public static ILogger GetLogger() + { + return GetLogger(typeof(T)); + } + + public static void SetLoggerFactory(ILoggerFactory loggerFactory) + { + _loggerFactory = loggerFactory; + } + } +} \ No newline at end of file diff --git a/src/CanalSharp.Common/Logging/NullLogger.cs b/src/CanalSharp.Common/Logging/NullLogger.cs new file mode 100644 index 0000000..86861b8 --- /dev/null +++ b/src/CanalSharp.Common/Logging/NullLogger.cs @@ -0,0 +1,27 @@ +using System; + +namespace Canal.Csharp.Abstract.Logging +{ + internal class NullLogger : ILogger + { + public void Debug(String message) + { + } + + public void Info(String message) + { + } + + public void Warning(String message) + { + } + + public void Error(String message, Exception exception) + { + } + + public void Trace(String message) + { + } + } +} \ No newline at end of file diff --git a/src/CanalSharp.Common/Logging/NullLoggerFactory.cs b/src/CanalSharp.Common/Logging/NullLoggerFactory.cs new file mode 100644 index 0000000..a5557b9 --- /dev/null +++ b/src/CanalSharp.Common/Logging/NullLoggerFactory.cs @@ -0,0 +1,12 @@ +using System; + +namespace Canal.Csharp.Abstract.Logging +{ + public class NullLoggerFactory : ILoggerFactory + { + public ILogger CreateLogger(Type type) + { + return new NullLogger(); + } + } +} \ No newline at end of file From 0b85d55e44dfd5c69734cf76ba915470d4a2462f Mon Sep 17 00:00:00 2001 From: WithLin Date: Sat, 15 Sep 2018 09:41:36 +0800 Subject: [PATCH 21/50] add zookeeper module --- .../Running/IServerRunningListener.cs | 25 +++++++++++++++++++ 1 file changed, 25 insertions(+) create mode 100644 src/CanalSharp.Common/Zookeeper/Running/IServerRunningListener.cs diff --git a/src/CanalSharp.Common/Zookeeper/Running/IServerRunningListener.cs b/src/CanalSharp.Common/Zookeeper/Running/IServerRunningListener.cs new file mode 100644 index 0000000..f7ad672 --- /dev/null +++ b/src/CanalSharp.Common/Zookeeper/Running/IServerRunningListener.cs @@ -0,0 +1,25 @@ +namespace CanalSharp.Common.Zookeeper.Running +{ + public interface IServerRunningListener + { + /** + * 启动时回调做点事情 + */ + void ProcessStart(); + + /** + * 关闭时回调做点事情 + */ + void ProcessStop(); + + /** + * 触发现在轮到自己做为active,需要载入上一个active的上下文数据 + */ + void ProcessActiveEnter(); + + /** + * 触发一下当前active模式失败 + */ + void ProcessActiveExit(); + } +} From 639f6837f9c093ad6e6f6aea2899bc9fe3dcc91d Mon Sep 17 00:00:00 2001 From: WithLin Date: Sat, 15 Sep 2018 09:44:21 +0800 Subject: [PATCH 22/50] Fix add Running module --- .../Running/IClientRunningListener.cs | 17 +++++++++++++++++ .../Running/Impl/ClientRunningData.cs | 9 +++++++++ .../Running/Impl/ClientRunningMonitor.cs | 11 +++++++++++ 3 files changed, 37 insertions(+) create mode 100644 src/CanalSharp.Client/Running/IClientRunningListener.cs create mode 100644 src/CanalSharp.Client/Running/Impl/ClientRunningData.cs create mode 100644 src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs diff --git a/src/CanalSharp.Client/Running/IClientRunningListener.cs b/src/CanalSharp.Client/Running/IClientRunningListener.cs new file mode 100644 index 0000000..1c35347 --- /dev/null +++ b/src/CanalSharp.Client/Running/IClientRunningListener.cs @@ -0,0 +1,17 @@ +using System.Net; + +namespace CanalSharp.Client.Running +{ + public interface IClientRunningListener + { + /** + * 触发现在轮到自己做为active,需要载入上一个active的上下文数据 + */ + SocketAddress ProcessActiveEnter(); + + /** + * 触发一下当前active模式失败 + */ + void ProcessActiveExit(); + } +} diff --git a/src/CanalSharp.Client/Running/Impl/ClientRunningData.cs b/src/CanalSharp.Client/Running/Impl/ClientRunningData.cs new file mode 100644 index 0000000..55343f4 --- /dev/null +++ b/src/CanalSharp.Client/Running/Impl/ClientRunningData.cs @@ -0,0 +1,9 @@ +namespace CanalSharp.Client.Running.Impl +{ + public class ClientRunningData + { + public short ClientId { get; set; } + public string Address { get; set; } + public bool Active { get; set; } = true; + } +} diff --git a/src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs b/src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs new file mode 100644 index 0000000..f3c0efb --- /dev/null +++ b/src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs @@ -0,0 +1,11 @@ +using System; +using System.Collections.Generic; +using System.Text; +using Canal.Csharp.Abstract.Common; + +namespace Canal.Csharp.Core.Running +{ + public class ClientRunningMonitor: AbstractCanalLifeCycle + { + } +} From 5e17fc0aba20d245989a40d4ed20a3819ba50094 Mon Sep 17 00:00:00 2001 From: WithLin Date: Sat, 15 Sep 2018 09:54:39 +0800 Subject: [PATCH 23/50] Fix add utils module --- src/CanalSharp.Common/Utils/AddressUtils.cs | 132 ++++++++++++++++++++ src/CanalSharp.Common/Utils/BooleanMutex.cs | 16 +++ 2 files changed, 148 insertions(+) create mode 100644 src/CanalSharp.Common/Utils/AddressUtils.cs create mode 100644 src/CanalSharp.Common/Utils/BooleanMutex.cs diff --git a/src/CanalSharp.Common/Utils/AddressUtils.cs b/src/CanalSharp.Common/Utils/AddressUtils.cs new file mode 100644 index 0000000..f0fd868 --- /dev/null +++ b/src/CanalSharp.Common/Utils/AddressUtils.cs @@ -0,0 +1,132 @@ +using System; +using System.IO; +using System.Linq; +using System.Net; +using System.Net.NetworkInformation; +using System.Net.Sockets; +using System.Text.RegularExpressions; +using CanalSharp.Common.Logging; + +namespace CanalSharp.Common.Utils +{ + + public class AddressUtils + { + private static readonly ILogger _logger = LogManager.GetLogger(typeof(AddressUtils)); + private static string LOCALHOST_IP = "127.0.0.1"; + private static string EMPTY_IP = "0.0.0.0"; + private static readonly Regex IP_PATTERN = new Regex("[0-9]{1,3}(\\.[0-9]{1,3}){3,}"); + + + public static bool IsAvailablePort(int port) + { + TcpListener ss = null; + try + { + ss = new TcpListener(port); + ss.Start(); + return true; + } + catch (IOException e) + { + return false; + } + finally + { + if (ss != null) + { + try + { + ss.Stop(); + } + catch (IOException e) + { + } + } + } + } + + private static bool IsValidHostAddress(IPAddress address) + { + if (address == null || IPAddress.IsLoopback(address)) return false; + var name = Dns.GetHostEntry(address).HostName; + return (name != null && !EMPTY_IP.Equals(name) && !LOCALHOST_IP.Equals(name) && IP_PATTERN.IsMatch(name)); + } + + + public static string GetHostIp() + { + var address = GetHostAddress(); + return address == null ? null : Dns.GetHostEntry(address).HostName; + } + + public static string GetHostName() + { + //IPHostEntry hostEntry; + + //hostEntry = Dns.GetHostEntry(host); + + ////you might get more than one ip for a hostname since + ////DNS supports more than one record + + //if (hostEntry.AddressList.Length > 0) + //{ + // var ip = hostEntry.AddressList[0]; + // Socket s = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP); + // s.Connect(ip, 80); + //} + var address = GetHostAddress(); + return address == null ? null : Dns.GetHostEntry(address).HostName; + } + + + public static IPAddress GetHostAddress() + { + IPAddress localAddress = null; + try + { + localAddress = Dns.GetHostEntry(Dns.GetHostName()) + .AddressList.First( + f => f.AddressFamily == AddressFamily.InterNetwork); + if (IsValidHostAddress(localAddress)) + { + return localAddress; + } + } + catch (System.Exception e) + { + _logger.Warning($"Failed to retriving local host ip address, try scan network card ip address. cause: {e.Message}"); + } + try + { + var interfaces = NetworkInterface.GetAllNetworkInterfaces(); + if (interfaces != null) + { + foreach (var ni in NetworkInterface.GetAllNetworkInterfaces()) + { + if (ni.NetworkInterfaceType != NetworkInterfaceType.Wireless80211 && + ni.NetworkInterfaceType != NetworkInterfaceType.Ethernet) continue; + Console.WriteLine(ni.Name); + foreach (var ip in ni.GetIPProperties().UnicastAddresses) + { + if (ip.Address.AddressFamily != AddressFamily.InterNetwork) continue; + var address = ip.Address; + if (IsValidHostAddress(address)) + { + return address; + } + } + } + + } + } + catch (System.Exception e) + { + _logger.Warning($"Failed to retriving network card ip address. cause:{e.Message}"); + } + _logger.Warning("Could not get local host ip address, will use 127.0.0.1 instead."); + return localAddress; + } + + } +} diff --git a/src/CanalSharp.Common/Utils/BooleanMutex.cs b/src/CanalSharp.Common/Utils/BooleanMutex.cs new file mode 100644 index 0000000..9d2fc93 --- /dev/null +++ b/src/CanalSharp.Common/Utils/BooleanMutex.cs @@ -0,0 +1,16 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Threading; + +namespace Canal.Csharp.Core.Common.Utils +{ + public class BooleanMutex + { + public void Set() + { + Mutex mutex =new Mutex(); + mutex.ReleaseMutex(); + } + } +} From dcc1edd8debcb3b267d21c6a38aa673ea5487ecc Mon Sep 17 00:00:00 2001 From: WithLin Date: Sat, 15 Sep 2018 13:05:09 +0800 Subject: [PATCH 24/50] Fix add d Sample Connector and add UnitTest --- .../Impl/SimpleCanalConnector.cs | 208 +++++++++++++++++- .../Running/Impl/ClientRunningMonitor.cs | 7 +- .../Alarm/ICanalAlarmHandler.cs | 11 +- .../Alarm/Impl/LogAlarmHandler.cs | 1 + src/CanalSharp.Common/Logging/ILogger.cs | 4 +- .../Logging/ILoggerFactory.cs | 2 +- src/CanalSharp.Common/Logging/LogManager.cs | 3 +- src/CanalSharp.Common/Logging/NullLogger.cs | 4 +- .../Logging/NullLoggerFactory.cs | 2 +- src/CanalSharp.Common/Utils/BooleanMutex.cs | 7 +- .../CanalSharp.UnitTests.csproj | 6 + test/CanalSharp.UnitTests/UnitTest1.cs | 9 +- 12 files changed, 234 insertions(+), 30 deletions(-) diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 4c65c8e..931943d 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -1,22 +1,120 @@ - -using System; +using System; +using System.Collections.Generic; +using System.Net; +using System.Threading.Tasks; +using CanalSharp.Common.Logging; using CanalSharp.Protocol; -using Microsoft.Extensions.Logging; +using CanalSharp.Protocol.Exception; +using Com.Alibaba.Otter.Canal.Protocol; +using DotNetty.Buffers; +using DotNetty.Codecs; +using DotNetty.Transport.Bootstrapping; +using DotNetty.Transport.Channels; +using DotNetty.Transport.Channels.Sockets; +using Google.Protobuf; + namespace CanalSharp.Client.Impl { - public class SimpleCanalConnector: ICanalConnector + public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector { - private ILogger _logger; + private readonly ILogger _logger = LogManager.GetLogger(typeof(SimpleCanalConnector)); + public string Address { get; set; } + public int Port { get; set; } + public string Username { get; set; } + public string Password { get; set; } + + /// + /// // milliseconds + /// + public int SoTimeout { get; set; } = 60000; + + /// + /// client和server之间的空闲链接超时的时间,默认为1小时 + /// + public int IdleTimeout { get; set; } = 60 * 60 * 1000; + + private ClientIdentity _clientIdentity; + /// + /// // 代表connected是否已正常执行,因为有HA,不代表在工作中 + /// + private volatile bool _connected = false; + + //private ClientRunningMonitor runningMonitor; + + private volatile bool _running = false; + /// + /// 记录上一次的filter提交值,便于自动重试时提交 + /// + private string _filter; + + private ISocketChannel _channel; + + private Task readableChannel; + + private IChannel writableChannel; + + private List supportedCompressions = new List(); + + private static readonly object _writeDataLock = new object(); + private static readonly object _readDataLock = new object(); + + - public SimpleCanalConnector(ILogger logger) + private IByteBuffer readHeader = Unpooled.Buffer(4); + private IByteBuffer writeHeader = Unpooled.Buffer(4); + + private IChannel _clientChannel; + + + + + public SimpleCanalConnector(string address, int port, string username, string password, string destination) : this(address, port, username, password, destination, 60000, 60 * 60 * 1000) { - _logger = logger; + } - public void Connect() + public SimpleCanalConnector(string address,int port, string username, string password, string destination, + int soTimeout) : this(address, port, username, password, destination, soTimeout, 60 * 60 * 1000) { - throw new NotImplementedException(); + } + + public SimpleCanalConnector(string address,int port, string username, string password, string destination, + int soTimeout, int idleTimeout) + { + Address = address; + Port = port; + Username = username; + Password = password; + SoTimeout = soTimeout; + IdleTimeout = idleTimeout; + _clientIdentity = new ClientIdentity(destination, (short)1001); + Environment.SetEnvironmentVariable("io.netty.allocator.maxOrder", "4"); + } + + public async void Connect() + { + if (_connected) + { + return; + } + + //WaitClientRunning(); + if (_running) + { + return; + } + + await DoConnect(); + //if (_filter != null) + //{ // 如果存在条件,说明是自动切换,基于上一次的条件订阅一次 + // subscribe(filter); + //} + //if (rollbackOnConnect) + //{ + // rollback(); + //} + _connected = true; } public void Disconnect() @@ -83,5 +181,95 @@ public void StopRunning() { throw new NotImplementedException(); } + private async Task DoConnect() + { + var group = new MultithreadEventLoopGroup(); + var bootstrap = new Bootstrap(); + bootstrap + .Group(group) + .Channel() + .Option(ChannelOption.SoTimeout, SoTimeout) + .Option(ChannelOption.TcpNodelay, true) + .Handler(new ActionChannelInitializer(channel => + { + IChannelPipeline pipeline = channel.Pipeline; + pipeline.AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())); + pipeline.AddLast(new StringEncoder(), new StringDecoder(), this); + })); + _clientChannel = await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(Address), Port)).ConfigureAwait(false); + _clientChannel.Read(); + } + + private void WaitClientRunning() + { + _running = true; + } + + + private void WriteWithHeader(IChannel channel, byte[] body) + { + lock (_writeDataLock) + { + writeHeader.Clear(); + writeHeader.WriteInt(body.Length); + channel.WriteAsync(writeHeader); + channel.WriteAsync(Unpooled.WrappedBuffer(body)); + } + } + private void WriteWithHeader(byte[] body) + { + WriteWithHeader(writableChannel, body); + } + + + public override void ChannelRead(IChannelHandlerContext context, object message) + { + var byteBuffer = message as IByteBuffer; + if (byteBuffer != null) + { + var p = Packet.Parser.ParseFrom(byteBuffer.Array); + if (p.Version != 1) + { + throw new CanalClientException("unsupported version at this client."); + } + + if (p.Type != PacketType.Handshake) + { + throw new CanalClientException("expect handshake but found other type."); + } + var handshake = Handshake.Parser.ParseFrom(p.Body); + supportedCompressions.Add(handshake.SupportedCompressions); + var ca = new ClientAuth() + { + Username = Username != null ? Username : "", + Password = ByteString.CopyFromUtf8(Password != null ? Password : ""), + NetReadTimeout = IdleTimeout, + NetWriteTimeout = IdleTimeout + }; + context.WriteAndFlushAsync(new Packet() + { + Type = PacketType.Clientauthentication, + Body = ca.ToByteString() + }.ToByteArray()); + + var ack = Packet.Parser.ParseFrom(byteBuffer.Array); + if (ack.Type != PacketType.Ack) + { + throw new CanalClientException("unexpected packet type when ack is expected"); + } + + + var ackBody = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(ack.Body); + if (ackBody.ErrorCode > 0) + { + throw new CanalClientException($"something goes wrong when doing authentication:{ackBody.ErrorMessage} "); + } + + _connected = true; + } + + } } -} \ No newline at end of file + + +} diff --git a/src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs b/src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs index f3c0efb..454e8b8 100644 --- a/src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs +++ b/src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; -using Canal.Csharp.Abstract.Common; +using CanalSharp.Common; -namespace Canal.Csharp.Core.Running +namespace CanalSharp.Client.Running.Impl { public class ClientRunningMonitor: AbstractCanalLifeCycle { diff --git a/src/CanalSharp.Common/Alarm/ICanalAlarmHandler.cs b/src/CanalSharp.Common/Alarm/ICanalAlarmHandler.cs index 1415a5a..a2fe73b 100644 --- a/src/CanalSharp.Common/Alarm/ICanalAlarmHandler.cs +++ b/src/CanalSharp.Common/Alarm/ICanalAlarmHandler.cs @@ -4,7 +4,16 @@ namespace CanalSharp.Common.Alarm { - interface ICanalAlarmHandler + /// + /// canal报警处理机制 + /// + public interface ICanalAlarmHandler { + /// + /// 发送对应destination的报警 + /// + /// + /// + void SendAlarm(string destination, string msg); } } diff --git a/src/CanalSharp.Common/Alarm/Impl/LogAlarmHandler.cs b/src/CanalSharp.Common/Alarm/Impl/LogAlarmHandler.cs index 7058690..af9b81a 100644 --- a/src/CanalSharp.Common/Alarm/Impl/LogAlarmHandler.cs +++ b/src/CanalSharp.Common/Alarm/Impl/LogAlarmHandler.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.Text; +using CanalSharp.Common.Logging; namespace CanalSharp.Common.Alarm.Impl { diff --git a/src/CanalSharp.Common/Logging/ILogger.cs b/src/CanalSharp.Common/Logging/ILogger.cs index eb88aa1..b0e2add 100644 --- a/src/CanalSharp.Common/Logging/ILogger.cs +++ b/src/CanalSharp.Common/Logging/ILogger.cs @@ -1,6 +1,6 @@ using System; -namespace Canal.Csharp.Abstract.Logging +namespace CanalSharp.Common.Logging { public interface ILogger { @@ -10,7 +10,7 @@ public interface ILogger void Warning(String message); - void Error(String message, Exception exception); + void Error(String message, System.Exception exception); void Trace(String message); } diff --git a/src/CanalSharp.Common/Logging/ILoggerFactory.cs b/src/CanalSharp.Common/Logging/ILoggerFactory.cs index 1549e49..7b9c938 100644 --- a/src/CanalSharp.Common/Logging/ILoggerFactory.cs +++ b/src/CanalSharp.Common/Logging/ILoggerFactory.cs @@ -1,6 +1,6 @@ using System; -namespace Canal.Csharp.Abstract.Logging +namespace CanalSharp.Common.Logging { public interface ILoggerFactory { diff --git a/src/CanalSharp.Common/Logging/LogManager.cs b/src/CanalSharp.Common/Logging/LogManager.cs index e93db62..2e03f16 100644 --- a/src/CanalSharp.Common/Logging/LogManager.cs +++ b/src/CanalSharp.Common/Logging/LogManager.cs @@ -1,7 +1,6 @@ using System; -using Servicecomb.Saga.Omega.Abstractions.Logging; -namespace Canal.Csharp.Abstract.Logging +namespace CanalSharp.Common.Logging { public static class LogManager { diff --git a/src/CanalSharp.Common/Logging/NullLogger.cs b/src/CanalSharp.Common/Logging/NullLogger.cs index 86861b8..80627ad 100644 --- a/src/CanalSharp.Common/Logging/NullLogger.cs +++ b/src/CanalSharp.Common/Logging/NullLogger.cs @@ -1,6 +1,6 @@ using System; -namespace Canal.Csharp.Abstract.Logging +namespace CanalSharp.Common.Logging { internal class NullLogger : ILogger { @@ -16,7 +16,7 @@ public void Warning(String message) { } - public void Error(String message, Exception exception) + public void Error(String message, System.Exception exception) { } diff --git a/src/CanalSharp.Common/Logging/NullLoggerFactory.cs b/src/CanalSharp.Common/Logging/NullLoggerFactory.cs index a5557b9..33cb92b 100644 --- a/src/CanalSharp.Common/Logging/NullLoggerFactory.cs +++ b/src/CanalSharp.Common/Logging/NullLoggerFactory.cs @@ -1,6 +1,6 @@ using System; -namespace Canal.Csharp.Abstract.Logging +namespace CanalSharp.Common.Logging { public class NullLoggerFactory : ILoggerFactory { diff --git a/src/CanalSharp.Common/Utils/BooleanMutex.cs b/src/CanalSharp.Common/Utils/BooleanMutex.cs index 9d2fc93..5ff3633 100644 --- a/src/CanalSharp.Common/Utils/BooleanMutex.cs +++ b/src/CanalSharp.Common/Utils/BooleanMutex.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Text; -using System.Threading; +using System.Threading; -namespace Canal.Csharp.Core.Common.Utils +namespace CanalSharp.Common.Utils { public class BooleanMutex { diff --git a/test/CanalSharp.UnitTests/CanalSharp.UnitTests.csproj b/test/CanalSharp.UnitTests/CanalSharp.UnitTests.csproj index 061aa24..1f4cadf 100644 --- a/test/CanalSharp.UnitTests/CanalSharp.UnitTests.csproj +++ b/test/CanalSharp.UnitTests/CanalSharp.UnitTests.csproj @@ -13,4 +13,10 @@
+ + + + + + diff --git a/test/CanalSharp.UnitTests/UnitTest1.cs b/test/CanalSharp.UnitTests/UnitTest1.cs index 4512f03..a179a09 100644 --- a/test/CanalSharp.UnitTests/UnitTest1.cs +++ b/test/CanalSharp.UnitTests/UnitTest1.cs @@ -1,4 +1,8 @@ using System; +using System.Net; +using CanalSharp.Client; +using CanalSharp.Client.Impl; +using CanalSharp.Common.Utils; using Xunit; namespace Canal4Net.UnitTests @@ -8,7 +12,10 @@ public class UnitTest1 [Fact] public void Test1() { - + string destination = "example"; + ICanalConnector connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); + connector.Connect(); + Console.Read(); } } } From efdd633d04b982157c54832570a6258f0f9fdaab Mon Sep 17 00:00:00 2001 From: WithLin Date: Sat, 15 Sep 2018 13:06:41 +0800 Subject: [PATCH 25/50] fix CI --- src/CanalSharp.Client/Impl/CanalConnectors.cs | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/CanalSharp.Client/Impl/CanalConnectors.cs diff --git a/src/CanalSharp.Client/Impl/CanalConnectors.cs b/src/CanalSharp.Client/Impl/CanalConnectors.cs new file mode 100644 index 0000000..23a0771 --- /dev/null +++ b/src/CanalSharp.Client/Impl/CanalConnectors.cs @@ -0,0 +1,27 @@ +using System.Net; +using Canal.Csharp.Core; + +namespace CanalSharp.Client.Impl +{ + public class CanalConnectors + { + /// + /// 创建单链接的客户端链接 + /// + /// + /// + /// + /// + /// + public static ICanalConnector NewSingleConnector(string address, int port, string destination, string username, + string password) + { + var canalConnector = new SimpleCanalConnector(address, port, username, password, destination) + { + SoTimeout = 60 * 1000, + IdleTimeout = 60 * 60 * 1000 + }; + return canalConnector; + } + } +} From 9b01208876953ccb77c258183a7817aaaa88db25 Mon Sep 17 00:00:00 2001 From: WithLin Date: Sat, 15 Sep 2018 13:11:41 +0800 Subject: [PATCH 26/50] Fix code style --- test/CanalSharp.UnitTests/UnitTest1.cs | 2 -- 1 file changed, 2 deletions(-) diff --git a/test/CanalSharp.UnitTests/UnitTest1.cs b/test/CanalSharp.UnitTests/UnitTest1.cs index a179a09..b2eedfd 100644 --- a/test/CanalSharp.UnitTests/UnitTest1.cs +++ b/test/CanalSharp.UnitTests/UnitTest1.cs @@ -1,8 +1,6 @@ using System; -using System.Net; using CanalSharp.Client; using CanalSharp.Client.Impl; -using CanalSharp.Common.Utils; using Xunit; namespace Canal4Net.UnitTests From 4ea376b192cd33888cbb278e04c4c3aba34d969c Mon Sep 17 00:00:00 2001 From: WithLin Date: Sun, 16 Sep 2018 16:31:48 +0800 Subject: [PATCH 27/50] Fix add implement Receive Message and Fix Proto3 bug --- src/CanalSharp.Client/ICanalConnector.cs | 2 +- src/CanalSharp.Client/Impl/CanalConnectors.cs | 5 +- .../Impl/SimpleCanalConnector.cs | 224 +++++++++++++----- src/CanalSharp.Protocol/CanalProtocol.cs | 13 +- src/CanalSharp.Protocol/Message.cs | 9 +- test/CanalSharp.UnitTests/UnitTest1.cs | 1 + 6 files changed, 186 insertions(+), 68 deletions(-) diff --git a/src/CanalSharp.Client/ICanalConnector.cs b/src/CanalSharp.Client/ICanalConnector.cs index 250e179..d1a12b7 100644 --- a/src/CanalSharp.Client/ICanalConnector.cs +++ b/src/CanalSharp.Client/ICanalConnector.cs @@ -84,7 +84,7 @@ public interface ICanalConnector /// /// /// - Message GetWithoutAck(int batchSize, long timeout, TimeSpan unit); + Message GetWithoutAck(int batchSize, long? timeout, int? unit); /// /// 进行 batch id 的确认。确认之后,小于等于此 batchId 的 Message 都会被确认。 diff --git a/src/CanalSharp.Client/Impl/CanalConnectors.cs b/src/CanalSharp.Client/Impl/CanalConnectors.cs index 23a0771..a123bb6 100644 --- a/src/CanalSharp.Client/Impl/CanalConnectors.cs +++ b/src/CanalSharp.Client/Impl/CanalConnectors.cs @@ -1,7 +1,4 @@ -using System.Net; -using Canal.Csharp.Core; - -namespace CanalSharp.Client.Impl +namespace CanalSharp.Client.Impl { public class CanalConnectors { diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 931943d..0d178d3 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -1,6 +1,9 @@ using System; using System.Collections.Generic; +using System.IO; +using System.Linq; using System.Net; +using System.Net.Sockets; using System.Threading.Tasks; using CanalSharp.Common.Logging; using CanalSharp.Protocol; @@ -8,8 +11,11 @@ using Com.Alibaba.Otter.Canal.Protocol; using DotNetty.Buffers; using DotNetty.Codecs; +using DotNetty.Codecs.Protobuf; +using DotNetty.Common.Utilities; using DotNetty.Transport.Bootstrapping; using DotNetty.Transport.Channels; +using DotNetty.Transport.Channels.Embedded; using DotNetty.Transport.Channels.Sockets; using Google.Protobuf; @@ -65,6 +71,12 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector private IChannel _clientChannel; + // 是否在connect链接成功后,自动执行rollback操作 + private bool _rollbackOnConnect = true; + + private Message _message; + // 是否自动化解析Entry对象,如果考虑最大化性能可以延后解析 + private bool _lazyParseEntry = false; @@ -73,13 +85,13 @@ public SimpleCanalConnector(string address, int port, string username, string pa } - public SimpleCanalConnector(string address,int port, string username, string password, string destination, + public SimpleCanalConnector(string address, int port, string username, string password, string destination, int soTimeout) : this(address, port, username, password, destination, soTimeout, 60 * 60 * 1000) { } - public SimpleCanalConnector(string address,int port, string username, string password, string destination, + public SimpleCanalConnector(string address, int port, string username, string password, string destination, int soTimeout, int idleTimeout) { Address = address; @@ -89,7 +101,7 @@ public SimpleCanalConnector(string address,int port, string username, string pas SoTimeout = soTimeout; IdleTimeout = idleTimeout; _clientIdentity = new ClientIdentity(destination, (short)1001); - Environment.SetEnvironmentVariable("io.netty.allocator.maxOrder", "4"); + //Environment.SetEnvironmentVariable("io.netty.allocator.maxOrder", "4"); } public async void Connect() @@ -106,14 +118,14 @@ public async void Connect() } await DoConnect(); - //if (_filter != null) - //{ // 如果存在条件,说明是自动切换,基于上一次的条件订阅一次 - // subscribe(filter); - //} - //if (rollbackOnConnect) - //{ - // rollback(); - //} + if (_filter != null) + { // 如果存在条件,说明是自动切换,基于上一次的条件订阅一次 + Subscribe(_filter); + } + if (_rollbackOnConnect) + { + Rollback(); + } _connected = true; } @@ -129,7 +141,40 @@ public bool CheckValid() public void Subscribe(string filter) { - throw new NotImplementedException(); + //waitClientRunning(); + if (!_running) + { + return; + } + + try + { + var pack = new Packet() + { + Type = PacketType.Subscription, + Body = new Sub() + { + Destination = _clientIdentity.Destination, + ClientId = _clientIdentity.ClientId.ToString(), + Filter = _filter != null ? _filter : "" + }.ToByteString() + }; + WriteWithHeader(_channel, pack.ToByteArray()); + + //Packet p = Packet.parseFrom(readNextPacket()); + //Ack ack = Ack.parseFrom(p.getBody()); + //if (ack.getErrorCode() > 0) + //{ + // throw new CanalClientException("failed to subscribe with reason: " + ack.getErrorMessage()); + //} + + _clientIdentity.Filter = filter; + } + catch (IOException e) + { + throw new CanalClientException(e.Message); + } + } public void Subscribe() @@ -144,7 +189,7 @@ public void UnSubscribe() public Message Get(int batchSize) { - throw new NotImplementedException(); + return GetWithoutAck(batchSize, null, null); } public Message Get(int batchSize, long timeout, TimeSpan unit) @@ -157,9 +202,47 @@ public Message GetWithoutAck(int batchSize) throw new NotImplementedException(); } - public Message GetWithoutAck(int batchSize, long timeout, TimeSpan unit) + public Message GetWithoutAck(int batchSize, long? timeout, int? unit) { - throw new NotImplementedException(); + //waitClientRunning(); + if (!_running) + { + return null; + } + + try + { + var size = (batchSize <= 0) ? 1000 : batchSize; + // -1代表不做timeout控制 + var time = (timeout == null || timeout < 0) ? -1 : timeout; + if (unit == null) + { + unit = 1; + } + var get = new Get() + { + AutoAck = false, + Destination = _clientIdentity.Destination, + ClientId = _clientIdentity.ClientId.ToString(), + FetchSize = size, + Timeout = (long)time, + Unit = (int)unit + }; + var packet = new Packet() + { + Type = PacketType.Get, + Body = get.ToByteString() + }.ToByteArray(); + + WriteWithHeader(_channel, packet); + + return _message; + + } + catch (IOException e) + { + throw e; + } } public void Ack(long batchId) @@ -190,14 +273,14 @@ private async Task DoConnect() .Channel() .Option(ChannelOption.SoTimeout, SoTimeout) .Option(ChannelOption.TcpNodelay, true) + .Option(ChannelOption.Allocator, UnpooledByteBufferAllocator.Default) .Handler(new ActionChannelInitializer(channel => { - IChannelPipeline pipeline = channel.Pipeline; - pipeline.AddLast(new DelimiterBasedFrameDecoder(8192, Delimiters.LineDelimiter())); - pipeline.AddLast(new StringEncoder(), new StringDecoder(), this); + var pipeline = channel.Pipeline; + pipeline.AddLast(nameof(SimpleCanalConnector), this); })); _clientChannel = await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(Address), Port)).ConfigureAwait(false); - _clientChannel.Read(); + } private void WaitClientRunning() @@ -213,9 +296,11 @@ private void WriteWithHeader(IChannel channel, byte[] body) writeHeader.Clear(); writeHeader.WriteInt(body.Length); channel.WriteAsync(writeHeader); - channel.WriteAsync(Unpooled.WrappedBuffer(body)); + channel.WriteAndFlushAsync(Unpooled.WrappedBuffer(body)).Wait(); + } } + private void WriteWithHeader(byte[] body) { WriteWithHeader(writableChannel, body); @@ -224,52 +309,81 @@ private void WriteWithHeader(byte[] body) public override void ChannelRead(IChannelHandlerContext context, object message) { - var byteBuffer = message as IByteBuffer; + var byteBuffer = (IByteBuffer)message; if (byteBuffer != null) { - var p = Packet.Parser.ParseFrom(byteBuffer.Array); - if (p.Version != 1) - { - throw new CanalClientException("unsupported version at this client."); - } - - if (p.Type != PacketType.Handshake) - { - throw new CanalClientException("expect handshake but found other type."); - } - var handshake = Handshake.Parser.ParseFrom(p.Body); - supportedCompressions.Add(handshake.SupportedCompressions); - var ca = new ClientAuth() - { - Username = Username != null ? Username : "", - Password = ByteString.CopyFromUtf8(Password != null ? Password : ""), - NetReadTimeout = IdleTimeout, - NetWriteTimeout = IdleTimeout - }; - context.WriteAndFlushAsync(new Packet() + var result = byteBuffer.Array.Slice(4, 2); + var p = Packet.Parser.ParseFrom(result); + switch (p.Type) { - Type = PacketType.Clientauthentication, - Body = ca.ToByteString() - }.ToByteArray()); - - var ack = Packet.Parser.ParseFrom(byteBuffer.Array); - if (ack.Type != PacketType.Ack) - { - throw new CanalClientException("unexpected packet type when ack is expected"); + case PacketType.Handshake when p.Version != 1: + throw new CanalClientException("unsupported version at this client."); + case PacketType.Handshake when p.Type != PacketType.Handshake: + throw new CanalClientException("expect handshake but found other type."); + case PacketType.Handshake: + var handshake = Handshake.Parser.ParseFrom(p.Body); + supportedCompressions.Add(handshake.SupportedCompressions); + + var ca = new ClientAuth() + { + Username = Username != null ? Username : "", + Password = ByteString.CopyFromUtf8(Password != null ? Password : ""), + NetReadTimeout = IdleTimeout, + NetWriteTimeout = IdleTimeout + }; + + WriteWithHeader(context.Channel, new Packet() + { + Type = PacketType.Clientauthentication, + Body = ca.ToByteString() + }.ToByteArray()); + break; + case PacketType.Ack when p.Type != PacketType.Ack: + throw new CanalClientException("unexpected packet type when ack is expected"); + case PacketType.Ack: + var ackBody = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); + if (ackBody.ErrorCode > 0) + { + throw new CanalClientException($"something goes wrong when doing authentication:{ackBody.ErrorMessage} "); + } + + break; + case PacketType.Messages when !p.Compression.Equals(Compression.None): + throw new CanalClientException("compression is not supported in this connector"); + //return msg; + case PacketType.Messages: + var messages = Messages.Parser.ParseFrom(p.Body); + var msg = new Message(messages.BatchId); + if (_lazyParseEntry) + { + // byteString + msg.RawEntries = messages.Messages_.ToList(); + } + else + { + foreach (ByteString byteString in messages.Messages_) + { + msg.Entries.Add(Entry.Parser.ParseFrom(byteString)); + } + } + + _message = msg; + break; } - var ackBody = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(ack.Body); - if (ackBody.ErrorCode > 0) - { - throw new CanalClientException($"something goes wrong when doing authentication:{ackBody.ErrorMessage} "); - } - _connected = true; } } + + public override void ChannelReadComplete(IChannelHandlerContext context) + { + + } } + + } diff --git a/src/CanalSharp.Protocol/CanalProtocol.cs b/src/CanalSharp.Protocol/CanalProtocol.cs index 5e67c62..9cfef05 100644 --- a/src/CanalSharp.Protocol/CanalProtocol.cs +++ b/src/CanalSharp.Protocol/CanalProtocol.cs @@ -5,6 +5,7 @@ #pragma warning disable 1591, 0612, 3021 #region Designer generated code +using System.Text; using pb = global::Google.Protobuf; using pbc = global::Google.Protobuf.Collections; using pbr = global::Google.Protobuf.Reflection; @@ -179,7 +180,7 @@ public Packet Clone() { public const int MagicNumberFieldNumber = 1; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int MagicNumber { - get { return magicNumberPresentCase_ == MagicNumberPresentOneofCase.MagicNumber ? (int) magicNumberPresent_ : 0; } + get { return magicNumberPresentCase_ == MagicNumberPresentOneofCase.MagicNumber ? (int) magicNumberPresent_ : 17; } set { magicNumberPresent_ = value; magicNumberPresentCase_ = MagicNumberPresentOneofCase.MagicNumber; @@ -190,7 +191,7 @@ public int MagicNumber { public const int VersionFieldNumber = 2; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int Version { - get { return versionPresentCase_ == VersionPresentOneofCase.Version ? (int) versionPresent_ : 0; } + get { return versionPresentCase_ == VersionPresentOneofCase.Version ? (int) versionPresent_ : 1; } set { versionPresent_ = value; versionPresentCase_ = VersionPresentOneofCase.Version; @@ -212,7 +213,7 @@ public int Version { public const int CompressionFieldNumber = 4; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Com.Alibaba.Otter.Canal.Protocol.Compression Compression { - get { return compressionPresentCase_ == CompressionPresentOneofCase.Compression ? (global::Com.Alibaba.Otter.Canal.Protocol.Compression) compressionPresent_ : 0; } + get { return compressionPresentCase_ == CompressionPresentOneofCase.Compression ? (global::Com.Alibaba.Otter.Canal.Protocol.Compression) compressionPresent_ : Compression.None; } set { compressionPresent_ = value; compressionPresentCase_ = CompressionPresentOneofCase.Compression; @@ -650,7 +651,7 @@ public Handshake Clone() { public const int CommunicationEncodingFieldNumber = 1; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public string CommunicationEncoding { - get { return communicationEncodingPresentCase_ == CommunicationEncodingPresentOneofCase.CommunicationEncoding ? (string) communicationEncodingPresent_ : ""; } + get { return communicationEncodingPresentCase_ == CommunicationEncodingPresentOneofCase.CommunicationEncoding ? (string) communicationEncodingPresent_ : Encoding.UTF8.ToString(); } set { communicationEncodingPresent_ = pb::ProtoPreconditions.CheckNotNull(value, "value"); communicationEncodingPresentCase_ = CommunicationEncodingPresentOneofCase.CommunicationEncoding; @@ -2057,7 +2058,7 @@ public int FetchSize { /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public long Timeout { - get { return timeoutPresentCase_ == TimeoutPresentOneofCase.Timeout ? (long) timeoutPresent_ : 0L; } + get { return timeoutPresentCase_ == TimeoutPresentOneofCase.Timeout ? (long) timeoutPresent_ : -1L; } set { timeoutPresent_ = value; timeoutPresentCase_ = TimeoutPresentOneofCase.Timeout; @@ -2071,7 +2072,7 @@ public long Timeout { /// [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int Unit { - get { return unitPresentCase_ == UnitPresentOneofCase.Unit ? (int) unitPresent_ : 0; } + get { return unitPresentCase_ == UnitPresentOneofCase.Unit ? (int) unitPresent_ : 2; } set { unitPresent_ = value; unitPresentCase_ = UnitPresentOneofCase.Unit; diff --git a/src/CanalSharp.Protocol/Message.cs b/src/CanalSharp.Protocol/Message.cs index e1d0d92..19a8ef9 100644 --- a/src/CanalSharp.Protocol/Message.cs +++ b/src/CanalSharp.Protocol/Message.cs @@ -21,16 +21,21 @@ public Message(long id, List entries) Entries = entries ?? new List(); Raw = false; } + + public Message(long id) + { + Id = id; + } public Message(long id, bool raw, object entries) { Id = id; if (raw) { - RawEntries = (List) (entries ?? new List()); + RawEntries = (List)(entries ?? new List()); } else { - Entries = (List) (entries ?? new List()); + Entries = (List)(entries ?? new List()); } } } diff --git a/test/CanalSharp.UnitTests/UnitTest1.cs b/test/CanalSharp.UnitTests/UnitTest1.cs index b2eedfd..5d683ab 100644 --- a/test/CanalSharp.UnitTests/UnitTest1.cs +++ b/test/CanalSharp.UnitTests/UnitTest1.cs @@ -1,4 +1,5 @@ using System; +using System.Net.Sockets; using CanalSharp.Client; using CanalSharp.Client.Impl; using Xunit; From 45b0ca91a6511d6d1f1e15ac25a596e71f6dc154 Mon Sep 17 00:00:00 2001 From: WithLin Date: Sun, 16 Sep 2018 16:53:04 +0800 Subject: [PATCH 28/50] Fix Protocal default value --- src/CanalSharp.Protocol/EntryProtocol.cs | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/CanalSharp.Protocol/EntryProtocol.cs b/src/CanalSharp.Protocol/EntryProtocol.cs index 067baa6..0ce0114 100644 --- a/src/CanalSharp.Protocol/EntryProtocol.cs +++ b/src/CanalSharp.Protocol/EntryProtocol.cs @@ -214,7 +214,7 @@ public Entry Clone() { public const int EntryTypeFieldNumber = 2; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Com.Alibaba.Otter.Canal.Protocol.EntryType EntryType { - get { return entryTypePresentCase_ == EntryTypePresentOneofCase.EntryType ? (global::Com.Alibaba.Otter.Canal.Protocol.EntryType) entryTypePresent_ : 0; } + get { return entryTypePresentCase_ == EntryTypePresentOneofCase.EntryType ? (global::Com.Alibaba.Otter.Canal.Protocol.EntryType) entryTypePresent_ : EntryType.Rowdata; } set { entryTypePresent_ = value; entryTypePresentCase_ = EntryTypePresentOneofCase.EntryType; @@ -449,7 +449,7 @@ public Header Clone() { public const int VersionFieldNumber = 1; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public int Version { - get { return versionPresentCase_ == VersionPresentOneofCase.Version ? (int) versionPresent_ : 0; } + get { return versionPresentCase_ == VersionPresentOneofCase.Version ? (int) versionPresent_ : 1; } set { versionPresent_ = value; versionPresentCase_ = VersionPresentOneofCase.Version; @@ -530,7 +530,7 @@ public long ExecuteTime { public const int SourceTypeFieldNumber = 7; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Com.Alibaba.Otter.Canal.Protocol.Type SourceType { - get { return sourceTypePresentCase_ == SourceTypePresentOneofCase.SourceType ? (global::Com.Alibaba.Otter.Canal.Protocol.Type) sourceTypePresent_ : 0; } + get { return sourceTypePresentCase_ == SourceTypePresentOneofCase.SourceType ? (global::Com.Alibaba.Otter.Canal.Protocol.Type) sourceTypePresent_ : Type.Mysql; } set { sourceTypePresent_ = value; sourceTypePresentCase_ = SourceTypePresentOneofCase.SourceType; @@ -583,7 +583,7 @@ public long EventLength { public const int EventTypeFieldNumber = 11; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Com.Alibaba.Otter.Canal.Protocol.EventType EventType { - get { return eventTypePresentCase_ == EventTypePresentOneofCase.EventType ? (global::Com.Alibaba.Otter.Canal.Protocol.EventType) eventTypePresent_ : 0; } + get { return eventTypePresentCase_ == EventTypePresentOneofCase.EventType ? (global::Com.Alibaba.Otter.Canal.Protocol.EventType) eventTypePresent_ : EventType.Update; } set { eventTypePresent_ = value; eventTypePresentCase_ = EventTypePresentOneofCase.EventType; @@ -1629,7 +1629,7 @@ public long TableId { public const int EventTypeFieldNumber = 2; [global::System.Diagnostics.DebuggerNonUserCodeAttribute] public global::Com.Alibaba.Otter.Canal.Protocol.EventType EventType { - get { return eventTypePresentCase_ == EventTypePresentOneofCase.EventType ? (global::Com.Alibaba.Otter.Canal.Protocol.EventType) eventTypePresent_ : 0; } + get { return eventTypePresentCase_ == EventTypePresentOneofCase.EventType ? (global::Com.Alibaba.Otter.Canal.Protocol.EventType) eventTypePresent_ : EventType.Update; } set { eventTypePresent_ = value; eventTypePresentCase_ = EventTypePresentOneofCase.EventType; From 2c0eb01937a1eebcfe8664b924e5a2fb517476e8 Mon Sep 17 00:00:00 2001 From: WithLin Date: Sun, 16 Sep 2018 21:42:16 +0800 Subject: [PATCH 29/50] Fix code style --- .../Impl/SimpleCanalConnector.cs | 31 ++++++++++++------- 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 0d178d3..b22997b 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -3,19 +3,15 @@ using System.IO; using System.Linq; using System.Net; -using System.Net.Sockets; using System.Threading.Tasks; using CanalSharp.Common.Logging; using CanalSharp.Protocol; using CanalSharp.Protocol.Exception; using Com.Alibaba.Otter.Canal.Protocol; using DotNetty.Buffers; -using DotNetty.Codecs; -using DotNetty.Codecs.Protobuf; using DotNetty.Common.Utilities; using DotNetty.Transport.Bootstrapping; using DotNetty.Transport.Channels; -using DotNetty.Transport.Channels.Embedded; using DotNetty.Transport.Channels.Sockets; using Google.Protobuf; @@ -70,6 +66,7 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector private IByteBuffer writeHeader = Unpooled.Buffer(4); private IChannel _clientChannel; + private IChannel _testChannel; // 是否在connect链接成功后,自动执行rollback操作 private bool _rollbackOnConnect = true; @@ -101,7 +98,6 @@ public SimpleCanalConnector(string address, int port, string username, string pa SoTimeout = soTimeout; IdleTimeout = idleTimeout; _clientIdentity = new ClientIdentity(destination, (short)1001); - //Environment.SetEnvironmentVariable("io.netty.allocator.maxOrder", "4"); } public async void Connect() @@ -122,10 +118,10 @@ public async void Connect() { // 如果存在条件,说明是自动切换,基于上一次的条件订阅一次 Subscribe(_filter); } - if (_rollbackOnConnect) - { - Rollback(); - } + //if (_rollbackOnConnect) + //{ + // Rollback(); + //} _connected = true; } @@ -279,8 +275,10 @@ private async Task DoConnect() var pipeline = channel.Pipeline; pipeline.AddLast(nameof(SimpleCanalConnector), this); })); - _clientChannel = await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(Address), Port)).ConfigureAwait(false); - + _clientChannel =await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(Address), Port)); + var _testChannel = _clientChannel; + _testChannel.Pipeline.Remove(this); + _testChannel.Pipeline.AddLast(new Test()); } private void WaitClientRunning() @@ -332,7 +330,7 @@ public override void ChannelRead(IChannelHandlerContext context, object message) NetWriteTimeout = IdleTimeout }; - WriteWithHeader(context.Channel, new Packet() + WriteWithHeader(_testChannel, new Packet() { Type = PacketType.Clientauthentication, Body = ca.ToByteString() @@ -383,6 +381,15 @@ public override void ChannelReadComplete(IChannelHandlerContext context) } } + public class Test : ChannelHandlerAdapter + { + public override void ChannelRead(IChannelHandlerContext context, object message) + { + + } + } + + From 3901dc31d8f95e07cd349f3f0e2265ac9b194ccb Mon Sep 17 00:00:00 2001 From: WithLin Date: Mon, 17 Sep 2018 00:01:11 +0800 Subject: [PATCH 30/50] Fix Down Data --- .../Impl/SimpleCanalConnector.cs | 71 ++++++++++++------- test/CanalSharp.UnitTests/UnitTest1.cs | 23 ++++++ 2 files changed, 67 insertions(+), 27 deletions(-) diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index b22997b..754e34a 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -3,6 +3,7 @@ using System.IO; using System.Linq; using System.Net; +using System.Threading; using System.Threading.Tasks; using CanalSharp.Common.Logging; using CanalSharp.Protocol; @@ -62,8 +63,8 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector - private IByteBuffer readHeader = Unpooled.Buffer(4); - private IByteBuffer writeHeader = Unpooled.Buffer(4); + private IByteBuffer readHeader = Unpooled.Buffer(1024); + private IByteBuffer writeHeader = Unpooled.Buffer(1024); private IChannel _clientChannel; private IChannel _testChannel; @@ -100,7 +101,7 @@ public SimpleCanalConnector(string address, int port, string username, string pa _clientIdentity = new ClientIdentity(destination, (short)1001); } - public async void Connect() + public void Connect() { if (_connected) { @@ -113,7 +114,7 @@ public async void Connect() return; } - await DoConnect(); + DoConnect().Wait(); if (_filter != null) { // 如果存在条件,说明是自动切换,基于上一次的条件订阅一次 Subscribe(_filter); @@ -195,20 +196,22 @@ public Message Get(int batchSize, long timeout, TimeSpan unit) public Message GetWithoutAck(int batchSize) { - throw new NotImplementedException(); + return GetWithoutAck(batchSize, null, null); } - public Message GetWithoutAck(int batchSize, long? timeout, int? unit) + public Message GetWithoutAck(int batchSize, long? timeout, int? unit) { //waitClientRunning(); - if (!_running) - { - return null; - } + //if (!_running) + //{ + // return null; + //} try { - var size = (batchSize <= 0) ? 1000 : batchSize; + lock (this) + { + var size = (batchSize <= 0) ? 1000 : batchSize; // -1代表不做timeout控制 var time = (timeout == null || timeout < 0) ? -1 : timeout; if (unit == null) @@ -230,10 +233,15 @@ public Message GetWithoutAck(int batchSize, long? timeout, int? unit) Body = get.ToByteString() }.ToByteArray(); - WriteWithHeader(_channel, packet); + WriteWithHeaderA(_clientChannel, packet); + Monitor.Wait(this); + } + + return _message; + } catch (IOException e) { @@ -269,17 +277,15 @@ private async Task DoConnect() .Channel() .Option(ChannelOption.SoTimeout, SoTimeout) .Option(ChannelOption.TcpNodelay, true) + .Option(ChannelOption.SoKeepalive, true) .Option(ChannelOption.Allocator, UnpooledByteBufferAllocator.Default) .Handler(new ActionChannelInitializer(channel => { var pipeline = channel.Pipeline; pipeline.AddLast(nameof(SimpleCanalConnector), this); })); - _clientChannel =await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(Address), Port)); - var _testChannel = _clientChannel; - _testChannel.Pipeline.Remove(this); - _testChannel.Pipeline.AddLast(new Test()); - } + _clientChannel =await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(Address), Port)).ConfigureAwait(false); + } private void WaitClientRunning() { @@ -299,6 +305,18 @@ private void WriteWithHeader(IChannel channel, byte[] body) } } + private void WriteWithHeaderA(IChannel channel, byte[] body) + { + lock (_writeDataLock) + { + readHeader.Clear(); + readHeader.WriteInt(body.Length); + channel.WriteAsync(readHeader); + channel.WriteAndFlushAsync(Unpooled.WrappedBuffer(body)).Wait(); + + } + } + private void WriteWithHeader(byte[] body) { WriteWithHeader(writableChannel, body); @@ -330,7 +348,7 @@ public override void ChannelRead(IChannelHandlerContext context, object message) NetWriteTimeout = IdleTimeout }; - WriteWithHeader(_testChannel, new Packet() + WriteWithHeader(_clientChannel, new Packet() { Type = PacketType.Clientauthentication, Body = ca.ToByteString() @@ -345,6 +363,7 @@ public override void ChannelRead(IChannelHandlerContext context, object message) throw new CanalClientException($"something goes wrong when doing authentication:{ackBody.ErrorMessage} "); } + new Thread(() => { GetWithoutAck(100, null, null); }).Start(); break; case PacketType.Messages when !p.Compression.Equals(Compression.None): throw new CanalClientException("compression is not supported in this connector"); @@ -365,7 +384,13 @@ public override void ChannelRead(IChannelHandlerContext context, object message) } } - _message = msg; + + lock (this) + { + _message = msg; + Monitor.Pulse(this); + } + break; } @@ -381,14 +406,6 @@ public override void ChannelReadComplete(IChannelHandlerContext context) } } - public class Test : ChannelHandlerAdapter - { - public override void ChannelRead(IChannelHandlerContext context, object message) - { - - } - } - diff --git a/test/CanalSharp.UnitTests/UnitTest1.cs b/test/CanalSharp.UnitTests/UnitTest1.cs index 5d683ab..dccd04b 100644 --- a/test/CanalSharp.UnitTests/UnitTest1.cs +++ b/test/CanalSharp.UnitTests/UnitTest1.cs @@ -1,5 +1,6 @@ using System; using System.Net.Sockets; +using System.Threading; using CanalSharp.Client; using CanalSharp.Client.Impl; using Xunit; @@ -8,6 +9,8 @@ namespace Canal4Net.UnitTests { public class UnitTest1 { + private string aa; + private static readonly object _lock = new object(); [Fact] public void Test1() { @@ -15,6 +18,26 @@ public void Test1() ICanalConnector connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); connector.Connect(); Console.Read(); + //lock (_lock) + //{ + // new Thread(Test).Start(); + // Monitor.Wait(_lock); + // Console.WriteLine(aa); + // Console.Read(); + //} + + } + + + public void Test() + { + lock (_lock) + { + Thread.Sleep(500); + aa = "aaaaa"; + Monitor.Pulse(_lock); + } + } } } From 44a4b5b690c578e5805bb56ae2297d879ae07499 Mon Sep 17 00:00:00 2001 From: stulzq Date: Mon, 17 Sep 2018 22:44:44 +0800 Subject: [PATCH 31/50] add sample project --- CanalSharp.sln | 17 +++++++++++++---- .../CanalSharp.SimpleClient.csproj | 12 ++++++++++++ sample/CanalSharp.SimpleClient/Program.cs | 17 +++++++++++++++++ 3 files changed, 42 insertions(+), 4 deletions(-) create mode 100644 sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj create mode 100644 sample/CanalSharp.SimpleClient/Program.cs diff --git a/CanalSharp.sln b/CanalSharp.sln index 436f9a4..71e205c 100644 --- a/CanalSharp.sln +++ b/CanalSharp.sln @@ -3,7 +3,7 @@ Microsoft Visual Studio Solution File, Format Version 12.00 # Visual Studio 15 VisualStudioVersion = 15.0.27703.2026 MinimumVisualStudioVersion = 10.0.40219.1 -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{9F45639B-A9FA-4F6A-94EC-0D251FA3285D}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01 Solution Items", "01 Solution Items", "{9F45639B-A9FA-4F6A-94EC-0D251FA3285D}" ProjectSection(SolutionItems) = preProject .gitignore = .gitignore build\common.props = build\common.props @@ -12,9 +12,9 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution build\version.props = build\version.props EndProjectSection EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{BD70CDB7-94E9-4621-B702-DC04DB9D59EF}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03 test", "03 test", "{BD70CDB7-94E9-4621-B702-DC04DB9D59EF}" EndProject -Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}" +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02 src", "02 src", "{4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}" EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.UnitTests", "test\CanalSharp.UnitTests\CanalSharp.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}" EndProject @@ -22,7 +22,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Client", "src\Ca EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Protocol", "src\CanalSharp.Protocol\CanalSharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}" EndProject -Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CanalSharp.Common", "src\CanalSharp.Common\CanalSharp.Common.csproj", "{B583684C-4E2F-42A5-8F08-1E3C4EE4C586}" +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Common", "src\CanalSharp.Common\CanalSharp.Common.csproj", "{B583684C-4E2F-42A5-8F08-1E3C4EE4C586}" +EndProject +Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "04 sample", "04 sample", "{A4650FA0-4725-4956-90D3-F462F3C7474F}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CanalSharp.SimpleClient", "sample\CanalSharp.SimpleClient\CanalSharp.SimpleClient.csproj", "{CE9C0E45-F613-4E28-89EE-7F646B028BFB}" EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution @@ -46,6 +50,10 @@ Global {B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Debug|Any CPU.Build.0 = Debug|Any CPU {B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Release|Any CPU.ActiveCfg = Release|Any CPU {B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Release|Any CPU.Build.0 = Release|Any CPU + {CE9C0E45-F613-4E28-89EE-7F646B028BFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {CE9C0E45-F613-4E28-89EE-7F646B028BFB}.Debug|Any CPU.Build.0 = Debug|Any CPU + {CE9C0E45-F613-4E28-89EE-7F646B028BFB}.Release|Any CPU.ActiveCfg = Release|Any CPU + {CE9C0E45-F613-4E28-89EE-7F646B028BFB}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -55,6 +63,7 @@ Global {E33BCF38-D450-4AFE-B409-E6E7C0251479} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} {B9782080-16BD-4328-A394-3EC8D9B49326} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} {B583684C-4E2F-42A5-8F08-1E3C4EE4C586} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910} + {CE9C0E45-F613-4E28-89EE-7F646B028BFB} = {A4650FA0-4725-4956-90D3-F462F3C7474F} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {FD9B9146-8418-4F80-A666-9B47BE4F9C9C} diff --git a/sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj b/sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj new file mode 100644 index 0000000..b833b03 --- /dev/null +++ b/sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj @@ -0,0 +1,12 @@ + + + + Exe + netcoreapp2.1 + + + + + + + diff --git a/sample/CanalSharp.SimpleClient/Program.cs b/sample/CanalSharp.SimpleClient/Program.cs new file mode 100644 index 0000000..ee9cb19 --- /dev/null +++ b/sample/CanalSharp.SimpleClient/Program.cs @@ -0,0 +1,17 @@ +using System; +using CanalSharp.Client; +using CanalSharp.Client.Impl; + +namespace CanalSharp.SimpleClient +{ + class Program + { + static void Main(string[] args) + { + string destination = "example"; + ICanalConnector connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); + connector.Connect(); + Console.Read(); + } + } +} From d40459ec4beaa96518281a0e6ebf9b01f0a38b3e Mon Sep 17 00:00:00 2001 From: stulzq Date: Mon, 17 Sep 2018 22:54:28 +0800 Subject: [PATCH 32/50] Add read valid data logic --- .../Impl/SimpleCanalConnector.cs | 48 ++++++++++++++++--- 1 file changed, 42 insertions(+), 6 deletions(-) diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 754e34a..a1cad33 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -1,5 +1,6 @@ using System; using System.Collections.Generic; +using System.Diagnostics.Contracts; using System.IO; using System.Linq; using System.Net; @@ -10,6 +11,7 @@ using CanalSharp.Protocol.Exception; using Com.Alibaba.Otter.Canal.Protocol; using DotNetty.Buffers; +using DotNetty.Codecs; using DotNetty.Common.Utilities; using DotNetty.Transport.Bootstrapping; using DotNetty.Transport.Channels; @@ -325,11 +327,36 @@ private void WriteWithHeader(byte[] body) public override void ChannelRead(IChannelHandlerContext context, object message) { + var byteBuffer = (IByteBuffer)message; - if (byteBuffer != null) + if (byteBuffer == null) { - var result = byteBuffer.Array.Slice(4, 2); - var p = Packet.Parser.ParseFrom(result); + return; + } + int length = byteBuffer.ReadableBytes; + if (length <= 0) + { + return; + } + + Stream inputStream = null; + try + { + CodedInputStream codedInputStream; + if (byteBuffer.IoBufferCount == 1) + { + + var len = byteBuffer.GetInt(0); + byteBuffer.SetReaderIndex(4); + ArraySegment bytes = byteBuffer.GetIoBuffer(byteBuffer.ReaderIndex, len); + codedInputStream = new CodedInputStream(bytes.Array, bytes.Offset, len); + } + else + { + inputStream = new ReadOnlyByteBufferStream(byteBuffer, false); + codedInputStream = new CodedInputStream(inputStream); + } + var p = Packet.Parser.ParseFrom(codedInputStream); switch (p.Type) { case PacketType.Handshake when p.Version != 1: @@ -363,7 +390,7 @@ public override void ChannelRead(IChannelHandlerContext context, object message) throw new CanalClientException($"something goes wrong when doing authentication:{ackBody.ErrorMessage} "); } - new Thread(() => { GetWithoutAck(100, null, null); }).Start(); + new Thread(() => { GetWithoutAck(100, null, null); }).Start(); break; case PacketType.Messages when !p.Compression.Equals(Compression.None): throw new CanalClientException("compression is not supported in this connector"); @@ -384,19 +411,28 @@ public override void ChannelRead(IChannelHandlerContext context, object message) } } - + lock (this) { _message = msg; Monitor.Pulse(this); } - + break; } _connected = true; } + catch (Exception exception) + { + throw new CodecException(exception); + } + finally + { + inputStream?.Dispose(); + } + } From a1666f57e87f2942dadf4e98eb5e7c0edcedd09a Mon Sep 17 00:00:00 2001 From: stulzq Date: Mon, 17 Sep 2018 23:25:17 +0800 Subject: [PATCH 33/50] Remove redundant files --- .../Running}/ClientRunningMonitor.cs | 2 +- .../Running/IClientRunningListener.cs | 17 ----------------- .../Running/Impl/ClientRunningData.cs | 9 --------- 3 files changed, 1 insertion(+), 27 deletions(-) rename src/CanalSharp.Client/{Running/Impl => Impl/Running}/ClientRunningMonitor.cs (72%) delete mode 100644 src/CanalSharp.Client/Running/IClientRunningListener.cs delete mode 100644 src/CanalSharp.Client/Running/Impl/ClientRunningData.cs diff --git a/src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs b/src/CanalSharp.Client/Impl/Running/ClientRunningMonitor.cs similarity index 72% rename from src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs rename to src/CanalSharp.Client/Impl/Running/ClientRunningMonitor.cs index 454e8b8..90202dc 100644 --- a/src/CanalSharp.Client/Running/Impl/ClientRunningMonitor.cs +++ b/src/CanalSharp.Client/Impl/Running/ClientRunningMonitor.cs @@ -1,6 +1,6 @@ using CanalSharp.Common; -namespace CanalSharp.Client.Running.Impl +namespace CanalSharp.Client.Impl.Running { public class ClientRunningMonitor: AbstractCanalLifeCycle { diff --git a/src/CanalSharp.Client/Running/IClientRunningListener.cs b/src/CanalSharp.Client/Running/IClientRunningListener.cs deleted file mode 100644 index 1c35347..0000000 --- a/src/CanalSharp.Client/Running/IClientRunningListener.cs +++ /dev/null @@ -1,17 +0,0 @@ -using System.Net; - -namespace CanalSharp.Client.Running -{ - public interface IClientRunningListener - { - /** - * 触发现在轮到自己做为active,需要载入上一个active的上下文数据 - */ - SocketAddress ProcessActiveEnter(); - - /** - * 触发一下当前active模式失败 - */ - void ProcessActiveExit(); - } -} diff --git a/src/CanalSharp.Client/Running/Impl/ClientRunningData.cs b/src/CanalSharp.Client/Running/Impl/ClientRunningData.cs deleted file mode 100644 index 55343f4..0000000 --- a/src/CanalSharp.Client/Running/Impl/ClientRunningData.cs +++ /dev/null @@ -1,9 +0,0 @@ -namespace CanalSharp.Client.Running.Impl -{ - public class ClientRunningData - { - public short ClientId { get; set; } - public string Address { get; set; } - public bool Active { get; set; } = true; - } -} From 0f4783542949dfa1fbfabdc1a8f8d4e9357a25f3 Mon Sep 17 00:00:00 2001 From: WithLin Date: Tue, 18 Sep 2018 17:53:46 +0800 Subject: [PATCH 34/50] Fix impl Connect Subscribe --- src/CanalSharp.Client/ICanalConnector.cs | 7 +- .../Impl/SimpleCanalConnector.cs | 321 +++++++----------- 2 files changed, 126 insertions(+), 202 deletions(-) diff --git a/src/CanalSharp.Client/ICanalConnector.cs b/src/CanalSharp.Client/ICanalConnector.cs index d1a12b7..d630107 100644 --- a/src/CanalSharp.Client/ICanalConnector.cs +++ b/src/CanalSharp.Client/ICanalConnector.cs @@ -1,4 +1,5 @@ using System; +using System.Threading.Tasks; using CanalSharp.Protocol; namespace CanalSharp.Client @@ -8,7 +9,7 @@ public interface ICanalConnector /// /// 链接对应的canal server /// - void Connect(); + Task Connect(); /// /// 释放链接 @@ -34,12 +35,12 @@ public interface ICanalConnector /// /// /// TODO: 后续可以考虑,如果本次提交的filter不为空,在执行过滤时,是对canal server filter + 本次filter的交集处理,达到只取1份binlog数据,多个客户端消费不同的表 - void Subscribe(string filter); + Task Subscribe(string filter); /// /// 客户端订阅,不提交客户端filter,以服务端的filter为准 /// - void Subscribe(); + Task Subscribe(); /// /// 取消订阅 diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index a1cad33..620fcf3 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -1,9 +1,7 @@ using System; using System.Collections.Generic; -using System.Diagnostics.Contracts; using System.IO; -using System.Linq; -using System.Net; +using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; using CanalSharp.Common.Logging; @@ -11,9 +9,6 @@ using CanalSharp.Protocol.Exception; using Com.Alibaba.Otter.Canal.Protocol; using DotNetty.Buffers; -using DotNetty.Codecs; -using DotNetty.Common.Utilities; -using DotNetty.Transport.Bootstrapping; using DotNetty.Transport.Channels; using DotNetty.Transport.Channels.Sockets; using Google.Protobuf; @@ -65,8 +60,8 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector - private IByteBuffer readHeader = Unpooled.Buffer(1024); - private IByteBuffer writeHeader = Unpooled.Buffer(1024); + private IByteBuffer readHeader = Unpooled.Buffer(10240); + private IByteBuffer writeHeader = Unpooled.Buffer(10240); private IChannel _clientChannel; private IChannel _testChannel; @@ -78,6 +73,9 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector // 是否自动化解析Entry对象,如果考虑最大化性能可以延后解析 private bool _lazyParseEntry = false; + private TcpClient _tcpClient; + private NetworkStream _channelNetworkStream; + public SimpleCanalConnector(string address, int port, string username, string password, string destination) : this(address, port, username, password, destination, 60000, 60 * 60 * 1000) @@ -103,7 +101,7 @@ public SimpleCanalConnector(string address, int port, string username, string pa _clientIdentity = new ClientIdentity(destination, (short)1001); } - public void Connect() + public async Task Connect() { if (_connected) { @@ -116,10 +114,10 @@ public void Connect() return; } - DoConnect().Wait(); + await DoConnect(); if (_filter != null) { // 如果存在条件,说明是自动切换,基于上一次的条件订阅一次 - Subscribe(_filter); + await Subscribe(_filter); } //if (_rollbackOnConnect) //{ @@ -138,9 +136,9 @@ public bool CheckValid() throw new NotImplementedException(); } - public void Subscribe(string filter) + public async Task Subscribe(string filter) { - //waitClientRunning(); + //WaitClientRunning(); if (!_running) { return; @@ -157,28 +155,29 @@ public void Subscribe(string filter) ClientId = _clientIdentity.ClientId.ToString(), Filter = _filter != null ? _filter : "" }.ToByteString() - }; - WriteWithHeader(_channel, pack.ToByteArray()); + }.ToByteArray(); - //Packet p = Packet.parseFrom(readNextPacket()); - //Ack ack = Ack.parseFrom(p.getBody()); - //if (ack.getErrorCode() > 0) - //{ - // throw new CanalClientException("failed to subscribe with reason: " + ack.getErrorMessage()); - //} + await WriteWithHeader(pack); + + var p = Packet.Parser.ParseFrom(ReadNextPacket()); + var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); + if (ack.ErrorCode > 0) + { + throw new CanalClientException($"failed to subscribe with reason: {ack.ErrorMessage}"); + } _clientIdentity.Filter = filter; } - catch (IOException e) + catch (Exception e) { throw new CanalClientException(e.Message); } } - public void Subscribe() + public async Task Subscribe() { - throw new NotImplementedException(); + await Subscribe(""); } public void UnSubscribe() @@ -198,10 +197,10 @@ public Message Get(int batchSize, long timeout, TimeSpan unit) public Message GetWithoutAck(int batchSize) { - return GetWithoutAck(batchSize, null, null); + return GetWithoutAck(batchSize, null, null); } - public Message GetWithoutAck(int batchSize, long? timeout, int? unit) + public Message GetWithoutAck(int batchSize, long? timeout, int? unit) { //waitClientRunning(); //if (!_running) @@ -214,29 +213,29 @@ public Message GetWithoutAck(int batchSize, long? timeout, int? unit) lock (this) { var size = (batchSize <= 0) ? 1000 : batchSize; - // -1代表不做timeout控制 - var time = (timeout == null || timeout < 0) ? -1 : timeout; - if (unit == null) - { - unit = 1; - } - var get = new Get() - { - AutoAck = false, - Destination = _clientIdentity.Destination, - ClientId = _clientIdentity.ClientId.ToString(), - FetchSize = size, - Timeout = (long)time, - Unit = (int)unit - }; - var packet = new Packet() - { - Type = PacketType.Get, - Body = get.ToByteString() - }.ToByteArray(); + // -1代表不做timeout控制 + var time = (timeout == null || timeout < 0) ? -1 : timeout; + if (unit == null) + { + unit = 1; + } + var get = new Get() + { + AutoAck = false, + Destination = _clientIdentity.Destination, + ClientId = _clientIdentity.ClientId.ToString(), + FetchSize = size, + Timeout = (long)time, + Unit = (int)unit + }; + var packet = new Packet() + { + Type = PacketType.Get, + Body = get.ToByteString() + }.ToByteArray(); - WriteWithHeaderA(_clientChannel, packet); - Monitor.Wait(this); + //WriteWithHeaderA(_clientChannel, packet); + Monitor.Wait(this); } @@ -272,178 +271,102 @@ public void StopRunning() } private async Task DoConnect() { - var group = new MultithreadEventLoopGroup(); - var bootstrap = new Bootstrap(); - bootstrap - .Group(group) - .Channel() - .Option(ChannelOption.SoTimeout, SoTimeout) - .Option(ChannelOption.TcpNodelay, true) - .Option(ChannelOption.SoKeepalive, true) - .Option(ChannelOption.Allocator, UnpooledByteBufferAllocator.Default) - .Handler(new ActionChannelInitializer(channel => - { - var pipeline = channel.Pipeline; - pipeline.AddLast(nameof(SimpleCanalConnector), this); - })); - _clientChannel =await bootstrap.ConnectAsync(new IPEndPoint(IPAddress.Parse(Address), Port)).ConfigureAwait(false); - } - - private void WaitClientRunning() - { - _running = true; - } - - - private void WriteWithHeader(IChannel channel, byte[] body) - { - lock (_writeDataLock) + try { - writeHeader.Clear(); - writeHeader.WriteInt(body.Length); - channel.WriteAsync(writeHeader); - channel.WriteAndFlushAsync(Unpooled.WrappedBuffer(body)).Wait(); + _tcpClient = new TcpClient(Address, Port); + _channelNetworkStream = _tcpClient.GetStream(); + var p = Packet.Parser.ParseFrom(ReadNextPacket()); + if (p != null) + { + if (p.Version != 1) + { + throw new CanalClientException("unsupported version at this client."); + } + if (p.Type != PacketType.Handshake) + { + throw new CanalClientException("expect handshake but found other type."); + } + var handshake = Handshake.Parser.ParseFrom(p.Body); + supportedCompressions.Add(handshake.SupportedCompressions); - } - } + var ca = new ClientAuth() + { + Username = Username != null ? Username : "", + Password = ByteString.CopyFromUtf8(Password != null ? Password : ""), + NetReadTimeout = IdleTimeout, + NetWriteTimeout = IdleTimeout + }; - private void WriteWithHeaderA(IChannel channel, byte[] body) - { - lock (_writeDataLock) - { - readHeader.Clear(); - readHeader.WriteInt(body.Length); - channel.WriteAsync(readHeader); - channel.WriteAndFlushAsync(Unpooled.WrappedBuffer(body)).Wait(); + var packArray = new Packet() + { + Type = PacketType.Clientauthentication, + Body = ca.ToByteString() + }.ToByteArray(); - } - } + await WriteWithHeader(packArray); - private void WriteWithHeader(byte[] body) - { - WriteWithHeader(writableChannel, body); - } + var packet = Packet.Parser.ParseFrom(ReadNextPacket()); + if (packet.Type != PacketType.Ack) + { + throw new CanalClientException("unexpected packet type when ack is expected"); + } + var ackBody = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); + if (ackBody.ErrorCode > 0) + { + throw new CanalClientException("something goes wrong when doing authentication:" + ackBody.ErrorMessage); + } - public override void ChannelRead(IChannelHandlerContext context, object message) - { - - var byteBuffer = (IByteBuffer)message; - if (byteBuffer == null) - { - return; + _connected = _tcpClient.Connected; + } } - int length = byteBuffer.ReadableBytes; - if (length <= 0) + catch (Exception e) { - return; + throw e; } - Stream inputStream = null; - try - { - CodedInputStream codedInputStream; - if (byteBuffer.IoBufferCount == 1) - { - - var len = byteBuffer.GetInt(0); - byteBuffer.SetReaderIndex(4); - ArraySegment bytes = byteBuffer.GetIoBuffer(byteBuffer.ReaderIndex, len); - codedInputStream = new CodedInputStream(bytes.Array, bytes.Offset, len); - } - else - { - inputStream = new ReadOnlyByteBufferStream(byteBuffer, false); - codedInputStream = new CodedInputStream(inputStream); - } - var p = Packet.Parser.ParseFrom(codedInputStream); - switch (p.Type) - { - case PacketType.Handshake when p.Version != 1: - throw new CanalClientException("unsupported version at this client."); - case PacketType.Handshake when p.Type != PacketType.Handshake: - throw new CanalClientException("expect handshake but found other type."); - case PacketType.Handshake: - var handshake = Handshake.Parser.ParseFrom(p.Body); - supportedCompressions.Add(handshake.SupportedCompressions); - - var ca = new ClientAuth() - { - Username = Username != null ? Username : "", - Password = ByteString.CopyFromUtf8(Password != null ? Password : ""), - NetReadTimeout = IdleTimeout, - NetWriteTimeout = IdleTimeout - }; - - WriteWithHeader(_clientChannel, new Packet() - { - Type = PacketType.Clientauthentication, - Body = ca.ToByteString() - }.ToByteArray()); - break; - case PacketType.Ack when p.Type != PacketType.Ack: - throw new CanalClientException("unexpected packet type when ack is expected"); - case PacketType.Ack: - var ackBody = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); - if (ackBody.ErrorCode > 0) - { - throw new CanalClientException($"something goes wrong when doing authentication:{ackBody.ErrorMessage} "); - } - - new Thread(() => { GetWithoutAck(100, null, null); }).Start(); - break; - case PacketType.Messages when !p.Compression.Equals(Compression.None): - throw new CanalClientException("compression is not supported in this connector"); - //return msg; - case PacketType.Messages: - var messages = Messages.Parser.ParseFrom(p.Body); - var msg = new Message(messages.BatchId); - if (_lazyParseEntry) - { - // byteString - msg.RawEntries = messages.Messages_.ToList(); - } - else - { - foreach (ByteString byteString in messages.Messages_) - { - msg.Entries.Add(Entry.Parser.ParseFrom(byteString)); - } - } - - - lock (this) - { - _message = msg; - Monitor.Pulse(this); - } - - break; - } + } - _connected = true; - } - catch (Exception exception) - { - throw new CodecException(exception); - } - finally + + private byte[] ReadNextPacket() + { + lock (_readDataLock) { - inputStream?.Dispose(); + var headerLength = ReadHeaderLength(); + var recevieData = new byte[headerLength]; + _channelNetworkStream.Read(recevieData, 0, recevieData.Length); + return recevieData; } - - } - public override void ChannelReadComplete(IChannelHandlerContext context) + private int ReadHeaderLength() { - + var headerBytes = new byte[4]; + _channelNetworkStream.Read(headerBytes, 0, 4); + Array.Reverse(headerBytes); + return BitConverter.ToInt32(headerBytes, 0); + } + private async Task WriteWithHeader(byte[] body) + { + var len = body.Length; + var bytes = GetHeaderBytes(len); + await _channelNetworkStream.WriteAsync(bytes, 0, bytes.Length); + await _channelNetworkStream.WriteAsync(body, 0, body.Length); } - } - + private byte[] GetHeaderBytes(int lenth) + { + var data = BitConverter.GetBytes(lenth); + Array.Reverse(data); + return data; + } + private void WaitClientRunning() + { + _running = true; + } + } } From da15545c99256e7266ba5330f6589a83968ccf7a Mon Sep 17 00:00:00 2001 From: WithLin Date: Tue, 18 Sep 2018 18:33:16 +0800 Subject: [PATCH 35/50] add sample --- .../CanalSharp.SimpleClient.csproj | 1 + sample/CanalSharp.SimpleClient/Program.cs | 73 +++++++++++++- .../Impl/SimpleCanalConnector.cs | 95 +++++++++++++------ src/CanalSharp.Protocol/Message.cs | 1 + 4 files changed, 139 insertions(+), 31 deletions(-) diff --git a/sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj b/sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj index b833b03..f2d4469 100644 --- a/sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj +++ b/sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj @@ -7,6 +7,7 @@ + diff --git a/sample/CanalSharp.SimpleClient/Program.cs b/sample/CanalSharp.SimpleClient/Program.cs index ee9cb19..c1812a3 100644 --- a/sample/CanalSharp.SimpleClient/Program.cs +++ b/sample/CanalSharp.SimpleClient/Program.cs @@ -1,6 +1,10 @@ using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading; using CanalSharp.Client; using CanalSharp.Client.Impl; +using Com.Alibaba.Otter.Canal.Protocol; namespace CanalSharp.SimpleClient { @@ -8,10 +12,73 @@ class Program { static void Main(string[] args) { - string destination = "example"; - ICanalConnector connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); + var destination = "example"; + var connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); connector.Connect(); - Console.Read(); + connector.Subscribe(); + while (true) + { + var message = connector.Get(100); + var batchId = message.Id; + if (batchId == -1 || message.Entries.Count<=0) + { + Thread.Sleep(300); + } + PrintEntry(message.Entries); + } + } + + private static void PrintEntry(List entrys) + { + foreach (var entry in entrys) + { + if (entry.EntryType == EntryType.Transactionbegin || entry.EntryType == EntryType.Transactionend) + { + continue; + } + + RowChange rowChange = null; + + try + { + rowChange = RowChange.Parser.ParseFrom(entry.StoreValue); + } + catch (Exception e) + { + + } + + EventType eventType = rowChange.EventType; + Console.WriteLine( + $"================> binlog[{entry.Header.LogfileName}:{entry.Header.LogfileOffset}] , name[{entry.Header.SchemaName},{entry.Header.TableName}] , eventType :{eventType}"); + + foreach (var rowData in rowChange.RowDatas) + { + if (eventType == EventType.Delete) + { + PrintColumn(rowData.BeforeColumns.ToList()); + } + else if (eventType == EventType.Insert) + { + PrintColumn(rowData.BeforeColumns.ToList()); + } + else + { + Console.WriteLine("-------> before"); + PrintColumn(rowData.BeforeColumns.ToList()); + Console.WriteLine("-------> after"); + PrintColumn(rowData.AfterColumns.ToList()); + } + } + } + } + + private static void PrintColumn(List columns) + { + foreach (var column in columns) + { + Console.WriteLine($"{column.Name} : {column.Value} update= {column.Updated}"); + } } } } diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 620fcf3..74dc04c 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -1,6 +1,7 @@ using System; using System.Collections.Generic; using System.IO; +using System.Linq; using System.Net.Sockets; using System.Threading; using System.Threading.Tasks; @@ -117,7 +118,7 @@ public async Task Connect() await DoConnect(); if (_filter != null) { // 如果存在条件,说明是自动切换,基于上一次的条件订阅一次 - await Subscribe(_filter); + await Subscribe(_filter); } //if (_rollbackOnConnect) //{ @@ -175,7 +176,7 @@ public async Task Subscribe(string filter) } - public async Task Subscribe() + public async Task Subscribe() { await Subscribe(""); } @@ -210,37 +211,33 @@ public Message GetWithoutAck(int batchSize, long? timeout, int? unit) try { - lock (this) + var size = (batchSize <= 0) ? 1000 : batchSize; + // -1代表不做timeout控制 + var time = (timeout == null || timeout < 0) ? -1 : timeout; + if (unit == null) { - var size = (batchSize <= 0) ? 1000 : batchSize; - // -1代表不做timeout控制 - var time = (timeout == null || timeout < 0) ? -1 : timeout; - if (unit == null) - { - unit = 1; - } - var get = new Get() - { - AutoAck = false, - Destination = _clientIdentity.Destination, - ClientId = _clientIdentity.ClientId.ToString(), - FetchSize = size, - Timeout = (long)time, - Unit = (int)unit - }; - var packet = new Packet() - { - Type = PacketType.Get, - Body = get.ToByteString() - }.ToByteArray(); - - //WriteWithHeaderA(_clientChannel, packet); - Monitor.Wait(this); + unit = 1; } + var get = new Get() + { + AutoAck = false, + Destination = _clientIdentity.Destination, + ClientId = _clientIdentity.ClientId.ToString(), + FetchSize = size, + Timeout = (long)time, + Unit = (int)unit + }; + var packet = new Packet() + { + Type = PacketType.Get, + Body = get.ToByteString() + }.ToByteArray(); + WriteWithHeader(packet).Wait(); - return _message; + + return ReceiveMessages(); } @@ -250,6 +247,48 @@ public Message GetWithoutAck(int batchSize, long? timeout, int? unit) } } + private Message ReceiveMessages() + { + var data = ReadNextPacket(); + var p = Packet.Parser.ParseFrom(data); + switch (p.Type) + { + case PacketType.Messages: + { + if (!p.Compression.Equals(Compression.None)) + { + throw new CanalClientException("compression is not supported in this connector"); + } + + var messages = Messages.Parser.ParseFrom(p.Body); + var result = new Message(messages.BatchId); + if (_lazyParseEntry) + { + // byteString + result.RawEntries = messages.Messages_.ToList(); + + } + else + { + foreach (var byteString in messages.Messages_) + { + result.Entries.Add(Entry.Parser.ParseFrom(byteString)); + } + } + return result; + } + case PacketType.Ack: + { + var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); + throw new CanalClientException($"something goes wrong with reason:{ack.ErrorMessage}"); + } + default: + { + throw new CanalClientException($"unexpected packet type: {p.Type}"); + } + } + } + public void Ack(long batchId) { throw new NotImplementedException(); diff --git a/src/CanalSharp.Protocol/Message.cs b/src/CanalSharp.Protocol/Message.cs index 19a8ef9..0905376 100644 --- a/src/CanalSharp.Protocol/Message.cs +++ b/src/CanalSharp.Protocol/Message.cs @@ -25,6 +25,7 @@ public Message(long id, List entries) public Message(long id) { Id = id; + Entries = new List();; } public Message(long id, bool raw, object entries) { From a03259709dfd97927a2c3393f8ebc6e115ca9498 Mon Sep 17 00:00:00 2001 From: WithLin Date: Tue, 18 Sep 2018 18:35:44 +0800 Subject: [PATCH 36/50] fix code style --- sample/CanalSharp.SimpleClient/Program.cs | 1 - src/CanalSharp.Client/Impl/Running/ClientRunningData.cs | 5 +---- test/CanalSharp.UnitTests/UnitTest1.cs | 3 +-- 3 files changed, 2 insertions(+), 7 deletions(-) diff --git a/sample/CanalSharp.SimpleClient/Program.cs b/sample/CanalSharp.SimpleClient/Program.cs index c1812a3..66883ef 100644 --- a/sample/CanalSharp.SimpleClient/Program.cs +++ b/sample/CanalSharp.SimpleClient/Program.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Threading; -using CanalSharp.Client; using CanalSharp.Client.Impl; using Com.Alibaba.Otter.Canal.Protocol; diff --git a/src/CanalSharp.Client/Impl/Running/ClientRunningData.cs b/src/CanalSharp.Client/Impl/Running/ClientRunningData.cs index ce39018..9708322 100644 --- a/src/CanalSharp.Client/Impl/Running/ClientRunningData.cs +++ b/src/CanalSharp.Client/Impl/Running/ClientRunningData.cs @@ -1,7 +1,4 @@ - -using System; - -namespace CanalSharp.Client.Impl.Running +namespace CanalSharp.Client.Impl.Running { /// /// client running状态信息 diff --git a/test/CanalSharp.UnitTests/UnitTest1.cs b/test/CanalSharp.UnitTests/UnitTest1.cs index dccd04b..a8248eb 100644 --- a/test/CanalSharp.UnitTests/UnitTest1.cs +++ b/test/CanalSharp.UnitTests/UnitTest1.cs @@ -1,11 +1,10 @@ using System; -using System.Net.Sockets; using System.Threading; using CanalSharp.Client; using CanalSharp.Client.Impl; using Xunit; -namespace Canal4Net.UnitTests +namespace CanalSharp.UnitTests { public class UnitTest1 { From 677d5116eb5eaf88d32e4fba92f16b80c6919e6d Mon Sep 17 00:00:00 2001 From: WithLin Date: Wed, 19 Sep 2018 11:29:52 +0800 Subject: [PATCH 37/50] Fix read buffer miss buffer bug --- sample/CanalSharp.SimpleClient/Program.cs | 44 +++-- src/CanalSharp.Client/ICanalConnector.cs | 6 +- .../Impl/SimpleCanalConnector.cs | 171 ++++++++++++------ 3 files changed, 145 insertions(+), 76 deletions(-) diff --git a/sample/CanalSharp.SimpleClient/Program.cs b/sample/CanalSharp.SimpleClient/Program.cs index 66883ef..8491979 100644 --- a/sample/CanalSharp.SimpleClient/Program.cs +++ b/sample/CanalSharp.SimpleClient/Program.cs @@ -17,9 +17,9 @@ static void Main(string[] args) connector.Subscribe(); while (true) { - var message = connector.Get(100); + var message = connector.Get(5000); var batchId = message.Id; - if (batchId == -1 || message.Entries.Count<=0) + if (batchId == -1 || message.Entries.Count <= 0) { Thread.Sleep(300); } @@ -47,28 +47,32 @@ private static void PrintEntry(List entrys) } - EventType eventType = rowChange.EventType; - Console.WriteLine( - $"================> binlog[{entry.Header.LogfileName}:{entry.Header.LogfileOffset}] , name[{entry.Header.SchemaName},{entry.Header.TableName}] , eventType :{eventType}"); - - foreach (var rowData in rowChange.RowDatas) + if (rowChange != null) { - if (eventType == EventType.Delete) - { - PrintColumn(rowData.BeforeColumns.ToList()); - } - else if (eventType == EventType.Insert) - { - PrintColumn(rowData.BeforeColumns.ToList()); - } - else + EventType eventType = rowChange.EventType; + Console.WriteLine( + $"================> binlog[{entry.Header.LogfileName}:{entry.Header.LogfileOffset}] , name[{entry.Header.SchemaName},{entry.Header.TableName}] , eventType :{eventType}"); + + foreach (var rowData in rowChange.RowDatas) { - Console.WriteLine("-------> before"); - PrintColumn(rowData.BeforeColumns.ToList()); - Console.WriteLine("-------> after"); - PrintColumn(rowData.AfterColumns.ToList()); + if (eventType == EventType.Delete) + { + PrintColumn(rowData.BeforeColumns.ToList()); + } + else if (eventType == EventType.Insert) + { + PrintColumn(rowData.BeforeColumns.ToList()); + } + else + { + Console.WriteLine("-------> before"); + PrintColumn(rowData.BeforeColumns.ToList()); + Console.WriteLine("-------> after"); + PrintColumn(rowData.AfterColumns.ToList()); + } } } + } } diff --git a/src/CanalSharp.Client/ICanalConnector.cs b/src/CanalSharp.Client/ICanalConnector.cs index d630107..95ccfe5 100644 --- a/src/CanalSharp.Client/ICanalConnector.cs +++ b/src/CanalSharp.Client/ICanalConnector.cs @@ -35,12 +35,12 @@ public interface ICanalConnector /// /// /// TODO: 后续可以考虑,如果本次提交的filter不为空,在执行过滤时,是对canal server filter + 本次filter的交集处理,达到只取1份binlog数据,多个客户端消费不同的表 - Task Subscribe(string filter); + void Subscribe(string filter); /// /// 客户端订阅,不提交客户端filter,以服务端的filter为准 /// - Task Subscribe(); + void Subscribe(); /// /// 取消订阅 @@ -63,7 +63,7 @@ public interface ICanalConnector /// /// /// - Message Get(int batchSize, long timeout, TimeSpan unit); + Message Get(int batchSize, long? timeout, int? unit); /// /// 不指定 position 获取事件,该方法返回的条件: 尝试拿batchSize条记录,有多少取多少,不会阻塞等待 diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 74dc04c..d0c3eac 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -77,6 +77,8 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector private TcpClient _tcpClient; private NetworkStream _channelNetworkStream; + public int i { get; set; } = 1; + public SimpleCanalConnector(string address, int port, string username, string password, string destination) : this(address, port, username, password, destination, 60000, 60 * 60 * 1000) @@ -115,10 +117,10 @@ public async Task Connect() return; } - await DoConnect(); + DoConnect(); if (_filter != null) { // 如果存在条件,说明是自动切换,基于上一次的条件订阅一次 - await Subscribe(_filter); + Subscribe(_filter); } //if (_rollbackOnConnect) //{ @@ -137,7 +139,7 @@ public bool CheckValid() throw new NotImplementedException(); } - public async Task Subscribe(string filter) + public void Subscribe(string filter) { //WaitClientRunning(); if (!_running) @@ -158,7 +160,7 @@ public async Task Subscribe(string filter) }.ToByteString() }.ToByteArray(); - await WriteWithHeader(pack); + WriteWithHeader(pack); var p = Packet.Parser.ParseFrom(ReadNextPacket()); var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); @@ -176,9 +178,9 @@ public async Task Subscribe(string filter) } - public async Task Subscribe() + public void Subscribe() { - await Subscribe(""); + Subscribe(""); } public void UnSubscribe() @@ -188,12 +190,15 @@ public void UnSubscribe() public Message Get(int batchSize) { - return GetWithoutAck(batchSize, null, null); + var message = Get(batchSize, null, null); + return message; } - public Message Get(int batchSize, long timeout, TimeSpan unit) + public Message Get(int batchSize, long? timeout, int? unit) { - throw new NotImplementedException(); + var message = GetWithoutAck(batchSize, timeout, unit); + Ack(message.Id); + return message; } public Message GetWithoutAck(int batchSize) @@ -233,7 +238,7 @@ public Message GetWithoutAck(int batchSize, long? timeout, int? unit) Body = get.ToByteString() }.ToByteArray(); - WriteWithHeader(packet).Wait(); + WriteWithHeader(packet); @@ -249,49 +254,90 @@ public Message GetWithoutAck(int batchSize, long? timeout, int? unit) private Message ReceiveMessages() { - var data = ReadNextPacket(); - var p = Packet.Parser.ParseFrom(data); - switch (p.Type) + + try { - case PacketType.Messages: + lock (this) + { + var data = ReadNextPacket(); + var p = Packet.Parser.ParseFrom(data); + switch (p.Type) { - if (!p.Compression.Equals(Compression.None)) + case PacketType.Messages: { - throw new CanalClientException("compression is not supported in this connector"); - } + if (!p.Compression.Equals(Compression.None)) + { + throw new CanalClientException("compression is not supported in this connector"); + } - var messages = Messages.Parser.ParseFrom(p.Body); - var result = new Message(messages.BatchId); - if (_lazyParseEntry) - { - // byteString - result.RawEntries = messages.Messages_.ToList(); + i++; + var messages = Messages.Parser.ParseFrom(p.Body); + var result = new Message(messages.BatchId); + if (_lazyParseEntry) + { + // byteString + result.RawEntries = messages.Messages_.ToList(); - } - else - { - foreach (var byteString in messages.Messages_) + } + else { - result.Entries.Add(Entry.Parser.ParseFrom(byteString)); + foreach (var byteString in messages.Messages_) + { + result.Entries.Add(Entry.Parser.ParseFrom(byteString)); + } } + return result; + } + case PacketType.Ack: + { + var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); + throw new CanalClientException($"something goes wrong with reason:{ack.ErrorMessage}"); + } + default: + { + throw new CanalClientException($"unexpected packet type: {p.Type}"); } - return result; - } - case PacketType.Ack: - { - var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); - throw new CanalClientException($"something goes wrong with reason:{ack.ErrorMessage}"); - } - default: - { - throw new CanalClientException($"unexpected packet type: {p.Type}"); } + } + + } + catch (Exception e) + { + Console.WriteLine(i); + throw; } + } public void Ack(long batchId) { - throw new NotImplementedException(); + //waitClientRunning(); + //if (!running) + //{ + // return; + //} + + var ca = new ClientAck() + { + Destination = _clientIdentity.Destination, + ClientId = _clientIdentity.ClientId.ToString(), + BatchId = batchId + }; + + var pack = new Packet() + { + Type = PacketType.Clientack, + Body = ca.ToByteString() + }.ToByteArray(); + + try + { + WriteWithHeader(pack); + } + catch (IOException e) + { + throw new CanalClientException(e.Message, e); + } } public void Rollback(long batchId) @@ -308,7 +354,7 @@ public void StopRunning() { throw new NotImplementedException(); } - private async Task DoConnect() + private void DoConnect() { try { @@ -342,7 +388,7 @@ private async Task DoConnect() Body = ca.ToByteString() }.ToByteArray(); - await WriteWithHeader(packArray); + WriteWithHeader(packArray); var packet = Packet.Parser.ParseFrom(ReadNextPacket()); if (packet.Type != PacketType.Ack) @@ -373,25 +419,44 @@ private byte[] ReadNextPacket() lock (_readDataLock) { var headerLength = ReadHeaderLength(); - var recevieData = new byte[headerLength]; - _channelNetworkStream.Read(recevieData, 0, recevieData.Length); - return recevieData; + var recevieData = new byte[1024 * 2]; + using (var ms = new MemoryStream()) + { + while (headerLength>0) + { + var len= _channelNetworkStream.Read(recevieData, 0, (headerLength > recevieData.Length ? recevieData.Length : headerLength)); + ms.Write(recevieData, 0,len); + headerLength = headerLength - len; + } + + return ms.ToArray(); + } + + } } private int ReadHeaderLength() { - var headerBytes = new byte[4]; - _channelNetworkStream.Read(headerBytes, 0, 4); - Array.Reverse(headerBytes); - return BitConverter.ToInt32(headerBytes, 0); + lock (this) + { + var headerBytes = new byte[4]; + _channelNetworkStream.Read(headerBytes, 0, 4); + Array.Reverse(headerBytes); + return BitConverter.ToInt32(headerBytes, 0); + } } - private async Task WriteWithHeader(byte[] body) + + private void WriteWithHeader(byte[] body) { - var len = body.Length; - var bytes = GetHeaderBytes(len); - await _channelNetworkStream.WriteAsync(bytes, 0, bytes.Length); - await _channelNetworkStream.WriteAsync(body, 0, body.Length); + lock (_writeDataLock) + { + var len = body.Length; + var bytes = GetHeaderBytes(len); + _channelNetworkStream.Write(bytes, 0, bytes.Length); + _channelNetworkStream.Write(body, 0, body.Length); + } + } From 7741868a943f43846c3017a97d129cba152767c7 Mon Sep 17 00:00:00 2001 From: WithLin Date: Wed, 19 Sep 2018 11:31:39 +0800 Subject: [PATCH 38/50] Fix code style --- src/CanalSharp.Client/Impl/SimpleCanalConnector.cs | 9 --------- 1 file changed, 9 deletions(-) diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index d0c3eac..0df9a44 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -3,7 +3,6 @@ using System.IO; using System.Linq; using System.Net.Sockets; -using System.Threading; using System.Threading.Tasks; using CanalSharp.Common.Logging; using CanalSharp.Protocol; @@ -61,9 +60,6 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector - private IByteBuffer readHeader = Unpooled.Buffer(10240); - private IByteBuffer writeHeader = Unpooled.Buffer(10240); - private IChannel _clientChannel; private IChannel _testChannel; @@ -77,9 +73,6 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector private TcpClient _tcpClient; private NetworkStream _channelNetworkStream; - public int i { get; set; } = 1; - - public SimpleCanalConnector(string address, int port, string username, string password, string destination) : this(address, port, username, password, destination, 60000, 60 * 60 * 1000) { @@ -270,7 +263,6 @@ private Message ReceiveMessages() throw new CanalClientException("compression is not supported in this connector"); } - i++; var messages = Messages.Parser.ParseFrom(p.Body); var result = new Message(messages.BatchId); if (_lazyParseEntry) @@ -303,7 +295,6 @@ private Message ReceiveMessages() } catch (Exception e) { - Console.WriteLine(i); throw; } From 82586c312be5f23f91e2e11edb9051a34ee2cc4b Mon Sep 17 00:00:00 2001 From: WithLin Date: Wed, 19 Sep 2018 12:51:29 +0800 Subject: [PATCH 39/50] Fix Bug --- sample/CanalSharp.SimpleClient/Program.cs | 1 + .../Impl/SimpleCanalConnector.cs | 148 ++++++++++++------ 2 files changed, 100 insertions(+), 49 deletions(-) diff --git a/sample/CanalSharp.SimpleClient/Program.cs b/sample/CanalSharp.SimpleClient/Program.cs index 8491979..85e7eb4 100644 --- a/sample/CanalSharp.SimpleClient/Program.cs +++ b/sample/CanalSharp.SimpleClient/Program.cs @@ -21,6 +21,7 @@ static void Main(string[] args) var batchId = message.Id; if (batchId == -1 || message.Entries.Count <= 0) { + Console.WriteLine("没有数据了............."); Thread.Sleep(300); } PrintEntry(message.Entries); diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 0df9a44..0a9d5a2 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -8,7 +8,6 @@ using CanalSharp.Protocol; using CanalSharp.Protocol.Exception; using Com.Alibaba.Otter.Canal.Protocol; -using DotNetty.Buffers; using DotNetty.Transport.Channels; using DotNetty.Transport.Channels.Sockets; using Google.Protobuf; @@ -178,7 +177,35 @@ public void Subscribe() public void UnSubscribe() { - throw new NotImplementedException(); + //waitClientRunning(); + //if (!running) + //{ + // return; + //} + try + { + var unsub = new Unsub() + { + Destination = _clientIdentity.Destination, + ClientId = _clientIdentity.ClientId.ToString(), + }; + var pack = new Packet() + { + Type = PacketType.Unsubscription, + Body = unsub.ToByteString() + }.ToByteArray(); + WriteWithHeader(pack); + var p = Packet.Parser.ParseFrom(ReadNextPacket()); + var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); + if (ack.ErrorCode > 0) + { + throw new CanalClientException($"failed to unSubscribe with reason: {ack.ErrorMessage}"); + } + } + catch (IOException e) + { + throw new CanalClientException(e.Message, e); + } } public Message Get(int batchSize) @@ -231,7 +258,7 @@ public Message GetWithoutAck(int batchSize, long? timeout, int? unit) Body = get.ToByteString() }.ToByteArray(); - WriteWithHeader(packet); + WriteWithHeader(packet).Wait(); @@ -247,7 +274,7 @@ public Message GetWithoutAck(int batchSize, long? timeout, int? unit) private Message ReceiveMessages() { - + try { lock (this) @@ -257,47 +284,47 @@ private Message ReceiveMessages() switch (p.Type) { case PacketType.Messages: - { - if (!p.Compression.Equals(Compression.None)) { - throw new CanalClientException("compression is not supported in this connector"); - } + if (!p.Compression.Equals(Compression.None)) + { + throw new CanalClientException("compression is not supported in this connector"); + } - var messages = Messages.Parser.ParseFrom(p.Body); - var result = new Message(messages.BatchId); - if (_lazyParseEntry) - { - // byteString - result.RawEntries = messages.Messages_.ToList(); + var messages = Messages.Parser.ParseFrom(p.Body); + var result = new Message(messages.BatchId); + if (_lazyParseEntry) + { + // byteString + result.RawEntries = messages.Messages_.ToList(); - } - else - { - foreach (var byteString in messages.Messages_) + } + else { - result.Entries.Add(Entry.Parser.ParseFrom(byteString)); + foreach (var byteString in messages.Messages_) + { + result.Entries.Add(Entry.Parser.ParseFrom(byteString)); + } } + return result; } - return result; - } case PacketType.Ack: - { - var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); - throw new CanalClientException($"something goes wrong with reason:{ack.ErrorMessage}"); - } + { + var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); + throw new CanalClientException($"something goes wrong with reason:{ack.ErrorMessage}"); + } default: - { - throw new CanalClientException($"unexpected packet type: {p.Type}"); - } + { + throw new CanalClientException($"unexpected packet type: {p.Type}"); + } } } - + } catch (Exception e) { throw; } - + } public void Ack(long batchId) @@ -323,7 +350,7 @@ public void Ack(long batchId) try { - WriteWithHeader(pack); + WriteWithHeader(pack).Wait(); } catch (IOException e) { @@ -333,19 +360,42 @@ public void Ack(long batchId) public void Rollback(long batchId) { - throw new NotImplementedException(); + //waitClientRunning(); + + var ca = new ClientRollback() + { + Destination = _clientIdentity.Destination, + ClientId = _clientIdentity.ClientId.ToString(), + BatchId = batchId + }; + + try + { + var pack = new Packet() + { + Type = PacketType.Clientrollback, + Body = ca.ToByteString() + }.ToByteArray(); + + WriteWithHeader(pack).Wait(); + } + catch (IOException e) + { + throw new CanalClientException(e.Message, e); + } } public void Rollback() { - throw new NotImplementedException(); + //waitClientRunning(); + Rollback(0);// 0代笔未设置 } public void StopRunning() { throw new NotImplementedException(); } - private void DoConnect() + private void DoConnect() { try { @@ -379,7 +429,7 @@ private void DoConnect() Body = ca.ToByteString() }.ToByteArray(); - WriteWithHeader(packArray); + WriteWithHeader(packArray).Wait(); var packet = Packet.Parser.ParseFrom(ReadNextPacket()); if (packet.Type != PacketType.Ack) @@ -413,17 +463,17 @@ private byte[] ReadNextPacket() var recevieData = new byte[1024 * 2]; using (var ms = new MemoryStream()) { - while (headerLength>0) + while (headerLength > 0) { - var len= _channelNetworkStream.Read(recevieData, 0, (headerLength > recevieData.Length ? recevieData.Length : headerLength)); - ms.Write(recevieData, 0,len); + var len = _channelNetworkStream.Read(recevieData, 0, (headerLength > recevieData.Length ? recevieData.Length : headerLength)); + ms.Write(recevieData, 0, len); headerLength = headerLength - len; } return ms.ToArray(); } - - + + } } @@ -438,16 +488,16 @@ private int ReadHeaderLength() } } - private void WriteWithHeader(byte[] body) + private async Task WriteWithHeader(byte[] body) { - lock (_writeDataLock) - { - var len = body.Length; - var bytes = GetHeaderBytes(len); - _channelNetworkStream.Write(bytes, 0, bytes.Length); - _channelNetworkStream.Write(body, 0, body.Length); - } - + //lock (_writeDataLock) + //{ + var len = body.Length; + var bytes = GetHeaderBytes(len); + await _channelNetworkStream.WriteAsync(bytes, 0, bytes.Length); + await _channelNetworkStream.WriteAsync(body, 0, body.Length); + //} + } From 03800c6ed89cb3e06c15b3c6bcca47bbd7ee6271 Mon Sep 17 00:00:00 2001 From: WithLin Date: Wed, 19 Sep 2018 12:54:44 +0800 Subject: [PATCH 40/50] refactor code --- .../Impl/SimpleCanalConnector.cs | 26 ++++++++----------- 1 file changed, 11 insertions(+), 15 deletions(-) diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 0a9d5a2..0b61091 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -58,10 +58,6 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector private static readonly object _readDataLock = new object(); - - private IChannel _clientChannel; - private IChannel _testChannel; - // 是否在connect链接成功后,自动执行rollback操作 private bool _rollbackOnConnect = true; @@ -258,7 +254,7 @@ public Message GetWithoutAck(int batchSize, long? timeout, int? unit) Body = get.ToByteString() }.ToByteArray(); - WriteWithHeader(packet).Wait(); + WriteWithHeader(packet); @@ -350,7 +346,7 @@ public void Ack(long batchId) try { - WriteWithHeader(pack).Wait(); + WriteWithHeader(pack); } catch (IOException e) { @@ -377,7 +373,7 @@ public void Rollback(long batchId) Body = ca.ToByteString() }.ToByteArray(); - WriteWithHeader(pack).Wait(); + WriteWithHeader(pack); } catch (IOException e) { @@ -429,7 +425,7 @@ private void DoConnect() Body = ca.ToByteString() }.ToByteArray(); - WriteWithHeader(packArray).Wait(); + WriteWithHeader(packArray); var packet = Packet.Parser.ParseFrom(ReadNextPacket()); if (packet.Type != PacketType.Ack) @@ -488,15 +484,15 @@ private int ReadHeaderLength() } } - private async Task WriteWithHeader(byte[] body) + private void WriteWithHeader(byte[] body) { - //lock (_writeDataLock) - //{ - var len = body.Length; + lock (_writeDataLock) + { + var len = body.Length; var bytes = GetHeaderBytes(len); - await _channelNetworkStream.WriteAsync(bytes, 0, bytes.Length); - await _channelNetworkStream.WriteAsync(body, 0, body.Length); - //} + _channelNetworkStream.Write(bytes, 0, bytes.Length); + _channelNetworkStream.Write(body, 0, body.Length); + } } From 66445bd87a1f1b1e028ee8d8bfb2d8372f78e2a4 Mon Sep 17 00:00:00 2001 From: WithLin Date: Wed, 19 Sep 2018 13:01:46 +0800 Subject: [PATCH 41/50] refactor code --- sample/CanalSharp.SimpleClient/Program.cs | 2 +- src/CanalSharp.Client/ICanalConnector.cs | 2 +- .../Impl/SimpleCanalConnector.cs | 122 +++++++++--------- 3 files changed, 61 insertions(+), 65 deletions(-) diff --git a/sample/CanalSharp.SimpleClient/Program.cs b/sample/CanalSharp.SimpleClient/Program.cs index 85e7eb4..50e2f73 100644 --- a/sample/CanalSharp.SimpleClient/Program.cs +++ b/sample/CanalSharp.SimpleClient/Program.cs @@ -22,7 +22,7 @@ static void Main(string[] args) if (batchId == -1 || message.Entries.Count <= 0) { Console.WriteLine("没有数据了............."); - Thread.Sleep(300); + //Thread.Sleep(300); } PrintEntry(message.Entries); } diff --git a/src/CanalSharp.Client/ICanalConnector.cs b/src/CanalSharp.Client/ICanalConnector.cs index 95ccfe5..a40be77 100644 --- a/src/CanalSharp.Client/ICanalConnector.cs +++ b/src/CanalSharp.Client/ICanalConnector.cs @@ -9,7 +9,7 @@ public interface ICanalConnector /// /// 链接对应的canal server /// - Task Connect(); + void Connect(); /// /// 释放链接 diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 0b61091..195b878 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -38,7 +38,6 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector /// private volatile bool _connected = false; - //private ClientRunningMonitor runningMonitor; private volatile bool _running = false; /// @@ -92,15 +91,15 @@ public SimpleCanalConnector(string address, int port, string username, string pa _clientIdentity = new ClientIdentity(destination, (short)1001); } - public async Task Connect() + public void Connect() { if (_connected) { return; } - //WaitClientRunning(); - if (_running) + WaitClientRunning(); + if (!_running) { return; } @@ -110,10 +109,10 @@ public async Task Connect() { // 如果存在条件,说明是自动切换,基于上一次的条件订阅一次 Subscribe(_filter); } - //if (_rollbackOnConnect) - //{ - // Rollback(); - //} + if (_rollbackOnConnect) + { + Rollback(); + } _connected = true; } @@ -129,7 +128,7 @@ public bool CheckValid() public void Subscribe(string filter) { - //WaitClientRunning(); + WaitClientRunning(); if (!_running) { return; @@ -173,11 +172,11 @@ public void Subscribe() public void UnSubscribe() { - //waitClientRunning(); - //if (!running) - //{ - // return; - //} + WaitClientRunning(); + if (!_running) + { + return; + } try { var unsub = new Unsub() @@ -224,11 +223,11 @@ public Message GetWithoutAck(int batchSize) public Message GetWithoutAck(int batchSize, long? timeout, int? unit) { - //waitClientRunning(); - //if (!_running) - //{ - // return null; - //} + WaitClientRunning(); + if (!_running) + { + return null; + } try { @@ -273,46 +272,43 @@ private Message ReceiveMessages() try { - lock (this) + var data = ReadNextPacket(); + var p = Packet.Parser.ParseFrom(data); + switch (p.Type) { - var data = ReadNextPacket(); - var p = Packet.Parser.ParseFrom(data); - switch (p.Type) - { - case PacketType.Messages: + case PacketType.Messages: + { + if (!p.Compression.Equals(Compression.None)) { - if (!p.Compression.Equals(Compression.None)) - { - throw new CanalClientException("compression is not supported in this connector"); - } - - var messages = Messages.Parser.ParseFrom(p.Body); - var result = new Message(messages.BatchId); - if (_lazyParseEntry) - { - // byteString - result.RawEntries = messages.Messages_.ToList(); - - } - else - { - foreach (var byteString in messages.Messages_) - { - result.Entries.Add(Entry.Parser.ParseFrom(byteString)); - } - } - return result; + throw new CanalClientException("compression is not supported in this connector"); } - case PacketType.Ack: + + var messages = Messages.Parser.ParseFrom(p.Body); + var result = new Message(messages.BatchId); + if (_lazyParseEntry) { - var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); - throw new CanalClientException($"something goes wrong with reason:{ack.ErrorMessage}"); + // byteString + result.RawEntries = messages.Messages_.ToList(); + } - default: + else { - throw new CanalClientException($"unexpected packet type: {p.Type}"); + foreach (var byteString in messages.Messages_) + { + result.Entries.Add(Entry.Parser.ParseFrom(byteString)); + } } - } + return result; + } + case PacketType.Ack: + { + var ack = Com.Alibaba.Otter.Canal.Protocol.Ack.Parser.ParseFrom(p.Body); + throw new CanalClientException($"something goes wrong with reason:{ack.ErrorMessage}"); + } + default: + { + throw new CanalClientException($"unexpected packet type: {p.Type}"); + } } } @@ -325,11 +321,11 @@ private Message ReceiveMessages() public void Ack(long batchId) { - //waitClientRunning(); - //if (!running) - //{ - // return; - //} + WaitClientRunning(); + if (!_running) + { + return; + } var ca = new ClientAck() { @@ -356,7 +352,7 @@ public void Ack(long batchId) public void Rollback(long batchId) { - //waitClientRunning(); + WaitClientRunning(); var ca = new ClientRollback() { @@ -383,7 +379,7 @@ public void Rollback(long batchId) public void Rollback() { - //waitClientRunning(); + WaitClientRunning(); Rollback(0);// 0代笔未设置 } @@ -484,14 +480,14 @@ private int ReadHeaderLength() } } - private void WriteWithHeader(byte[] body) + private void WriteWithHeader(byte[] body) { lock (_writeDataLock) { var len = body.Length; - var bytes = GetHeaderBytes(len); - _channelNetworkStream.Write(bytes, 0, bytes.Length); - _channelNetworkStream.Write(body, 0, body.Length); + var bytes = GetHeaderBytes(len); + _channelNetworkStream.Write(bytes, 0, bytes.Length); + _channelNetworkStream.Write(body, 0, body.Length); } } From 31458ee60bd9a182a450d537557e7bc1e0ca143b Mon Sep 17 00:00:00 2001 From: WithLin Date: Wed, 19 Sep 2018 13:16:05 +0800 Subject: [PATCH 42/50] impl other method --- sample/CanalSharp.SimpleClient/Program.cs | 27 ++++++++++++++----- .../Impl/SimpleCanalConnector.cs | 26 +++++++++++++++++- 2 files changed, 45 insertions(+), 8 deletions(-) diff --git a/sample/CanalSharp.SimpleClient/Program.cs b/sample/CanalSharp.SimpleClient/Program.cs index 50e2f73..6aedf00 100644 --- a/sample/CanalSharp.SimpleClient/Program.cs +++ b/sample/CanalSharp.SimpleClient/Program.cs @@ -15,17 +15,30 @@ static void Main(string[] args) var connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); connector.Connect(); connector.Subscribe(); - while (true) + try { - var message = connector.Get(5000); - var batchId = message.Id; - if (batchId == -1 || message.Entries.Count <= 0) + while (true) { - Console.WriteLine("没有数据了............."); - //Thread.Sleep(300); + var message = connector.GetWithoutAck(5000); + var batchId = message.Id; + if (batchId == -1 || message.Entries.Count <= 0) + { + Console.WriteLine("=======没有数据了======="); + Thread.Sleep(300); + continue; + } + PrintEntry(message.Entries); + + connector.Ack(batchId); } - PrintEntry(message.Entries); } + catch (Exception e) + { + Console.WriteLine(e); + connector.Rollback(); + throw; + } + } private static void PrintEntry(List entrys) diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 195b878..292944d 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -67,6 +67,11 @@ public class SimpleCanalConnector : ChannelHandlerAdapter, ICanalConnector private TcpClient _tcpClient; private NetworkStream _channelNetworkStream; + /// + /// 是否在connect链接成功后,自动执行rollback操作 + /// + private bool _rollbackOnDisConnect = false; + public SimpleCanalConnector(string address, int port, string username, string password, string destination) : this(address, port, username, password, destination, 60000, 60 * 60 * 1000) { @@ -118,7 +123,26 @@ public void Connect() public void Disconnect() { - throw new NotImplementedException(); + if (_rollbackOnDisConnect && _tcpClient.Connected == false) + { + Rollback(); + } + _connected = false; + DoDisConnection(); + } + + private void DoDisConnection() + { + if (_tcpClient != null) + { + QuietlyClose(); + } + + } + + private void QuietlyClose() + { + _tcpClient.Close(); } public bool CheckValid() From 91d0261554e3be7a6842fec97dc621e5684c1548 Mon Sep 17 00:00:00 2001 From: WithLin Date: Wed, 19 Sep 2018 13:19:13 +0800 Subject: [PATCH 43/50] Refactor code --- src/CanalSharp.Client/ICanalConnector.cs | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/CanalSharp.Client/ICanalConnector.cs b/src/CanalSharp.Client/ICanalConnector.cs index a40be77..2e86d5f 100644 --- a/src/CanalSharp.Client/ICanalConnector.cs +++ b/src/CanalSharp.Client/ICanalConnector.cs @@ -1,6 +1,4 @@ -using System; -using System.Threading.Tasks; -using CanalSharp.Protocol; +using CanalSharp.Protocol; namespace CanalSharp.Client { From c0b602dcd76ebbdb9b2191f8a42b55039d6e64d0 Mon Sep 17 00:00:00 2001 From: WithLin Date: Wed, 19 Sep 2018 14:20:21 +0800 Subject: [PATCH 44/50] refactor name space --- src/CanalSharp.Client/ICanalNodeAccessStrategy.cs | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/src/CanalSharp.Client/ICanalNodeAccessStrategy.cs b/src/CanalSharp.Client/ICanalNodeAccessStrategy.cs index d83a9ce..a9ce2e7 100644 --- a/src/CanalSharp.Client/ICanalNodeAccessStrategy.cs +++ b/src/CanalSharp.Client/ICanalNodeAccessStrategy.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; -using System.Net; -using System.Text; +using System.Net; -namespace CanalSharp.Abstract +namespace CanalSharp.Client { public interface ICanalNodeAccessStrategy { From d6c6d16f9e6577c3a1ffb702e0b0b85fdba080bb Mon Sep 17 00:00:00 2001 From: WithLin Date: Wed, 19 Sep 2018 14:53:16 +0800 Subject: [PATCH 45/50] refactor code --- src/CanalSharp.Client/Impl/SimpleCanalConnector.cs | 3 --- src/CanalSharp.Client/Impl/SimpleNodeAccessStrategy.cs | 1 - 2 files changed, 4 deletions(-) diff --git a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs index 292944d..9cc1589 100644 --- a/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs +++ b/src/CanalSharp.Client/Impl/SimpleCanalConnector.cs @@ -495,13 +495,10 @@ private byte[] ReadNextPacket() private int ReadHeaderLength() { - lock (this) - { var headerBytes = new byte[4]; _channelNetworkStream.Read(headerBytes, 0, 4); Array.Reverse(headerBytes); return BitConverter.ToInt32(headerBytes, 0); - } } private void WriteWithHeader(byte[] body) diff --git a/src/CanalSharp.Client/Impl/SimpleNodeAccessStrategy.cs b/src/CanalSharp.Client/Impl/SimpleNodeAccessStrategy.cs index 1aeeac7..cc70fb9 100644 --- a/src/CanalSharp.Client/Impl/SimpleNodeAccessStrategy.cs +++ b/src/CanalSharp.Client/Impl/SimpleNodeAccessStrategy.cs @@ -2,7 +2,6 @@ using System.Collections.Generic; using System.Linq; using System.Net; -using CanalSharp.Abstract; namespace CanalSharp.Client.Impl { From c70972f04869b33c82ebff8d77415eeca86813fa Mon Sep 17 00:00:00 2001 From: WithLin Date: Thu, 20 Sep 2018 12:58:38 +0800 Subject: [PATCH 46/50] add CI --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 .travis.yml diff --git a/.travis.yml b/.travis.yml new file mode 100644 index 0000000..1b392e7 --- /dev/null +++ b/.travis.yml @@ -0,0 +1,7 @@ +language: csharp +solution: CanalSharp.sln +mono: none +dotnet: 2.1.302 +script: + - dotnet restore + - dotnet build \ No newline at end of file From b882eb1fc32a0ea04c10d4ae727fa2b4f90880bb Mon Sep 17 00:00:00 2001 From: WithLin Date: Thu, 20 Sep 2018 13:08:34 +0800 Subject: [PATCH 47/50] Fix add CI status --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index afb81d4..a58cfec 100644 --- a/README.md +++ b/README.md @@ -1,2 +1,3 @@ # canal-client-csharp +[![Build Status](https://travis-ci.org/CanalSharp/CanalSharp.svg?branch=dev)](https://travis-ci.org/CanalSharp/CanalSharp) The .NET canal client for Alibaba canal https://github.com/alibaba/canal From 8c9ea49a9d221313c28a55ed3ce987e7c55ea017 Mon Sep 17 00:00:00 2001 From: WithLin Date: Thu, 20 Sep 2018 13:12:21 +0800 Subject: [PATCH 48/50] Fix --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index a58cfec..4c13d3c 100644 --- a/README.md +++ b/README.md @@ -1,3 +1,4 @@ # canal-client-csharp [![Build Status](https://travis-ci.org/CanalSharp/CanalSharp.svg?branch=dev)](https://travis-ci.org/CanalSharp/CanalSharp) + The .NET canal client for Alibaba canal https://github.com/alibaba/canal From c698213b402cc2a6e88592a29f1007fa48eea28f Mon Sep 17 00:00:00 2001 From: WithLin Date: Thu, 20 Sep 2018 16:01:02 +0800 Subject: [PATCH 49/50] refactor the code --- sample/CanalSharp.SimpleClient/Program.cs | 27 +++++-------------- .../AbstractCanalLifeCycle.cs | 10 +++---- test/CanalSharp.UnitTests/UnitTest1.cs | 2 ++ 3 files changed, 12 insertions(+), 27 deletions(-) diff --git a/sample/CanalSharp.SimpleClient/Program.cs b/sample/CanalSharp.SimpleClient/Program.cs index 6aedf00..85e7eb4 100644 --- a/sample/CanalSharp.SimpleClient/Program.cs +++ b/sample/CanalSharp.SimpleClient/Program.cs @@ -15,30 +15,17 @@ static void Main(string[] args) var connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); connector.Connect(); connector.Subscribe(); - try + while (true) { - while (true) + var message = connector.Get(5000); + var batchId = message.Id; + if (batchId == -1 || message.Entries.Count <= 0) { - var message = connector.GetWithoutAck(5000); - var batchId = message.Id; - if (batchId == -1 || message.Entries.Count <= 0) - { - Console.WriteLine("=======没有数据了======="); - Thread.Sleep(300); - continue; - } - PrintEntry(message.Entries); - - connector.Ack(batchId); + Console.WriteLine("没有数据了............."); + Thread.Sleep(300); } + PrintEntry(message.Entries); } - catch (Exception e) - { - Console.WriteLine(e); - connector.Rollback(); - throw; - } - } private static void PrintEntry(List entrys) diff --git a/src/CanalSharp.Common/AbstractCanalLifeCycle.cs b/src/CanalSharp.Common/AbstractCanalLifeCycle.cs index 28ea9a9..58cbc5d 100644 --- a/src/CanalSharp.Common/AbstractCanalLifeCycle.cs +++ b/src/CanalSharp.Common/AbstractCanalLifeCycle.cs @@ -1,8 +1,4 @@ -// #region File Annotation -// - - -using CanalSharp.Common.Exception; +using CanalSharp.Common.Exception; namespace CanalSharp.Common { @@ -19,7 +15,7 @@ public virtual void Start() { if (Running) { - throw new CanalException(this.GetType().Name + " has startup , don't repeat start"); + throw new CanalException($" {nameof(AbstractCanalLifeCycle)} has startup , don't repeat start"); } Running = true; @@ -29,7 +25,7 @@ public virtual void Stop() { if (!Running) { - throw new CanalException(this.GetType().Name + " isn't start , please check"); + throw new CanalException($"{nameof(AbstractCanalLifeCycle)} isn't start , please check"); } Running = false; diff --git a/test/CanalSharp.UnitTests/UnitTest1.cs b/test/CanalSharp.UnitTests/UnitTest1.cs index a8248eb..fa75ef7 100644 --- a/test/CanalSharp.UnitTests/UnitTest1.cs +++ b/test/CanalSharp.UnitTests/UnitTest1.cs @@ -17,6 +17,8 @@ public void Test1() ICanalConnector connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); connector.Connect(); Console.Read(); + + Mutex a=new Mutex(false); //lock (_lock) //{ // new Thread(Test).Start(); From 4f16b2e5c830914d9a12fd9770f09202c60a8588 Mon Sep 17 00:00:00 2001 From: stulzq Date: Mon, 24 Sep 2018 22:59:56 +0800 Subject: [PATCH 50/50] update readme --- README.md | 60 ++++++++++++++++++- build/package.props | 13 ++-- sample/CanalSharp.SimpleClient/Program.cs | 7 ++- .../CanalSharp.Client.csproj | 5 +- .../CanalSharp.Common.csproj | 4 +- .../CanalSharp.Protocol.csproj | 4 +- 6 files changed, 77 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 4c13d3c..bdcca2b 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,58 @@ -# canal-client-csharp -[![Build Status](https://travis-ci.org/CanalSharp/CanalSharp.svg?branch=dev)](https://travis-ci.org/CanalSharp/CanalSharp) -The .NET canal client for Alibaba canal https://github.com/alibaba/canal +# CanalSharp + +## 一.CanalSharp是什么? + +CanalSharp 是阿里巴巴开源项目 Canal 的 .NET 客户端。为 .NET 开发者提供一个更友好的使用 Canal 的方式。Canal 是mysql数据库binlog的增量订阅&消费组件。 + +基于日志增量订阅&消费支持的业务: + +1. 数据库镜像 +2. 数据库实时备份 +3. 多级索引 (卖家和买家各自分库索引) +4. search build +5. 业务cache刷新 +6. 价格变化等重要业务消息 + +关于 Canal 的更多信息请访问 https://github.com/alibaba/canal + +## 二.如何使用 + +1.安装Canal + +Canal的安装以及配置使用请查看 https://github.com/alibaba/canal + +2.建立一个.NET Core App项目 + +3.为该项目从 Nuget 安装 CanalSharp + +````shell +Install-Package CanalSharp.Client +```` + +4.建立与Canal的连接 + +````csharp +//canal 配置的 destination,默认为 example +var destination = "example"; +//创建一个简单CanalClient连接对象(此对象不支持集群)传入参数分别为 canal地址、端口、destination、用户名、密码 +var connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); +//连接 Canal +connector.Connect(); +//订阅,同时传入Filter,如果不传则以Canal的Filter为准。Filter是一种过滤规则,通过该规则的表数据变更才会传递过来 +connector.Subscribe(""); +//获取消息并且需要发送Ack表示消费成功 +connector.Get(batchSize); +//获取消息但是不需要发送Ack来表示消费成功 +connector.GetWithoutAck(batchSize); +```` + +更多详情请查看 Sample + +## 三.贡献代码 + +1.fork本项目 + +2.做出你的更改 + +3.提交 pull request \ No newline at end of file diff --git a/build/package.props b/build/package.props index c8ad077..0783706 100644 --- a/build/package.props +++ b/build/package.props @@ -1,13 +1,14 @@ - C# client for canal. https://github.com/alibaba/canal - https://github.com/Canal4Net/Canal4Net/blob/master/LICENSE - https://github.com/Canal4Net/Canal4Net - https://github.com/Canal4Net/Canal4Net.git + + 阿里巴巴mysql数据库binlog的增量订阅/消费组件 Canal 的 .NET 客户端 + https://github.com/CanalSharp/CanalSharp/blob/dev/LICENSE + https://github.com/CanalSharp/CanalSharp + https://github.com/CanalSharp/CanalSharp.git git canal;mysql;binlog - Canal4Net Org. - stulzq,WithLin + CanalSharp Org. + stulzq,WithLin,CanalSharp diff --git a/sample/CanalSharp.SimpleClient/Program.cs b/sample/CanalSharp.SimpleClient/Program.cs index 85e7eb4..818e96d 100644 --- a/sample/CanalSharp.SimpleClient/Program.cs +++ b/sample/CanalSharp.SimpleClient/Program.cs @@ -11,12 +11,17 @@ class Program { static void Main(string[] args) { + //canal 配置的 destination,默认为 example var destination = "example"; + //创建一个简单CanalClient连接对象(此对象不支持集群)传入参数分别为 canal地址、端口、destination、用户名、密码 var connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", ""); + //连接 Canal connector.Connect(); - connector.Subscribe(); + //订阅,同时传入Filter,如果不传则以Canal的Filter为准。Filter是一种过滤规则,通过该规则的表数据变更才会传递过来 + connector.Subscribe(""); while (true) { + //获取消息数据 var message = connector.Get(5000); var batchId = message.Id; if (batchId == -1 || message.Entries.Count <= 0) diff --git a/src/CanalSharp.Client/CanalSharp.Client.csproj b/src/CanalSharp.Client/CanalSharp.Client.csproj index 87cb9be..c394b76 100644 --- a/src/CanalSharp.Client/CanalSharp.Client.csproj +++ b/src/CanalSharp.Client/CanalSharp.Client.csproj @@ -1,9 +1,10 @@ - - + + netstandard2.0 + diff --git a/src/CanalSharp.Common/CanalSharp.Common.csproj b/src/CanalSharp.Common/CanalSharp.Common.csproj index 9f5c4f4..a592c21 100644 --- a/src/CanalSharp.Common/CanalSharp.Common.csproj +++ b/src/CanalSharp.Common/CanalSharp.Common.csproj @@ -1,5 +1,5 @@ - - + + netstandard2.0 diff --git a/src/CanalSharp.Protocol/CanalSharp.Protocol.csproj b/src/CanalSharp.Protocol/CanalSharp.Protocol.csproj index 34f7c5c..b9722e7 100644 --- a/src/CanalSharp.Protocol/CanalSharp.Protocol.csproj +++ b/src/CanalSharp.Protocol/CanalSharp.Protocol.csproj @@ -1,5 +1,5 @@ - - + + netstandard2.0