Exemplo n.º 1
0
        public static void Main(string[] args)
        {
            //var subManager = new SubscriptionManager();

            var service = new PubSubImpl();

            Core.Server server = new Core.Server
            {
                Services = { Demos.PubSub.BindService(service) },
                Ports    = { new ServerPort("localhost", Port, ServerCredentials.Insecure) }
            };
            server.Start();


            bool shouldRun = true;

            Random rand = new Random(1000);


            Thread t = new Thread(() =>
            {
                while (shouldRun)
                {
                    if (service.SubscriberWritersMap.Any())
                    {
                        var indexedKeys = service.SubscriberWritersMap.Select((kvp, idx) => new
                        {
                            Idx = idx,
                            Key = kvp.Key
                        });

                        var subscriptionIdx      = rand.Next(service.SubscriberWritersMap.Count);
                        var randomSubscriptionId = indexedKeys.Single(x => x.Idx == subscriptionIdx).Key;
                        service.Publish(new SubscriptionEvent()
                        {
                            Event = new Event()
                            {
                                Value = $"And event for '{randomSubscriptionId}' {Guid.NewGuid().ToString("N")}"
                            },
                            SubscriptionId = randomSubscriptionId
                        });
                    }

                    Thread.Sleep(2000);
                }
            });

            t.Start();

            Console.WriteLine("Greeter server listening on port " + Port);
            Console.WriteLine("Press any key to stop the server...");



            Console.ReadKey();
            shouldRun = false;

            server.ShutdownAsync().Wait();
        }
 public async Task StopAsync(CancellationToken cancellationToken)
 {
     if (Interlocked.Exchange(ref this._stopped, 1) == 1)
     {
         return;
     }
     await _server.ShutdownAsync();
 }
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            const int port   = 9000;
            var       cacert = File.ReadAllText(@"ca.crt");
            var       cert   = File.ReadAllText(@"server.crt");
            var       key    = File.ReadAllText(@"server.key");

            var keypair        = new KeyCertificatePair(cert, key);
            var sslCredentials = new SslServerCredentials(new List <KeyCertificatePair> {
                keypair
            }, cacert, false);

            var server = new Core.Server
            {
                Ports    = { new ServerPort("0.0.0.0", port, sslCredentials) },
                Services = { Messages.EmployeeService.BindService(new EmployeeService()) }
            };

            server.Start();
            Console.WriteLine("Starting server ..");
            Console.ReadLine();
            server.ShutdownAsync().Wait();
        }