Skip to content

Commit 28f3741

Browse files
authored
Merge pull request #1 from CanalSharp/dev
Release 0.0.1
2 parents 99fe7b0 + 4f16b2e commit 28f3741

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+7733
-71
lines changed

.travis.yml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
language: csharp
2+
solution: CanalSharp.sln
3+
mono: none
4+
dotnet: 2.1.302
5+
script:
6+
- dotnet restore
7+
- dotnet build

Canal4Net.sln

Lines changed: 0 additions & 48 deletions
This file was deleted.

CanalSharp.sln

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
2+
Microsoft Visual Studio Solution File, Format Version 12.00
3+
# Visual Studio 15
4+
VisualStudioVersion = 15.0.27703.2026
5+
MinimumVisualStudioVersion = 10.0.40219.1
6+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "01 Solution Items", "01 Solution Items", "{9F45639B-A9FA-4F6A-94EC-0D251FA3285D}"
7+
ProjectSection(SolutionItems) = preProject
8+
.gitignore = .gitignore
9+
build\common.props = build\common.props
10+
build\package.props = build\package.props
11+
README.md = README.md
12+
build\version.props = build\version.props
13+
EndProjectSection
14+
EndProject
15+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "03 test", "03 test", "{BD70CDB7-94E9-4621-B702-DC04DB9D59EF}"
16+
EndProject
17+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "02 src", "02 src", "{4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}"
18+
EndProject
19+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.UnitTests", "test\CanalSharp.UnitTests\CanalSharp.UnitTests.csproj", "{83F407DD-5810-422F-8AF6-4E9BA75AC678}"
20+
EndProject
21+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Client", "src\CanalSharp.Client\CanalSharp.Client.csproj", "{E33BCF38-D450-4AFE-B409-E6E7C0251479}"
22+
EndProject
23+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Protocol", "src\CanalSharp.Protocol\CanalSharp.Protocol.csproj", "{B9782080-16BD-4328-A394-3EC8D9B49326}"
24+
EndProject
25+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CanalSharp.Common", "src\CanalSharp.Common\CanalSharp.Common.csproj", "{B583684C-4E2F-42A5-8F08-1E3C4EE4C586}"
26+
EndProject
27+
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "04 sample", "04 sample", "{A4650FA0-4725-4956-90D3-F462F3C7474F}"
28+
EndProject
29+
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CanalSharp.SimpleClient", "sample\CanalSharp.SimpleClient\CanalSharp.SimpleClient.csproj", "{CE9C0E45-F613-4E28-89EE-7F646B028BFB}"
30+
EndProject
31+
Global
32+
GlobalSection(SolutionConfigurationPlatforms) = preSolution
33+
Debug|Any CPU = Debug|Any CPU
34+
Release|Any CPU = Release|Any CPU
35+
EndGlobalSection
36+
GlobalSection(ProjectConfigurationPlatforms) = postSolution
37+
{83F407DD-5810-422F-8AF6-4E9BA75AC678}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
38+
{83F407DD-5810-422F-8AF6-4E9BA75AC678}.Debug|Any CPU.Build.0 = Debug|Any CPU
39+
{83F407DD-5810-422F-8AF6-4E9BA75AC678}.Release|Any CPU.ActiveCfg = Release|Any CPU
40+
{83F407DD-5810-422F-8AF6-4E9BA75AC678}.Release|Any CPU.Build.0 = Release|Any CPU
41+
{E33BCF38-D450-4AFE-B409-E6E7C0251479}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
42+
{E33BCF38-D450-4AFE-B409-E6E7C0251479}.Debug|Any CPU.Build.0 = Debug|Any CPU
43+
{E33BCF38-D450-4AFE-B409-E6E7C0251479}.Release|Any CPU.ActiveCfg = Release|Any CPU
44+
{E33BCF38-D450-4AFE-B409-E6E7C0251479}.Release|Any CPU.Build.0 = Release|Any CPU
45+
{B9782080-16BD-4328-A394-3EC8D9B49326}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
46+
{B9782080-16BD-4328-A394-3EC8D9B49326}.Debug|Any CPU.Build.0 = Debug|Any CPU
47+
{B9782080-16BD-4328-A394-3EC8D9B49326}.Release|Any CPU.ActiveCfg = Release|Any CPU
48+
{B9782080-16BD-4328-A394-3EC8D9B49326}.Release|Any CPU.Build.0 = Release|Any CPU
49+
{B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
50+
{B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Debug|Any CPU.Build.0 = Debug|Any CPU
51+
{B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Release|Any CPU.ActiveCfg = Release|Any CPU
52+
{B583684C-4E2F-42A5-8F08-1E3C4EE4C586}.Release|Any CPU.Build.0 = Release|Any CPU
53+
{CE9C0E45-F613-4E28-89EE-7F646B028BFB}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
54+
{CE9C0E45-F613-4E28-89EE-7F646B028BFB}.Debug|Any CPU.Build.0 = Debug|Any CPU
55+
{CE9C0E45-F613-4E28-89EE-7F646B028BFB}.Release|Any CPU.ActiveCfg = Release|Any CPU
56+
{CE9C0E45-F613-4E28-89EE-7F646B028BFB}.Release|Any CPU.Build.0 = Release|Any CPU
57+
EndGlobalSection
58+
GlobalSection(SolutionProperties) = preSolution
59+
HideSolutionNode = FALSE
60+
EndGlobalSection
61+
GlobalSection(NestedProjects) = preSolution
62+
{83F407DD-5810-422F-8AF6-4E9BA75AC678} = {BD70CDB7-94E9-4621-B702-DC04DB9D59EF}
63+
{E33BCF38-D450-4AFE-B409-E6E7C0251479} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}
64+
{B9782080-16BD-4328-A394-3EC8D9B49326} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}
65+
{B583684C-4E2F-42A5-8F08-1E3C4EE4C586} = {4B78B79B-7EBE-405E-9BE3-3A59FFAD1910}
66+
{CE9C0E45-F613-4E28-89EE-7F646B028BFB} = {A4650FA0-4725-4956-90D3-F462F3C7474F}
67+
EndGlobalSection
68+
GlobalSection(ExtensibilityGlobals) = postSolution
69+
SolutionGuid = {FD9B9146-8418-4F80-A666-9B47BE4F9C9C}
70+
EndGlobalSection
71+
EndGlobal

README.md

Lines changed: 58 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,58 @@
1-
# Canal4Net
2-
C# client for canal. https://github.com/alibaba/canal
1+
2+
# CanalSharp
3+
4+
## 一.CanalSharp是什么?
5+
6+
CanalSharp 是阿里巴巴开源项目 Canal 的 .NET 客户端。为 .NET 开发者提供一个更友好的使用 Canal 的方式。Canal 是mysql数据库binlog的增量订阅&消费组件。
7+
8+
基于日志增量订阅&消费支持的业务:
9+
10+
1. 数据库镜像
11+
2. 数据库实时备份
12+
3. 多级索引 (卖家和买家各自分库索引)
13+
4. search build
14+
5. 业务cache刷新
15+
6. 价格变化等重要业务消息
16+
17+
关于 Canal 的更多信息请访问 https://github.com/alibaba/canal
18+
19+
## 二.如何使用
20+
21+
1.安装Canal
22+
23+
Canal的安装以及配置使用请查看 https://github.com/alibaba/canal
24+
25+
2.建立一个.NET Core App项目
26+
27+
3.为该项目从 Nuget 安装 CanalSharp
28+
29+
````shell
30+
Install-Package CanalSharp.Client
31+
````
32+
33+
4.建立与Canal的连接
34+
35+
````csharp
36+
//canal 配置的 destination,默认为 example
37+
var destination = "example";
38+
//创建一个简单CanalClient连接对象(此对象不支持集群)传入参数分别为 canal地址、端口、destination、用户名、密码
39+
var connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", "");
40+
//连接 Canal
41+
connector.Connect();
42+
//订阅,同时传入Filter,如果不传则以Canal的Filter为准。Filter是一种过滤规则,通过该规则的表数据变更才会传递过来
43+
connector.Subscribe("");
44+
//获取消息并且需要发送Ack表示消费成功
45+
connector.Get(batchSize);
46+
//获取消息但是不需要发送Ack来表示消费成功
47+
connector.GetWithoutAck(batchSize);
48+
````
49+
50+
更多详情请查看 Sample
51+
52+
## 三.贡献代码
53+
54+
1.fork本项目
55+
56+
2.做出你的更改
57+
58+
3.提交 pull request

build/package.props

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<Project>
22
<PropertyGroup Label="Package">
3-
<Description>C# client for canal. https://github.com/alibaba/canal</Description>
43
<Copyright></Copyright>
5-
<PackageLicenseUrl>https://github.com/Canal4Net/Canal4Net/blob/master/LICENSE</PackageLicenseUrl>
6-
<PackageProjectUrl>https://github.com/Canal4Net/Canal4Net</PackageProjectUrl>
7-
<RepositoryUrl>https://github.com/Canal4Net/Canal4Net.git</RepositoryUrl>
4+
5+
<Description>阿里巴巴mysql数据库binlog的增量订阅/消费组件 Canal 的 .NET 客户端</Description>
6+
<PackageLicenseUrl>https://github.com/CanalSharp/CanalSharp/blob/dev/LICENSE</PackageLicenseUrl>
7+
<PackageProjectUrl>https://github.com/CanalSharp/CanalSharp</PackageProjectUrl>
8+
<RepositoryUrl>https://github.com/CanalSharp/CanalSharp.git</RepositoryUrl>
89
<RepositoryType>git</RepositoryType>
910
<PackageTags>canal;mysql;binlog</PackageTags>
10-
<Company>Canal4Net Org.</Company>
11-
<Authors>stulzq,WithLin</Authors>
11+
<Company>CanalSharp Org.</Company>
12+
<Authors>stulzq,WithLin,CanalSharp</Authors>
1213
</PropertyGroup>
1314
</Project>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
3+
<PropertyGroup>
4+
<OutputType>Exe</OutputType>
5+
<TargetFramework>netcoreapp2.1</TargetFramework>
6+
</PropertyGroup>
7+
8+
<ItemGroup>
9+
<ProjectReference Include="..\..\src\CanalSharp.Client\CanalSharp.Client.csproj" />
10+
<ProjectReference Include="..\..\src\CanalSharp.Protocol\CanalSharp.Protocol.csproj" />
11+
</ItemGroup>
12+
13+
</Project>
Lines changed: 93 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,93 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Threading;
5+
using CanalSharp.Client.Impl;
6+
using Com.Alibaba.Otter.Canal.Protocol;
7+
8+
namespace CanalSharp.SimpleClient
9+
{
10+
class Program
11+
{
12+
static void Main(string[] args)
13+
{
14+
//canal 配置的 destination,默认为 example
15+
var destination = "example";
16+
//创建一个简单CanalClient连接对象(此对象不支持集群)传入参数分别为 canal地址、端口、destination、用户名、密码
17+
var connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", "");
18+
//连接 Canal
19+
connector.Connect();
20+
//订阅,同时传入Filter,如果不传则以Canal的Filter为准。Filter是一种过滤规则,通过该规则的表数据变更才会传递过来
21+
connector.Subscribe("");
22+
while (true)
23+
{
24+
//获取消息数据
25+
var message = connector.Get(5000);
26+
var batchId = message.Id;
27+
if (batchId == -1 || message.Entries.Count <= 0)
28+
{
29+
Console.WriteLine("没有数据了.............");
30+
Thread.Sleep(300);
31+
}
32+
PrintEntry(message.Entries);
33+
}
34+
}
35+
36+
private static void PrintEntry(List<Entry> entrys)
37+
{
38+
foreach (var entry in entrys)
39+
{
40+
if (entry.EntryType == EntryType.Transactionbegin || entry.EntryType == EntryType.Transactionend)
41+
{
42+
continue;
43+
}
44+
45+
RowChange rowChange = null;
46+
47+
try
48+
{
49+
rowChange = RowChange.Parser.ParseFrom(entry.StoreValue);
50+
}
51+
catch (Exception e)
52+
{
53+
54+
}
55+
56+
if (rowChange != null)
57+
{
58+
EventType eventType = rowChange.EventType;
59+
Console.WriteLine(
60+
$"================> binlog[{entry.Header.LogfileName}:{entry.Header.LogfileOffset}] , name[{entry.Header.SchemaName},{entry.Header.TableName}] , eventType :{eventType}");
61+
62+
foreach (var rowData in rowChange.RowDatas)
63+
{
64+
if (eventType == EventType.Delete)
65+
{
66+
PrintColumn(rowData.BeforeColumns.ToList());
67+
}
68+
else if (eventType == EventType.Insert)
69+
{
70+
PrintColumn(rowData.BeforeColumns.ToList());
71+
}
72+
else
73+
{
74+
Console.WriteLine("-------> before");
75+
PrintColumn(rowData.BeforeColumns.ToList());
76+
Console.WriteLine("-------> after");
77+
PrintColumn(rowData.AfterColumns.ToList());
78+
}
79+
}
80+
}
81+
82+
}
83+
}
84+
85+
private static void PrintColumn(List<Column> columns)
86+
{
87+
foreach (var column in columns)
88+
{
89+
Console.WriteLine($"{column.Name}{column.Value} update= {column.Updated}");
90+
}
91+
}
92+
}
93+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
<Project Sdk="Microsoft.NET.Sdk">
2+
<Import Project="../../build/common.props" />
3+
<PropertyGroup>
4+
<TargetFramework>netstandard2.0</TargetFramework>
5+
</PropertyGroup>
6+
7+
8+
<ItemGroup>
9+
<PackageReference Include="DotNetty.Codecs.Protobuf" Version="0.5.0" />
10+
</ItemGroup>
11+
12+
<ItemGroup>
13+
<ProjectReference Include="..\CanalSharp.Common\CanalSharp.Common.csproj" />
14+
<ProjectReference Include="..\CanalSharp.Protocol\CanalSharp.Protocol.csproj" />
15+
</ItemGroup>
16+
17+
</Project>

0 commit comments

Comments
 (0)