static void Main(string[] args) { IMessageProcessor processor = MessageFactory.GetInstance(); processor.Init(10000, 5000); processor.Register(new MessageContext() { Key = "IES", Address = new string[] { "10.130.36.225:9015" }, QueueSize = 16 }); processor.AddMessage("IES", new IESMessage() { ID = "IES001", DeviceID = "Device001" }); Thread.Sleep(5000); processor.Register(new MessageContext() { Key = "LIVE", Address = new string[] { "10.130.36.225:9017" }, QueueSize = 16 }); processor.AddMessage("LIVE", new LIVEMessage() { MsgBody = "LIVE001&Device002" }); Thread.Sleep(5000); processor.AddMessage("IES", new IESMessage() { ID = "IES002", DeviceID = "Device001" }); processor.AddMessage("LIVE", new LIVEMessage() { MsgBody = "LIVE002&Device002" }); //Thread t = new Thread(new ParameterizedThreadStart(SetStatus1)); //t.Start(processor); //Thread.Sleep(5000); //Console.WriteLine(DateTime.Now + " Main SetTargetStatus"); //processor.SetTargetStatus("key1", true); //Console.WriteLine(DateTime.Now + " AddMessage"); //processor.AddMessage("key2", new MyMessage()); //processor.AddMessage("key1", new MyMessage()); //Thread.Sleep(5000); //processor.SetTargetAddress("key2", new string[] { "10.130.36.100:1111" }); //processor.SetTargetStatus("key2", true); //Thread.Sleep(5000); //Thread t2 = new Thread(new ParameterizedThreadStart(SetStatus2)); //t2.Start(processor); //Thread.Sleep(5000); //Console.WriteLine(DateTime.Now + " Main SetTargetStatus"); //processor.SetTargetStatus("key2", true); //processor.AddMessage("key2", new MyMessage()); Console.ReadKey(); }
private void RegisterHandlers(IMessageProcessor _, CancellationToken token) { _.Register(handlerBuilder => handlerBuilder.Build <PumpCalculateOneCommandHandler>(token)); //_.Register(handlerBuilder => handlerBuilder.Build<PumpCalculateOneCommandHandler>(token)); //_.Register(handlerBuilder => handlerBuilder.Build<PumpCalculateOneCommandHandler>(token)); //_.Register(handlerBuilder => handlerBuilder.Build<PumpCalculateOneCommandHandler>(token)); //_.Register(handlerBuilder => handlerBuilder.Build<PumpCalculateOneCommandHandler>(token)); }
private void RegisterCommandHandler(ServiceProvider provider) { try { _messageProcessor.Register(provider); } catch (Exception e) { _logger.LogInformation(e.Message); throw; } }
static void Main(string[] args) { IMessageProcessor processor = MessageFactory.GetInstance(); processor.Init(10000, 3000); processor.Register(new MessageContext() { Key = "IES", Address = new string[] { "10.130.36.225:8013" }, QueueSize = 16 }); processor.AddMessage("IES", new MyMessage()); processor.AddMessage("IES", new MyMessage()); processor.AddMessage("IES", new MyMessage()); Thread.Sleep(3005); processor.SetUdpPort(11111); processor.AddMessage("IES", new MyMessage()); processor.AddMessage("IES", new MyMessage()); processor.AddMessage("IES", new MyMessage()); Thread.Sleep(5000); processor.AddMessage("IES", new MyMessage()); processor.AddMessage("IES", new MyMessage()); processor.AddMessage("IES", new MyMessage()); ////processor.Register(new MessageContext() { Key = "key1", Address = new string[] { "10.130.36.225:11000" }, QueueSize = 16 }); ////processor.AddMessage("key1", new MyMessage()); //processor.Register(new MessageContext() { Key = "key1", Address = new string[] { "10.130.36.225:10000", "10.130.36.224:10000" }, QueueSize = 16 }); //processor.AddMessage("key1", new MyMessage()); //Thread.Sleep(5000); //processor.Register(new MessageContext() { Key = "key2", Address = new string[] { "10.130.36.111:10000", "10.130.36.222:10000" }, QueueSize = 16 }); //processor.AddMessage("key2", new MyMessage()); //Thread.Sleep(5000); //Thread t = new Thread(new ParameterizedThreadStart(SetStatus1)); //t.Start(processor); //Thread.Sleep(5000); //Console.WriteLine(DateTime.Now + " Main SetTargetStatus"); //processor.SetTargetStatus("key1", true); //Console.WriteLine(DateTime.Now + " AddMessage"); //processor.AddMessage("key2", new MyMessage()); //processor.AddMessage("key1", new MyMessage()); //Thread.Sleep(5000); //processor.SetTargetAddress("key2", new string[] { "10.130.36.100:1111" }); //processor.SetTargetStatus("key2", true); //Thread.Sleep(5000); //Thread t2 = new Thread(new ParameterizedThreadStart(SetStatus2)); //t2.Start(processor); //Thread.Sleep(5000); //Console.WriteLine(DateTime.Now + " Main SetTargetStatus"); //processor.SetTargetStatus("key2", true); //processor.AddMessage("key2", new MyMessage()); Console.ReadKey(); }
/// <summary> /// Run receiver /// </summary> /// <typeparam name="T"></typeparam> /// <param name="context"></param> /// <param name="taskCount"></param> /// <param name="receiver"></param> /// <returns></returns> public Task Run(IWorkContext context, int taskCount, Func <Message, Task> receiver) { context.Verify(nameof(context)).IsNotNull(); context.Container.Verify(nameof(context.Container)).IsNotNull(); taskCount.Verify(nameof(taskCount)).Assert(x => x >= 1, "Number of task must greater or equal to 1"); receiver.Verify(nameof(receiver)).IsNotNull(); var tasks = Enumerable.Range(0, taskCount) .Select(x => { IMessageProcessor messageProcessor = context.Container !.Resolve <IMessageProcessor>(); _messageProcessors.Add(messageProcessor); context.Telemetry.Info(context, "Starting receiver"); return(messageProcessor.Register(context, receiver)); }) .ToList(); return(Task.WhenAll(tasks)); }