public static async Task RunParallelPassiveConsumerAsync( IConnection conn, MyWorkerContext ctx, int agentCount ) { var agentList = new List <ConsumingAgent>(); try { Console.WriteLine($"Sub ({agentCount}) start {ctx.Subject}"); ctx.CronoStart(); var listeners = new Task[agentCount]; for (int i = 0; i < agentCount; i++) { var agent = ConsumingAgent.CreatePassive(conn, ctx, null); agentList.Add(agent); listeners[i] = Task.Run(agent.PassiveWorkerAsync); } await Task.WhenAll(listeners); ctx.CronoStop(); Console.WriteLine($"Sub ({agentCount}) end {ctx.Subject}"); } finally { foreach (var agent in agentList) { agent.Dispose(); } } }
public static void RunParallelReactiveConsumer( IConnection conn, MyWorkerContext ctx, int agentCount ) { var agentList = new List <ConsumingAgent>(); try { Console.WriteLine($"Sub ({agentCount}) start {ctx.Subject}"); ctx.CronoStart(); var cde = new CountdownEvent(agentCount); for (int i = 0; i < agentCount; i++) { var agent = ConsumingAgent.CreateReactive(conn, ctx, cde); agentList.Add(agent); //ThreadPool.QueueUserWorkItem(agent.PassiveWorker); } cde.Wait(); ctx.CronoStop(); Console.WriteLine($"Sub ({agentCount}) end {ctx.Subject}"); } finally { foreach (var agent in agentList) { agent.Dispose(); } } }
public static ConsumingAgent CreateReactive( IConnection conn, MyWorkerContext ctx, CountdownEvent cde ) { var instance = new ConsumingAgent(); instance._subReactive = conn.SubscribeReactive(ctx.Subject + ".>", instance.ReactiveListener); instance._ctx = ctx; instance._cde = cde; return(instance); }