当前位置: 首页>>代码示例>>C#>>正文


C# ConnectionFactory.Request方法代码示例

本文整理汇总了C#中NATS.Client.ConnectionFactory.Request方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionFactory.Request方法的具体用法?C# ConnectionFactory.Request怎么用?C# ConnectionFactory.Request使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在NATS.Client.ConnectionFactory的用法示例。


在下文中一共展示了ConnectionFactory.Request方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Run

        public void Run(string[] args)
        {
            Stopwatch sw = null;

            parseArgs(args);
            banner();

            Options opts = ConnectionFactory.GetDefaultOptions();
            opts.Url = url;

            using (IConnection c = new ConnectionFactory().CreateConnection(opts))
            {
                sw = Stopwatch.StartNew();

                for (int i = 0; i < count; i++)
                {
                    c.Request(subject, payload);
                }
                c.Flush();

                sw.Stop();

                System.Console.Write("Completed {0} requests in {1} seconds ", count, sw.Elapsed.TotalSeconds);
                System.Console.WriteLine("({0} requests/second).",
                    (int)(count / sw.Elapsed.TotalSeconds));
                printStats(c);

            }
        }
开发者ID:bendan365,项目名称:csnats-wip,代码行数:29,代码来源:Requestor.cs

示例2: TestClosedConnections

        public void TestClosedConnections()
        {
            IConnection c = new ConnectionFactory().CreateConnection();
            ISyncSubscription s = c.SubscribeSync("foo");

            c.Close();

            // While we can annotate all the exceptions in the test framework,
            // just do it manually.
            UnitTestUtilities.testExpectedException(
                () => { c.Publish("foo", null); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.Publish(new Msg("foo")); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.SubscribeAsync("foo"); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.SubscribeSync("foo"); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.SubscribeAsync("foo", "bar"); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.SubscribeSync("foo", "bar"); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { c.Request("foo", null); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { s.NextMessage(); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { s.NextMessage(100); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { s.Unsubscribe(); },
                typeof(NATSConnectionClosedException));

            UnitTestUtilities.testExpectedException(
                () => { s.AutoUnsubscribe(1); },
                typeof(NATSConnectionClosedException));
        }
开发者ID:ColinSullivan1,项目名称:csnats,代码行数:53,代码来源:UnitTestConn.cs

示例3: TestRequestTimeout

 public void TestRequestTimeout()
 {
     using (IConnection c = new ConnectionFactory().CreateConnection())
     {
         try
         {
             c.Request("foo", null, 500);
             Assert.Fail("Expected an exception.");
         }
         catch (NATSTimeoutException)
         {
             Console.WriteLine("Received expected exception.");
         }
     }
 }
开发者ID:ColinSullivan1,项目名称:csnats,代码行数:15,代码来源:UnitTestBasic.cs

示例4: TestRequestNoBody

        public void TestRequestNoBody()
        {
            using (IConnection c = new ConnectionFactory().CreateConnection())
            {
                using (IAsyncSubscription s = c.SubscribeAsync("foo"))
                {
                    byte[] response = Encoding.UTF8.GetBytes("I will help you.");

                    s.MessageHandler += (sender, args) =>
                    {
                        c.Publish(args.Message.Reply, response);
                    };

                    s.Start();

                    Msg m = c.Request("foo", null, 50000);

                    if (!compare(m.Data, response))
                    {
                        Assert.Fail("Response isn't valid");
                    }
                }
            }
        }
开发者ID:ColinSullivan1,项目名称:csnats,代码行数:24,代码来源:UnitTestBasic.cs

示例5: TestEncodedObjectRequestReply

        public void TestEncodedObjectRequestReply()
        {
            using (IEncodedConnection c = new ConnectionFactory().CreateEncodedConnection())
            {
                Object mu = new Object();
                SerializationTestObj origObj = new SerializationTestObj();

                EventHandler<EncodedMessageEventArgs> eh = (sender, args) =>
                {
                    SerializationTestObj so = (SerializationTestObj)args.ReceivedObject;
                    Assert.IsTrue(so.Equals(origObj));
                    String str = "Received";

                    c.Publish(args.Reply, str);
                    c.Flush();

                    lock (mu)
                    {
                        Monitor.Pulse(mu);
                    }
                };

                using (IAsyncSubscription s = c.SubscribeAsync("foo", eh))
                {
                    Assert.IsTrue("Received".Equals(c.Request("foo", origObj, 1000)));
                    Assert.IsTrue("Received".Equals(c.Request("foo", origObj)));
                }
            }
        }
开发者ID:ColinSullivan1,项目名称:csnats,代码行数:29,代码来源:UnitTestEncoding.cs


注:本文中的NATS.Client.ConnectionFactory.Request方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。