/
Program.cs
99 lines (85 loc) · 2.69 KB
/
Program.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
using System;
using Pitaya;
namespace PitayaCSharpExample
{
class Example
{
static void Main(string[] args)
{
Logger.SetLevel(LogLevel.DEBUG);
Console.WriteLine("c# prog running");
string serverId = System.Guid.NewGuid().ToString();
var sdConfig = new SDConfig(
endpoints: "http://127.0.0.1:4001",
etcdPrefix: "pitaya/",
heartbeatTTLSec: 60,
logHeartbeat: true,
logServerSync: true,
logServerDetails: true,
syncServersIntervalSec: 30,
logLevel: NativeLogLevel.Debug);
var sv = new Server(
id: serverId,
type: "csharp",
metadata: "{\"ip\":\"127.0.0.1\"}",
hostname: "localhost",
frontend: false);
NatsConfig nc = new NatsConfig("127.0.0.1:4222", 2000, 1000, 3, 100);
PitayaCluster cluster = null;
PitayaCluster.AddSignalHandler(() =>
{
Logger.Info("Calling terminate on cluster");
PitayaCluster.Terminate();
Logger.Info("Cluster terminated, exiting app");
Environment.Exit(1);
//Environment.FailFast("oops");
});
try
{
PitayaCluster.Initialize(sdConfig, nc, sv);
}
catch (PitayaException exc)
{
Logger.Error("Failed to create cluster: {0}", exc.Message);
Environment.Exit(1);
}
Logger.Info("pitaya lib initialized successfully :)");
TestRemote tr = new TestRemote();
PitayaCluster.RegisterRemote(tr);
System.Threading.Thread.Sleep(1000);
try
{
var res = PitayaCluster.Rpc<Protos.RPCRes>(Route.FromString("csharp.testremote.remote"), null);
Console.WriteLine($"Code: {res.Code}");
Console.WriteLine($"Msg: {res.Msg}");
}
catch (PitayaException exc)
{
Console.WriteLine($"RPC failed: {exc.Message}");
}
while(true){}
//Console.ReadKey();
//
// Server sv = PitayaCluster.GetServer(serverId);
// Logger.Info("got server with id: {0}", sv.id);
//
// Protos.RPCMsg msg = new Protos.RPCMsg();
// msg.Msg = "hellow from bla";
//
// try
// {
// Protos.RPCRes res = PitayaCluster.RPC<Protos.RPCRes>(Pitaya.Route.fromString("connector.testremote.test"), msg);
// Logger.Info("received rpc res {0}", res);
// }
// catch (Exception e)
// {
// Logger.Error("deu ruim: {0}", e);
// }
//
// Console.ReadKey();
// PitayaCluster.Shutdown();
// }
// }
}
}
}