本文整理汇总了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);
}
}
示例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));
}
示例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.");
}
}
}
示例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");
}
}
}
}
示例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)));
}
}
}