Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
5300b63
Fix add protocol
withlin Sep 7, 2018
b5f7f25
Fix sln compile error
withlin Sep 7, 2018
5ade140
Update README.md
withlin Sep 7, 2018
9cd504c
Update README.md
withlin Sep 7, 2018
0dcc689
Fix sln
withlin Sep 7, 2018
745f6c9
fix upgrade proto2 to proto3
withlin Sep 13, 2018
3770b0b
fix add interface action
withlin Sep 13, 2018
ceb8920
add position module
withlin Sep 14, 2018
2663a12
fix code style
withlin Sep 14, 2018
93f184d
Fix socket of type bug
withlin Sep 14, 2018
3b0f500
change project name Canal.Csharp->CanalSharp
stulzq Sep 14, 2018
d23778d
change namespace Canal.Csharp->CanalSharp
stulzq Sep 14, 2018
6a23ce3
CanalSharp.Core -> CanalSharp.Client
stulzq Sep 14, 2018
c50e021
change folder name
stulzq Sep 14, 2018
599bbcd
add client some impl
stulzq Sep 14, 2018
6f27987
remove CanalSharp.Abstract
stulzq Sep 14, 2018
bcee772
update sln
stulzq Sep 14, 2018
3d0f0ab
fix code style
withlin Sep 15, 2018
270f123
Fix add Alarm module
withlin Sep 15, 2018
a5a95ff
Fix add Log Module
withlin Sep 15, 2018
0b85d55
add zookeeper module
withlin Sep 15, 2018
639f683
Fix add Running module
withlin Sep 15, 2018
5e17fc0
Fix add utils module
withlin Sep 15, 2018
dcc1edd
Fix add d Sample Connector and add UnitTest
withlin Sep 15, 2018
efdd633
fix CI
withlin Sep 15, 2018
9b01208
Fix code style
withlin Sep 15, 2018
4ea376b
Fix add implement Receive Message and Fix Proto3 bug
withlin Sep 16, 2018
45b0ca9
Fix Protocal default value
withlin Sep 16, 2018
2c0eb01
Fix code style
withlin Sep 16, 2018
3901dc3
Fix Down Data
withlin Sep 16, 2018
44a4b5b
add sample project
stulzq Sep 17, 2018
d40459e
Add read valid data logic
stulzq Sep 17, 2018
a1666f5
Remove redundant files
stulzq Sep 17, 2018
0f47835
Fix impl Connect Subscribe
withlin Sep 18, 2018
da15545
add sample
withlin Sep 18, 2018
a032597
fix code style
withlin Sep 18, 2018
677d511
Fix read buffer miss buffer bug
withlin Sep 19, 2018
7741868
Fix code style
withlin Sep 19, 2018
82586c3
Fix Bug
withlin Sep 19, 2018
03800c6
refactor code
withlin Sep 19, 2018
66445bd
refactor code
withlin Sep 19, 2018
31458ee
impl other method
withlin Sep 19, 2018
91d0261
Refactor code
withlin Sep 19, 2018
c0b602d
refactor name space
withlin Sep 19, 2018
d6c6d16
refactor code
withlin Sep 19, 2018
c70972f
add CI
withlin Sep 20, 2018
b882eb1
Fix add CI status
withlin Sep 20, 2018
8c9ea49
Fix
withlin Sep 20, 2018
c698213
refactor the code
withlin Sep 20, 2018
4f16b2e
update readme
stulzq Sep 24, 2018
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
language: csharp
solution: CanalSharp.sln
mono: none
dotnet: 2.1.302
script:
- dotnet restore
- dotnet build
48 changes: 0 additions & 48 deletions Canal4Net.sln

This file was deleted.

71 changes: 71 additions & 0 deletions CanalSharp.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

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}") = "01 Solution Items", "01 Solution Items", "{9F45639B-A9FA-4F6A-94EC-0D251FA3285D}"
ProjectSection(SolutionItems) = preProject
.gitignore = .gitignore
build\common.props = build\common.props
build\package.props = build\package.props
README.md = README.md
build\version.props = build\version.props
EndProjectSection
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03 test", "03 test", "{BD70CDB7-94E9-4621-B702-DC04DB9D59EF}"
EndProject
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
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}"
EndProject
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
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{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
{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
{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
{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
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{83F407DD-5810-422F-8AF6-4E9BA75AC678} = {BD70CDB7-94E9-4621-B702-DC04DB9D59EF}
{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}
EndGlobalSection
EndGlobal
60 changes: 58 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,58 @@
# Canal4Net
C# client for 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
13 changes: 7 additions & 6 deletions build/package.props
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
<Project>
<PropertyGroup Label="Package">
<Description>C# client for canal. https://github.com/alibaba/canal</Description>
<Copyright></Copyright>
<PackageLicenseUrl>https://github.com/Canal4Net/Canal4Net/blob/master/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/Canal4Net/Canal4Net</PackageProjectUrl>
<RepositoryUrl>https://github.com/Canal4Net/Canal4Net.git</RepositoryUrl>

<Description>阿里巴巴mysql数据库binlog的增量订阅/消费组件 Canal 的 .NET 客户端</Description>
<PackageLicenseUrl>https://github.com/CanalSharp/CanalSharp/blob/dev/LICENSE</PackageLicenseUrl>
<PackageProjectUrl>https://github.com/CanalSharp/CanalSharp</PackageProjectUrl>
<RepositoryUrl>https://github.com/CanalSharp/CanalSharp.git</RepositoryUrl>
<RepositoryType>git</RepositoryType>
<PackageTags>canal;mysql;binlog</PackageTags>
<Company>Canal4Net Org.</Company>
<Authors>stulzq,WithLin</Authors>
<Company>CanalSharp Org.</Company>
<Authors>stulzq,WithLin,CanalSharp</Authors>
</PropertyGroup>
</Project>
13 changes: 13 additions & 0 deletions sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.1</TargetFramework>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\..\src\CanalSharp.Client\CanalSharp.Client.csproj" />
<ProjectReference Include="..\..\src\CanalSharp.Protocol\CanalSharp.Protocol.csproj" />
</ItemGroup>

</Project>
93 changes: 93 additions & 0 deletions sample/CanalSharp.SimpleClient/Program.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading;
using CanalSharp.Client.Impl;
using Com.Alibaba.Otter.Canal.Protocol;

namespace CanalSharp.SimpleClient
{
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();
//订阅,同时传入Filter,如果不传则以Canal的Filter为准。Filter是一种过滤规则,通过该规则的表数据变更才会传递过来
connector.Subscribe("");
while (true)
{
//获取消息数据
var message = connector.Get(5000);
var batchId = message.Id;
if (batchId == -1 || message.Entries.Count <= 0)
{
Console.WriteLine("没有数据了.............");
Thread.Sleep(300);
}
PrintEntry(message.Entries);
}
}

private static void PrintEntry(List<Entry> 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)
{

}

if (rowChange != null)
{
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<Column> columns)
{
foreach (var column in columns)
{
Console.WriteLine($"{column.Name} : {column.Value} update= {column.Updated}");
}
}
}
}
17 changes: 17 additions & 0 deletions src/CanalSharp.Client/CanalSharp.Client.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>


<ItemGroup>
<PackageReference Include="DotNetty.Codecs.Protobuf" Version="0.5.0" />
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\CanalSharp.Common\CanalSharp.Common.csproj" />
<ProjectReference Include="..\CanalSharp.Protocol\CanalSharp.Protocol.csproj" />
</ItemGroup>

</Project>
Loading