本文整理汇总了C#中QueueManager.SubscribeForNewItem方法的典型用法代码示例。如果您正苦于以下问题:C# QueueManager.SubscribeForNewItem方法的具体用法?C# QueueManager.SubscribeForNewItem怎么用?C# QueueManager.SubscribeForNewItem使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueueManager
的用法示例。
在下文中一共展示了QueueManager.SubscribeForNewItem方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Main
static void Main(string[] args)
{
BootstrapManager.InitLogging();
BootstrapManager.BootRedis();
var queueManager = new QueueManager<Job>("urn:company:product:module:function");
queueManager.Flush();
queueManager.SubscribeForNewItem(
job => job.DoWork()
);
Console.WriteLine("Press ENTER to stop serving...");
Console.Read();
}
示例2: Test_Queue_Notifications_Concurrency
public void Test_Queue_Notifications_Concurrency()
{
int count = 100;
var qn = "q1";
var cq1 = new QueueManager<string>(qn);
var cq2 = new QueueManager<string>(qn);
var incomingMessages1 = new List<string>();
var incomingMessages2 = new List<string>();
cq1.Flush();
cq2.Flush();
cq1.SubscribeForNewItem(x => {
incomingMessages1.Add(x);
Log.Debug("Incoming item cq1 Value:" + x);
});
cq2.SubscribeForNewItem(x =>
{
incomingMessages2.Add(x);
Log.Debug("Incoming item cq2 Value:" + x);
});
int xx = 0;
for (int i = 0; i < count; i++)
{
Task.Factory.StartNew(() => {
int item = xx++;
Log.Debug("New Push:" + item.ToString() + " Thread:" + Thread.CurrentThread.ManagedThreadId);
cq1.Push(item.ToString(), true);
});
}
Log.Debug("Waiting...");
Thread.Sleep(2000);
Assert.AreEqual(incomingMessages1.Count + incomingMessages2.Count, count);
Log.Debug("Check if the queues are empty.");
var p1 = cq1.Pop();
Assert.IsNull(p1);
Log.Debug("Done!");
}