Exemplo n.º 1
0
        public static void SubscribeToNatsTopic()
        {
            NatsClient <Message> client = new NatsClient <Message>();

            EventHandler <EncodedMessageEventArgs> handler = (sender, args) =>
            {
                Message obj = (Message)args.ReceivedObject;
                AddToCache(obj);

                System.Console.WriteLine("From: " + obj.UserName);
                System.Console.WriteLine("Message: " + obj.TextMessage);
                System.Console.WriteLine("Time: " + obj.TimeStamp);
            };

            client.Subscribe(TopicName, handler);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Runs the Dea Reactor. This function is not blocking.
        /// </summary>
        public override void Start()
        {
            base.Start();

            NatsClient.Subscribe("dea.status", this.OnDeaStatus);
            NatsClient.Subscribe("droplet.status", this.OnDropletStatus);
            NatsClient.Subscribe("dea.discover", this.OnDeaDiscover);
            NatsClient.Subscribe("dea.find.droplet", this.OnDeaFindDroplet);
            NatsClient.Subscribe("dea.update", this.OnDeaUpdate);

            NatsClient.Subscribe("dea.stop", this.OnDeaStop);
            NatsClient.Subscribe(string.Format(CultureInfo.InvariantCulture, Strings.NatsMessageDeaStart, this.UUID), this.OnDeaStart);

            NatsClient.Subscribe("router.start", this.OnRouterStart);
            NatsClient.Subscribe("healthmanager.start", this.OnHealthManagerStart);
        }
        /// <summary>
        /// Runs the Dea Reactor. This function is not blocking.
        /// </summary>
        public override void Start()
        {
            base.Start();

            NatsClient.Subscribe("dea.status", this.OnDeaStatus);

            NatsClient.Subscribe("dea.find.droplet", this.OnDeaFindDroplet);
            NatsClient.Subscribe("dea.update", this.OnDeaUpdate);
            NatsClient.Subscribe("dea.locate", this.OnDeaLocate);

            NatsClient.Subscribe("staging.locate", this.OnStagingLocate);

            NatsClient.Subscribe("dea.stop", this.OnDeaStop);
            NatsClient.Subscribe(string.Format(CultureInfo.InvariantCulture, "dea.{0}.start", this.UUID), this.OnDeaStart);

            NatsClient.Subscribe("router.start", this.OnRouterStart);
            NatsClient.Subscribe("healthmanager.start", this.OnHealthManagerStart);
        }
Exemplo n.º 4
0
        static async Task Main(string[] args)
        {
            Console.WriteLine("Hello World!");

            // hit ctrl-C to close/exit

            var cts = new CancellationTokenSource();

            Console.CancelKeyPress += (_, e) =>
            {
                Console.WriteLine("cancelled...");
                cts.Cancel();
                e.Cancel = true;
            };

            var sp = ConfigureServices();

            var nats = new NatsClient();
            await nats.StartAsync(new IPEndPoint(IPAddress.Loopback, 4222), sp);

            nats.Connect(new ConnectOperation {
                Verbose = false
            });

            nats.Subscribe("test", msg =>
            {
                var text = Encoding.UTF8.GetString(msg.Data.Span);
                Console.WriteLine($"OnMsg: subject:{msg.Subject} sid:{msg.Sid} replyto:{msg.ReplyTo} text:{text}");
            });

            while (!cts.Token.IsCancellationRequested)
            {
                Console.WriteLine("pub...");
                nats.Publish("test", Encoding.UTF8.GetBytes("hello"));
                await Task.Delay(2000);
            }

            Console.WriteLine("done...");
            Console.ReadLine();
        }
 public void SubscribeToStaging()
 {
     NatsClient.Subscribe(string.Format(CultureInfo.InvariantCulture, "staging.{0}.start", this.UUID), this.OnStagingStart);
     NatsClient.Subscribe("staging.stop", this.OnStagingStop);
 }