Пример #1
0
 void subscribe(INATS nats, string subject, int count, ILog log)
 {
     nats.Subscribe(subject, (data) =>
     {
         log.Info("Received {0}", count);
         //log.Trace(data);
         count--;
     });
     while (count > 0)
     {
         System.Threading.Thread.Sleep(250);
     }
 }
Пример #2
0
 void publish(INATS nats, string subject, string data, int count, ILog log)
 {
     if (System.IO.File.Exists(data))
     {
         data = System.IO.File.ReadAllText(data);
     }
     for (int i = 0; i < count && nats.Connected; i++)
     {
         string msg = string.Format(data, i);
         log.Info("Sending {0}", i);
         nats.Publish(subject, msg);
         //System.Threading.Thread.Sleep(100);//System.Threading.Timeout.Infinite);
     }
 }
Пример #3
0
 void publish(INATS nats, string subject, string data, int count, ILog log)
 {
     if (System.IO.File.Exists(data))
     {
         data = System.IO.File.ReadAllText(data);
     }
     for (int i = 0; i < count && nats.Connected; i++)
     {
         string msg = string.Format(data, i);
         log.Info("Sending {0}", i);
         nats.Publish(subject,msg);
         //System.Threading.Thread.Sleep(100);//System.Threading.Timeout.Infinite);
     }
 }
Пример #4
0
        void run(CLIOptions opts)
        {
            ILog  log  = null;
            INATS nats = null;

            try
            {
                log = new dotnet_nats.log.Logger(opts.loglevel);
                IFactory f = new Factory(log);
                nats = new NATS(f, opts, log);
                var t = nats.Connect();
                t.Wait();
                if (t.Result)
                {
                    if (opts.mode.Equals("pub", StringComparison.InvariantCultureIgnoreCase))
                    {
                        publish(nats, opts.subject, opts.data, opts.count, log);
                    }
                    else if (opts.mode.Equals("sub", StringComparison.InvariantCultureIgnoreCase))
                    {
                        subscribe(nats, opts.subject, opts.count, log);
                    }
                    else
                    {
                        log.Fatal("Unknown mode supplied: {0}", opts.mode);
                    }
                }
                else
                {
                    throw new Exception("Failed to connect to server");
                }
            }
            catch (Exception ex)
            {
                if (log != null)
                {
                    log.Error("Error processing", ex);
                }
                //throw;
            }
            finally
            {
                if (nats != null)
                {
                    nats.Close();
                }
                nats = null;
            }
        }
Пример #5
0
 void subscribe(INATS nats, string subject, int count, ILog log)
 {
     nats.Subscribe(subject, (data) =>
     {
         log.Info("Received {0}", count);
         //log.Trace(data);
         count--;
     });
     while (count > 0) { System.Threading.Thread.Sleep(250); }
 }