Skip to content

Commit c698213

Browse files
committed
refactor the code
1 parent 8c9ea49 commit c698213

File tree

3 files changed

+12
-27
lines changed

3 files changed

+12
-27
lines changed

sample/CanalSharp.SimpleClient/Program.cs

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -15,30 +15,17 @@ static void Main(string[] args)
1515
var connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", "");
1616
connector.Connect();
1717
connector.Subscribe();
18-
try
18+
while (true)
1919
{
20-
while (true)
20+
var message = connector.Get(5000);
21+
var batchId = message.Id;
22+
if (batchId == -1 || message.Entries.Count <= 0)
2123
{
22-
var message = connector.GetWithoutAck(5000);
23-
var batchId = message.Id;
24-
if (batchId == -1 || message.Entries.Count <= 0)
25-
{
26-
Console.WriteLine("=======没有数据了=======");
27-
Thread.Sleep(300);
28-
continue;
29-
}
30-
PrintEntry(message.Entries);
31-
32-
connector.Ack(batchId);
24+
Console.WriteLine("没有数据了.............");
25+
Thread.Sleep(300);
3326
}
27+
PrintEntry(message.Entries);
3428
}
35-
catch (Exception e)
36-
{
37-
Console.WriteLine(e);
38-
connector.Rollback();
39-
throw;
40-
}
41-
4229
}
4330

4431
private static void PrintEntry(List<Entry> entrys)

src/CanalSharp.Common/AbstractCanalLifeCycle.cs

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,4 @@
1-
// #region File Annotation
2-
//
3-
4-
5-
using CanalSharp.Common.Exception;
1+
using CanalSharp.Common.Exception;
62

73
namespace CanalSharp.Common
84
{
@@ -19,7 +15,7 @@ public virtual void Start()
1915
{
2016
if (Running)
2117
{
22-
throw new CanalException(this.GetType().Name + " has startup , don't repeat start");
18+
throw new CanalException($" {nameof(AbstractCanalLifeCycle)} has startup , don't repeat start");
2319
}
2420

2521
Running = true;
@@ -29,7 +25,7 @@ public virtual void Stop()
2925
{
3026
if (!Running)
3127
{
32-
throw new CanalException(this.GetType().Name + " isn't start , please check");
28+
throw new CanalException($"{nameof(AbstractCanalLifeCycle)} isn't start , please check");
3329
}
3430

3531
Running = false;

test/CanalSharp.UnitTests/UnitTest1.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ public void Test1()
1717
ICanalConnector connector = CanalConnectors.NewSingleConnector("127.0.0.1", 11111, destination, "", "");
1818
connector.Connect();
1919
Console.Read();
20+
21+
Mutex a=new Mutex(false);
2022
//lock (_lock)
2123
//{
2224
// new Thread(Test).Start();

0 commit comments

Comments
 (0)