Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
stulzq committed Sep 24, 2018
1 parent c698213 commit 4f16b2e
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 16 deletions.
60 changes: 57 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -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
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>
7 changes: 6 additions & 1 deletion sample/CanalSharp.SimpleClient/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
5 changes: 3 additions & 2 deletions src/CanalSharp.Client/CanalSharp.Client.csproj
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
<Project Sdk="Microsoft.NET.Sdk">

<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>
Expand Down
4 changes: 2 additions & 2 deletions src/CanalSharp.Common/CanalSharp.Common.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
Expand Down
4 changes: 2 additions & 2 deletions src/CanalSharp.Protocol/CanalSharp.Protocol.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">

<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../../build/common.props" />
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
Expand Down

0 comments on commit 4f16b2e

Please sign in to comment.