Beispiel #1
0
        static void Main(string[] args)
        {
            Console.WriteLine("######### AuctionEventPublisher Started #########");

            var repository = new AggregateRepository();
            Tuple <long, string> eventData = null;
            var eventName = String.Empty;

            while (true)
            {
                try {
                    eventData = repository.GetEventDataForPublishing().GetAwaiter().GetResult();
                    if (!String.IsNullOrWhiteSpace(eventData.Item2))
                    {
                        eventName = GetEventName(eventData.Item2);

                        var redis     = RedisStore.RedisCache;
                        var publisher = redis.Multiplexer.GetSubscriber();
                        var count     = publisher.Publish(eventName, eventData.Item2);

                        repository.CreatePublishingRecord(eventData.Item1).GetAwaiter().GetResult();
                        Console.WriteLine($"Published SequenceID: {eventData.Item1}, {eventName}");
                    }
                }
                catch (Exception ex) {
                    Console.WriteLine(ex.Message);
                }

                Thread.Sleep(9000);
            }

            //var eventName = "AuctionDomainUser.Events.UserCreated";
            //var data = "{\"$type\":\"AuctionDomainUser.Events.UserCreated, AuctionDomainUser\",\"UserID\":\"0fe6807e-c045-4dd7-a16d-d0b772ac3db0\",\"FirstName\":\"Phillip\",\"LastName\":\"Do\",\"PhoneNumber\":\"714-235-5554\",\"EmailAddress\":\"[email protected]\",\"Password\":\"Password@1\",\"Attributes\":{\"$type\":\"System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.String, mscorlib]], mscorlib\"}}";

            //var redis = RedisStore.RedisCache;
            //var publisher = redis.Multiplexer.GetSubscriber();
            //var count = publisher.Publish(eventName, data);

            //var eventName = "AuctionDomainUser.Events.UserPasswordChanged";
            //var data = "{\"$type\":\"AuctionDomainUser.Events.UserPasswordChanged, AuctionDomainUser\",\"UserID\":\"0fe6807e-c045-4dd7-a16d-d0b772ac3db0\",\"Password\":\"Password@2\",\"Attributes\":{\"$type\":\"System.Collections.Generic.Dictionary`2[[System.String, mscorlib],[System.String, mscorlib]], mscorlib\"}}";

            //var redis = RedisStore.RedisCache;
            //var publisher = redis.Multiplexer.GetSubscriber();
            //var count = publisher.Publish(eventName, data);
            //Debug.WriteLine($"Number of listeners for {eventName}: {count}");
        }