Exemplo n.º 1
0
        public static void RunParallelReactiveConsumer(
            Original.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.CreatePassive(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();
                }
            }
        }
Exemplo n.º 2
0
        public static ConsumingAgent CreateReactive(
            Original.IConnection conn,
            MyWorkerContext ctx,
            CountdownEvent cde
            )
        {
            var instance = new ConsumingAgent();

            instance._subReactive = conn.SubscribeAsync(ctx.Subject + ".>", instance.ReactiveHandler);
            instance._ctx         = ctx;
            instance._cde         = cde;
            return(instance);
        }