-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from CanalSharp/dev
Release 0.0.1
- Loading branch information
Showing
48 changed files
with
7,733 additions
and
71 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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
13
sample/CanalSharp.SimpleClient/CanalSharp.SimpleClient.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}"); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
Oops, something went wrong.