void InitButtonClicked() { Pitaya.Logger.SetLevel(LogLevel.DEBUG); Console.WriteLine("c# prog running"); SDConfig sdConfig = new SDConfig("127.0.0.1:2379", 30, "pitaya/", 30, true, 60); NatsRPCClientConfig rpcClientConfig = new NatsRPCClientConfig("nats://localhost:4222", 10, 5000); // TODO does it makes sense to give freedom to set reconnectionRetries and messagesBufferSize? NatsRPCServerConfig rpcServerConfig = new NatsRPCServerConfig("nats://localhost:4222", 10, 75); PitayaCluster.Init( sdConfig, rpcClientConfig, rpcServerConfig, new Server( System.Guid.NewGuid().ToString(), "unity", "{\"ip\":\"127.0.0.1\"}", false) ); TestRemote tr = new TestRemote(); PitayaCluster.RegisterRemote(tr); }
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:2379", etcdPrefix: "pitaya/", serverTypeFilters: new List <string>(), heartbeatTTLSec: 60, logHeartbeat: true, logServerSync: true, logServerDetails: true, syncServersIntervalSec: 30, maxNumberOfRetries: 0, retryDelayMilliseconds: 0); var sv = new Server( id: serverId, type: "csharp", metadata: "", hostname: "localhost", frontend: false); var natsConfig = new NatsConfig( endpoint: "127.0.0.1:4222", connectionTimeoutMs: 2000, requestTimeoutMs: 1000, serverShutdownDeadlineMs: 3, serverMaxNumberOfRpcs: 100, maxConnectionRetries: 3, maxPendingMessages: 1000, reconnectBufSize: 4 * 1024 * 1024); var grpcConfig = new GrpcConfig( host: "127.0.0.1", port: 5444, serverShutdownDeadlineMs: 2000, serverMaxNumberOfRpcs: 200, clientRpcTimeoutMs: 10000 ); Dictionary <string, string> constantTags = new Dictionary <string, string> { { "game", "game" }, { "serverType", "svType" } }; var statsdMR = new StatsdMetricsReporter("localhost", 5000, "game", constantTags); MetricsReporters.AddMetricReporter(statsdMR); var prometheusMR = new PrometheusMetricsReporter("default", "game", 9090); MetricsReporters.AddMetricReporter(prometheusMR); 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( grpcConfig, sdConfig, sv, NativeLogLevel.Debug, new PitayaCluster.ServiceDiscoveryListener((action, server) => { switch (action) { case PitayaCluster.ServiceDiscoveryAction.ServerAdded: Console.WriteLine("Server was added"); Console.WriteLine(" id: " + server.id); Console.WriteLine(" type: " + server.type); break; case PitayaCluster.ServiceDiscoveryAction.ServerRemoved: Console.WriteLine("Server was removed"); Console.WriteLine(" id: " + server.id); Console.WriteLine(" type: " + server.type); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } })); //PitayaCluster.Initialize(natsConfig, sdConfig, sv, NativeLogLevel.Debug, ""); } catch (PitayaException exc) { Logger.Error("Failed to create cluster: {0}", exc.Message); Environment.Exit(1); } Logger.Info("pitaya lib initialized successfully :)"); var tr = new TestRemote(); PitayaCluster.RegisterRemote(tr); var th = new TestHandler(); PitayaCluster.RegisterHandler(th); Thread.Sleep(1000); TrySendRpc(); Console.ReadKey(); PitayaCluster.Terminate(); }
private void Init() { Debug.Log("Init button clicked!"); NPitaya.Models.Logger.SetLevel(LogLevel.DEBUG); Console.WriteLine("c# prog running"); string serverId = Guid.NewGuid().ToString(); var sdConfig = new SDConfig( endpoints: "http://10.0.21.167:2379", etcdPrefix: "pitaya/", serverTypeFilters: new List <string>(), heartbeatTTLSec: 60, logHeartbeat: false, logServerSync: true, logServerDetails: false, syncServersIntervalSec: 60, maxNumberOfRetries: 10, retryDelayMilliseconds: 100); var grpcConfig = new GrpcConfig( host: "127.0.0.1", port: 3000, serverShutdownDeadlineMs: 3000, serverMaxNumberOfRpcs: 1000, clientRpcTimeoutMs: 4000 ); var sv = new Server( serverId, "csharp", "{\"ip\":\"127.0.0.1\"}", "localhost", false); var nc = new NatsConfig( endpoint: "127.0.0.1:4222", connectionTimeoutMs: 2000, requestTimeoutMs: 2000, serverShutdownDeadlineMs: 4000, serverMaxNumberOfRpcs: 1000, maxConnectionRetries: 10, maxPendingMessages: 100, reconnectBufSize: 4 * 1024 * 1024); Debug.Log("Adding signal handler"); Debug.Log("Adding signal handler DONE"); try { Debug.Log("Initializing PitayaCluster"); // PitayaCluster.Initialize(sdConfig, nc, sv); var listener = new PitayaCluster.ServiceDiscoveryListener((action, server) => { switch (action) { case PitayaCluster.ServiceDiscoveryAction.ServerAdded: Debug.Log("Server added:"); Debug.Log(" id: " + server.id); Debug.Log(" type:" + server.type); break; case PitayaCluster.ServiceDiscoveryAction.ServerRemoved: Debug.Log("Server removed:"); Debug.Log(" id: " + server.id); Debug.Log(" type:" + server.type); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } }); #if UNITY_EDITOR PitayaCluster.Initialize(nc, sdConfig, sv, NativeLogLevel.Debug, listener, "MY_LOG_FILE.txt"); #else PitayaCluster.Initialize(grpcConfig, sdConfig, sv, NativeLogLevel.Debug, listener); #endif } catch (PitayaException e) { Debug.LogError($"Failed to create cluster {e.Message}"); Application.Quit(); return; } NPitaya.Models.Logger.Info("pitaya lib initialized successfully :)"); var tr = new TestRemote(); PitayaCluster.RegisterRemote(tr); }
static void Main(string[] args) { Logger.SetLevel(LogLevel.DEBUG); Console.WriteLine("c# prog running"); string serverId = System.Guid.NewGuid().ToString(); SDConfig sdConfig = new SDConfig("127.0.0.1:2379", 30, "pitaya/", 30, true, 60); // NatsRPCClientConfig rpcClientConfig = new NatsRPCClientConfig("nats://localhost:4222", 10, 5000); // // TODO does it makes sense to give freedom to set reconnectionRetries and messagesBufferSize? // NatsRPCServerConfig rpcServerConfig = new NatsRPCServerConfig("nats://localhost:4222", 10, 75); // PitayaCluster.Init( // sdConfig, // rpcClientConfig, // rpcServerConfig, // new Server( // serverId, // "csharp", // "{\"ip\":\"127.0.0.1\"}", // false) // ); GrpcRPCClientConfig grpcClientConfig = new GrpcRPCClientConfig(5000, 5000, "127.0.0.1:2379", "pitaya/"); GrpcRPCServerConfig grpcServerConfig = new GrpcRPCServerConfig(5340); PitayaCluster.Init( sdConfig, grpcClientConfig, grpcServerConfig, new Server( serverId, "csharp", "{\"ip\":\"127.0.0.1\",\"grpc-host\":\"127.0.0.1\",\"grpc-port\":\"5340\"}", false) ); PitayaCluster.ConfigureJaeger(1.0, GoString.fromString("test-svc")); TestRemote tr = new TestRemote(); PitayaCluster.RegisterRemote(tr); // prevent from closing 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(); }
static void Main(string[] args) { Logger.SetLevel(LogLevel.DEBUG); Console.WriteLine("c# prog running"); var constantTags = new Dictionary<string, string> { {"game", "game"}, {"serverType", "svType"} }; AppDomain.CurrentDomain.ProcessExit += (object sender, EventArgs args) => { Console.WriteLine("shutting down pitaya cluster"); PitayaCluster.Terminate(); }; var customMetrics = new CustomMetrics(); customMetrics.AddHistogram( "my_histogram", new HistogramBuckets(HistogramBucketKind.Linear, 1, 2, 10), "Some test histogram", new []{"my_label"}); var metricsParameters = new MetricsConfiguration( true, "127.0.0.1", "8000", "myns", customMetrics); try { PitayaCluster.Initialize( "exampleapp", "csharp.toml", new Server( id: Guid.NewGuid().ToString(), kind: "csharp", metadata: "{}", hostname: "ololo", frontend: false ), NativeLogLevel.Debug, NativeLogKind.Console, (msg) => { Console.Write($"C# Log: {msg}"); }, metricsParameters, new PitayaCluster.ServiceDiscoveryListener((action, server) => { switch (action) { case PitayaCluster.ServiceDiscoveryAction.ServerAdded: Console.WriteLine("Server was added"); Console.WriteLine(" id: " + server.Id); Console.WriteLine(" kind: " + server.Kind); break; case PitayaCluster.ServiceDiscoveryAction.ServerRemoved: Console.WriteLine("Server was removed"); Console.WriteLine(" id: " + server.Id); Console.WriteLine(" kind: " + server.Kind); break; default: throw new ArgumentOutOfRangeException(nameof(action), action, null); } })); } catch (PitayaException exc) { Logger.Error("Failed to create cluster: {0}", exc.Message); Environment.Exit(1); } Logger.Info("pitaya lib initialized successfully :)"); PitayaCluster.RegisterRemote(new TestRemote()); PitayaCluster.RegisterHandler(new TestHandler()); TrySendRpc(); PitayaCluster.WaitShutdownSignal(); }