Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("Press 'Enter' to send a message. To exit, Ctrl + C");

            var bus = BusCreator.CreateBus();

            bus.Start();

            //创建请求客户端
            var client = CreateRequestClient(bus);

            for (;;)
            {
                Console.Write("Enter customer id (quit exits): ");
                string customerId = Console.ReadLine();
                if (customerId == "quit")
                {
                    break;
                }

                // this is run as a Task to avoid weird console application issues
                Task.Run(async() =>
                {
                    //发起请求,获得响应
                    var response = await client.Request(new SimpleRequest()
                    {
                        CustomerId = customerId
                    });

                    //打印响应信息
                    Console.WriteLine("Customer Name: {0}", response.CusomerName);
                }).Wait();
            }
        }
Beispiel #2
0
        static async Task Main(string[] args)
        {
            Console.Title = "Consumer 2";

            var bus = BusCreator.CreateBus((cfg, host) =>
            {
                cfg.ReceiveEndpoint(host, Constants.QueueA, e =>
                {
                    e.Handler <RequestA>(context =>
                    {
                        Console.WriteLine($"Receive Request: id={context.Message.Id}, {context.Message.DateTime}");

                        return(context.RespondAsync <ResponseA>(new
                        {
                            Id = context.Message.Id,
                            DateTime = DateTime.Now,
                        }));
                    });
                });
            });

            await bus.StartAsync();

            Console.WriteLine($"Listening ({Constants.QueueA})... Press enter to exit.");
            Console.ReadLine();

            await bus.StopAsync();
        }
        static async Task Main(string[] args)
        {
            Console.Title = "Producer";

            Console.WriteLine("Press 'Enter' to send a message. To exit, Ctrl + C");

            var bus = BusCreator.CreateBus();
            await bus.StartAsync();

            while (Console.ReadLine() != null)
            {
                var command = new
                {
                    Id       = Guid.NewGuid(),
                    DateTime = DateTime.Now
                };
                await bus.Publish <EventA>(command);

                Console.WriteLine($"Publish Event: id={command.Id}, {command.DateTime}");
            }

            Console.ReadLine();

            await bus.StopAsync();
        }
Beispiel #4
0
        static async Task Main(string[] args)
        {
            Console.Title = "Producer";

            Console.WriteLine("Press 'Enter' to send a message. To exit, Ctrl + C");

            var bus = BusCreator.CreateBus();
            await bus.StartAsync();

            while (Console.ReadLine() != null)
            {
                var request = new
                {
                    Id       = Guid.NewGuid(),
                    DateTime = DateTime.Now
                };

                var response = await bus.Request <RequestA, ResponseA>(
                    new Uri($"{Constants.RabbitMqUri}{Constants.QueueA}"),
                    request);

                Console.WriteLine($"Send Request: id={request.Id}, {request.DateTime}");
                Console.WriteLine($"Receive Response: id={response.Message.Id}, {response.Message.DateTime}");
            }

            Console.ReadLine();

            await bus.StopAsync();
        }
        static async Task Main(string[] args)
        {
            Console.Title = "Producer";

            Console.WriteLine("Press 'Enter' to send a message. To exit, Ctrl + C");

            var bus = BusCreator.CreateBus();
            await bus.StartAsync();

            var sendToUri = new Uri($"{Constants.RabbitMqUri}{Constants.QueueA}");
            var endPoint  = await bus.GetSendEndpoint(sendToUri);

            while (Console.ReadLine() != null)
            {
                var command = new
                {
                    Id       = Guid.NewGuid(),
                    DateTime = DateTime.Now
                };
                await endPoint.Send <CommandA>(command);

                Console.WriteLine($"Send Command: id={command.Id}, {command.DateTime}");
            }

            Console.ReadLine();

            await bus.StopAsync();
        }
Beispiel #6
0
        /// <summary>
        /// 全部监听
        /// </summary>
        /// <param name="process"></param>
        private static void CreateBusListener(ProcessConfig process)
        {
            Dictionary <string, IConsumer <Models.ProcessContext> > dictionary =
                new Dictionary <string, IConsumer <Models.ProcessContext> >()
            {
                { "flow_waitInStock", new WaitInStockConsumer() },
                { "flow_inStock", new InStockConsumer() },
                { "flow_gateway", new GatewayConsumer() },
                { "flow_warning", new WarningServiceConsumer() },
                { "flow_notify1", new NotifyServiceConsumer() },
                { "flow_notify2", new NotifyServiceConsumer() },
                { "flow_end", new EndConsumer() },
            };

            foreach (var item in dictionary)
            {
                var bus = BusCreator.CreateBus(process, (cfg, host) =>
                {
                    cfg.ReceiveEndpoint(host, item.Key, e =>
                    {
                        e.Instance(item.Value);
                        //e.QueueExpiration = TimeSpan.MaxValue;
                        //e.Durable = true;
                    });
                });
                bus.Start();
            }
        }
Beispiel #7
0
 public GreetingServer()
 {
     _log.Info("register consumer");
     _bus = BusCreator.CreateBus((cfg, host) =>
     {
         cfg.ReceiveEndpoint(host, RabbitMqConstants.GreetingQueue, e =>
         {
             e.Consumer <GreetingConsumer>();
         });
     });
 }
Beispiel #8
0
        public GreetingServer()
        {
            var configurations = AppSettings.RabbitMqConfigurations;

            log.Info("register consumer");
            bus = BusCreator.Create(configurations, (cfg, host) =>
            {
                cfg.ReceiveEndpoint(host, configurations.WindowsServiceQueue, e =>
                {
                    e.Consumer <WindowsServiceConsumer>();
                });
            });
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Press 'Enter' to send a message.To exit, Ctrl + C");

            var bus       = BusCreator.CreateBus();
            var sendToUri = new Uri($"{RabbitMqConstants.RabbitMqUri}{RabbitMqConstants.GreetingQueue}");

            while (Console.ReadLine() != null)
            {
                Task.Run(() => SendCommand(bus, sendToUri)).Wait();
            }

            Console.ReadLine();
        }
Beispiel #10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Start Request Service 提供服务:");
            var bus = BusCreator.CreateBus((cfg, host) =>
            {
                cfg.ReceiveEndpoint(host, RabbitMqConstants.RequestClientQueue, e =>
                {
                    e.Consumer <RequestConsumer>();
                });
            });

            bus.Start();

            Console.WriteLine("Listening for Request.. Press enter to exit");
            Console.ReadLine();

            bus.Stop();
        }
Beispiel #11
0
        public void Start()
        {
            _bus = BusCreator.CreateBus(Context.ProcessConfig);
            _bus.Start();

            // 根据process配置,找到第一个start
            var startId   = Context.ProcessConfig.StartEvent.Id;
            var startFlow = Context.ProcessConfig.SequenceFlow.FirstOrDefault(t => t.SourceRef == startId);

            if (startFlow == null)
            {
                return;
            }
            Context.CurrentSequenceFlow = startFlow;
            var sendToUri = new Uri($"{Context.ProcessConfig.RabbitMqUri.Url}{startFlow?.Id}");

            BusCreator.SendCommand(_bus, sendToUri, Context);
        }
Beispiel #12
0
        static void Main(string[] args)
        {
            Console.WriteLine("SubscriberB");

            var bus = BusCreator.CreateBus((cfg, host) =>
            {
                cfg.ReceiveEndpoint(host, RabbitMqConstants.GreetingEventSubscriberBQueue, e =>
                {
                    e.Consumer <GreetingEventConsumer>();
                });
            });

            bus.Start();

            Console.WriteLine("Listening for Greeting events.. Press enter to exit");
            Console.ReadLine();

            bus.Stop();
        }
        static void Main(string[] args)
        {
            Console.Title = "Greeting";

            var bus = BusCreator.CreateBus((cfg, host) =>
            {
                cfg.ReceiveEndpoint(host, RabbitMqConstants.GreetingQueue, e =>
                {
                    e.Consumer <GreetingConsumer>();
                    e.Consumer <GreetingConsumerB>();
                });
            });

            bus.Start();

            Console.WriteLine("Listening for Greeting commands.. Press enter to exit");
            Console.ReadLine();

            bus.Stop();
        }
Beispiel #14
0
        public void DoNext()
        {
            _bus = BusCreator.CreateBus(Context.ProcessConfig);
            _bus.Start();

            // 找到当前的节点的下一个节点执行(TODO:目标的服务可能是列表)
            var nextFlows = Context.ProcessConfig.SequenceFlow.Where(t => t.SourceRef == Context.CurrentSequenceFlow?.TargetRef).ToList();

            if (!nextFlows.Any())
            {
                return;
            }

            var node = GetNextNode(nextFlows);

            Context.CurrentSequenceFlow = node;
            var sendToUri = new Uri($"{Context.ProcessConfig.RabbitMqUri.Url}{node.Id}");

            BusCreator.SendCommand(_bus, sendToUri, Context);
        }
Beispiel #15
0
        static void Main(string[] args)
        {
            Console.Title = "Hierarchy message producer";

            var bus = BusCreator.CreateBus();

            bus.Start();

            do
            {
                Console.WriteLine("Enter message (or quit to exit)");
                Console.Write("> ");
                string value = Console.ReadLine();

                if ("quit".Equals(value, StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }

                //发布消息
                var uuMsg = new UserUpdatedMessage()
                {
                    Id = Guid.NewGuid(), Type = "User updated"
                };
                bus.Publish(uuMsg);
                Console.WriteLine($"publish command:id={uuMsg.Id},{uuMsg.Type}, {DateTime.Now}");

                var udMsg = new UserDeletedMessage()
                {
                    Id = Guid.NewGuid(), Type = "User deleted"
                };
                bus.Publish(udMsg);
                Console.WriteLine($"publish command:id={udMsg.Id},{udMsg.Type}, {DateTime.Now}");
            }while (true);


            Console.WriteLine("Publish Hierarchy events.. Press enter to exit");
            Console.ReadLine();

            bus.Stop();
        }
Beispiel #16
0
        static void Main(string[] args)
        {
            Console.Title = "Greeting";

            var bus = BusCreator.CreateBus();

            bus.Start();

            do
            {
                Console.WriteLine("Enter message (or quit to exit)");
                Console.Write("> ");
                string value = Console.ReadLine();

                if ("quit".Equals(value, StringComparison.OrdinalIgnoreCase))
                {
                    break;
                }

                //发布消息
                var commandA = new GreetingEventA()
                {
                    Id = Guid.NewGuid(), DateTime = DateTime.Now
                };
                bus.Publish(commandA);
                Console.WriteLine($"publish command:id={commandA.Id},{commandA.DateTime}");

                var commandB = new GreetingEventB()
                {
                    Id = Guid.NewGuid(), DateTime = DateTime.Now
                };
                bus.Publish(commandB);
                Console.WriteLine($"publish command:id={commandB.Id},{commandB.DateTime}");
            }while (true);


            Console.WriteLine("Publish Greeting events.. Press enter to exit");
            Console.ReadLine();

            bus.Stop();
        }
        static void Main(string[] args)
        {
            Console.WriteLine("Hierarchy message subscriber 订阅");

            var bus = BusCreator.CreateBus((cfg, host) =>
            {
                cfg.ReceiveEndpoint(host, RabbitMqConstants.HierarchyMessageSubscriberQueue, e =>
                {
                    e.Consumer <UserUpdatedMessageConsumer>();
                    e.Consumer <BaseInterfaceMessageConsumer>();
                    e.Consumer <BaseMessageConsumer>();
                });
            });

            bus.Start();

            Console.WriteLine("Listening for Hierarchy events.. Press enter to exit");
            Console.ReadLine();

            bus.Stop();
        }
Beispiel #18
0
        static async Task Main(string[] args)
        {
            Console.Title = "Consumer 1";

            var bus = BusCreator.CreateBus((cfg, host) =>
            {
                cfg.ReceiveEndpoint(host, Constants.QueueA, e =>
                {
                    e.UseRetry(r => r.Immediate(5));

                    e.Consumer <CommandAConsumer>();
                });
            });

            await bus.StartAsync();

            Console.WriteLine($"Listening ({Constants.QueueA})... Press enter to exit.");
            Console.ReadLine();

            await bus.StopAsync();
        }
        static void Main(string[] args)
        {
            var configurations = AppSettings.RabbitMqConfigurations;
            var bus            = BusCreator.Create(configurations);
            var sendToUri      = new Uri($"{configurations.Uri}{configurations.WindowsServiceQueue}");

            var text = string.Empty;

            while (text != "quit")
            {
                Console.Write("Enter a message: ");
                text = Console.ReadLine();

                var message = new WindowsServiceCommand
                {
                    Id       = Guid.NewGuid(),
                    Message  = text,
                    DateTime = DateTime.Now
                };

                Task.Run(() => CommandExtension.SendCommand(bus, sendToUri, message));
            }
        }
Beispiel #20
0
        static async Task Main(string[] args)
        {
            Console.Title = "Consumer 2";

            var bus = BusCreator.CreateBus((cfg, host) =>
            {
                cfg.ReceiveEndpoint(host, Constants.QueueA, e =>
                {
                    e.Handler <CommandA>(context =>
                    {
                        Console.WriteLine($"Receive Command: id={context.Message.Id}, {context.Message.DateTime}");
                        return(Task.CompletedTask);
                    });
                });
            });

            await bus.StartAsync();

            Console.WriteLine($"Listening ({Constants.QueueA})... Press enter to exit.");
            Console.ReadLine();

            await bus.StopAsync();
        }
        static async Task Main(string[] args)
        {
            Console.Title = "Producer";

            Console.WriteLine("Press 'Enter' to send a message. To exit, Ctrl + C");

            var bus = BusCreator.CreateBus((cfg, host) =>
            {
                cfg.UseInMemoryScheduler();

                cfg.ReceiveEndpoint(host, $"{Constants.QueueA}_error", e =>
                {
                    e.Consumer <WantAllFaultsGimmeThem>();
                    e.Consumer <CommandAFaultConsumer>();
                });
            });

            await bus.StartAsync();

            var sendToUri = new Uri($"{Constants.RabbitMqUri}{Constants.QueueA}");

            while (Console.ReadLine() != null)
            {
                var command = new
                {
                    Id       = Guid.NewGuid(),
                    DateTime = DateTime.Now
                };
                await bus.ScheduleSend <CommandA>(sendToUri, DateTime.Now.AddMinutes(1), command);

                Console.WriteLine($"Send Command: id={command.Id}, {command.DateTime} -> {DateTime.Now.AddMinutes(1)}");
            }

            Console.ReadLine();

            await bus.StopAsync();
        }