本文整理匯總了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."));
}
}