Ejemplo n.º 1
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;
            }
        }
Ejemplo n.º 2
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;
     }
 }