本文整理汇总了C#中NATS.Client.ConnectionFactory.NewInbox方法的典型用法代码示例。如果您正苦于以下问题:C# ConnectionFactory.NewInbox方法的具体用法?C# ConnectionFactory.NewInbox怎么用?C# ConnectionFactory.NewInbox使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类NATS.Client.ConnectionFactory
的用法示例。
在下文中一共展示了ConnectionFactory.NewInbox方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestAsyncSubscriberStarvation
public void TestAsyncSubscriberStarvation()
{
Object waitCond = new Object();
using (IConnection c = new ConnectionFactory().CreateConnection())
{
using (IAsyncSubscription helper = c.SubscribeAsync("helper"),
start = c.SubscribeAsync("start"))
{
helper.MessageHandler += (sender, arg) =>
{
System.Console.WriteLine("Helper");
c.Publish(arg.Message.Reply,
Encoding.UTF8.GetBytes("Hello"));
};
helper.Start();
start.MessageHandler += (sender, arg) =>
{
System.Console.WriteLine("Responsder");
string responseIB = c.NewInbox();
IAsyncSubscription ia = c.SubscribeAsync(responseIB);
ia.MessageHandler += (iSender, iArgs) =>
{
System.Console.WriteLine("Internal subscriber.");
lock (waitCond) { Monitor.Pulse(waitCond); }
};
ia.Start();
c.Publish("helper", responseIB,
Encoding.UTF8.GetBytes("Help me!"));
};
start.Start();
c.Publish("start", Encoding.UTF8.GetBytes("Begin"));
c.Flush();
lock (waitCond)
{
Assert.IsTrue(Monitor.Wait(waitCond, 2000));
}
}
}
}
示例2: TestInbox
public void TestInbox()
{
using (IConnection c = new ConnectionFactory().CreateConnection())
{
string inbox = c.NewInbox();
Assert.IsFalse(string.IsNullOrWhiteSpace(inbox));
Assert.IsTrue(inbox.StartsWith("_INBOX."));
}
}