コード例 #1
0
        static void Main(string[] args)
        {
            using (var busBroker = new EventBusClientBroker("localhost", 8181, "abcde550", new TestProcessor()))
            {
                Console.WriteLine("Press 'q' to quit");


                while (true)
                {
                    string choice = Console.ReadLine();
                    if (choice == "1")
                    {
                        NewUserRegisteredEvent evt = new NewUserRegisteredEvent();
                        evt.RegisterDate = DateTime.Now;
                        evt.UserName     = "******";
                        busBroker.Publish <NewUserRegisteredEvent>(evt, "NewUserRegister", 1);
                    }
                    else if (choice == "2")
                    {
                        UserProfileUpdatedEvent evt = new UserProfileUpdatedEvent();
                        evt.UserID = 100;
                        busBroker.Publish <UserProfileUpdatedEvent>(evt, "UserProfileUpdated", 2);
                    }
                }
            }
        }
コード例 #2
0
        public async Task <Unit> Handle(PublishNewRegisteredUserCommand request, CancellationToken cancellationToken)
        {
            var newRegisteredUserEvent = await _unitOfWork.AuditRecords
                                         .FirstOrDefaultAsync(x => x.TableName == AuditRecordTable.Users &&
                                                              x.Published == false, cancellationToken);

            if (newRegisteredUserEvent != null)
            {
                var user = await _unitOfWork.Users
                           .SingleAsync(x => x.Id == newRegisteredUserEvent.SubjectId, cancellationToken);

                var @event = new NewUserRegisteredEvent
                {
                    FullName      = user.FullName,
                    Email         = user.Email,
                    ApplicationId = ApplicationId.QnA,
                    EventDate     = newRegisteredUserEvent.DateTime
                };

                newRegisteredUserEvent.MarkAsPublished(_dateService);

                await _broker.Publish(@event);

                await _unitOfWork.SaveChangesWithoutHistoryAsync(cancellationToken);
            }

            return(Unit.Value);
        }