Exemple #1
0
        private static void Main(string[] args)
        {
            ObjectContainer.SetContainer(new AutofacContainerObject());

            var applictionInitializer = new EventHandleProvider();

            applictionInitializer.Initialize(Assembly.GetExecutingAssembly());

            var commandInitializer = new CommandHandleProvider();

            commandInitializer.Initialize(Assembly.GetExecutingAssembly());

            ObjectContainer.RegisterInstance(applictionInitializer);
            ObjectContainer.RegisterInstance(commandInitializer);

            var dbConnection = new MySqlConnection(_mysqlConnection);

            var persistence = new SnapshotPersistence(dbConnection);

            var binarySerializer = new DefaultBinarySerializer();

            var snapshotRepository = new SnapshotRepository(persistence, new SnapshotFactory(binarySerializer));

            var eventPersistence = new EventStorePersistence(dbConnection);

            var eventFactory = new EventStreamFactory(binarySerializer);

            var eventStore = new EventStore(eventPersistence, eventFactory);

            IRepository repository = new EventSouringRepository(eventStore, snapshotRepository);

            var comamndHandler = ObjectContainer.Resolve<CommandHandleProvider>();

            var changePasswordCommand = new ChangePasswordCommand("90ca0d59-65e6-403b-82c5-8df967cc8e22", "2222222", "11111");

            var commandContext = new CommandContext(repository);

            var commandHanldeAction = comamndHandler.GetInternalCommandHandle(typeof(ChangePasswordCommand));
            commandHanldeAction(commandContext, changePasswordCommand);

            var aggregateRoots = commandContext.AggregateRoots;

            IList<IEvent> unCommitEvents = null;

            foreach (var item in aggregateRoots)
            {
                unCommitEvents = item.Value.Commit();
            }

            var aggregateRoot = aggregateRoots.FirstOrDefault().Value;

            eventStore.AppendToStream(aggregateRoot.AggregateRootId, new EventStream(aggregateRoot.Version, unCommitEvents));

            snapshotRepository.Create(aggregateRoot);

            Console.WriteLine("改方法执行完毕...");
        }
Exemple #2
0
        public static void TestBinSer()
        {
            var changePasswordCommand = new ChangePasswordCommand("90ca0d59-65e6-403b-82c5-8df967cc8e22", "2222222", "11111");

            var message = new MessageWrapper();

            message.ExchangeName = changePasswordCommand.GetType().FullName;
            message.TypeName = changePasswordCommand.GetType().FullName;

            var binarySerializer = new DefaultBinarySerializer();
        }
        public void DefaultBinarySerializer_Test()
        {
            var o1 = new TestSerializeClass()
            {
                Id   = 1,
                Name = "zhang",
                Age  = 19
            };
            IBinarySerializer binarySerializer = new DefaultBinarySerializer();
            var binary1 = binarySerializer.Serialize(o1);

            var o2 = binarySerializer.Deserialize <TestSerializeClass>(binary1);

            Assert.Equal(o1.Id, o2.Id);
            Assert.Equal(o1.Name, o2.Name);
            Assert.Equal(o1.Age, o2.Age);

            var o3 = (TestSerializeClass)binarySerializer.Deserialize(binary1, typeof(TestSerializeClass));

            Assert.Equal(o1.Id, o3.Id);
            Assert.Equal(o1.Name, o3.Name);
            Assert.Equal(o1.Age, o3.Age);
        }
Exemple #4
0
        private static void Main(string[] args)
        {
            var containerBuilder = new AutofacContainerBuilder();

            var binarySerializer = new DefaultBinarySerializer();

            var eventHandleInitializer = new EventHandleProvider();
            eventHandleInitializer.Initialize(Assembly.GetExecutingAssembly(), Assembly.Load("Seven.Tests"));

            var commandInitializer = new CommandHandleProvider();
            commandInitializer.Initialize(Assembly.Load("Seven.Tests"));

            var messageTypeProvider = new MessageTypeProvider();
            messageTypeProvider.Initialize(Assembly.GetExecutingAssembly(), Assembly.Load("Seven.Tests"));

            containerBuilder.RegisterInstance(eventHandleInitializer);
            containerBuilder.RegisterInstance(commandInitializer);
            containerBuilder.RegisterInstance(messageTypeProvider);

            var mysqlEventStore = new MySqlEventStore(_mysqlConnection);

            var snapshotStorage = new MysqlSnapshotStorage(_mysqlConnection);

            var aggregateRootStorage = new MysqlAggregateRootStorage(_mysqlConnection);

            var aggregateRootMemory = new AggregateRootMemoryCache();

            var nonEventSouringRepository = new NonEventSouringRepository(aggregateRootStorage, binarySerializer);

            var eventSouringRepository = new EventSouringRepository(mysqlEventStore, snapshotStorage, binarySerializer,
                aggregateRootMemory);

            var endPoint = new RemoteEndpoint("127.0.0.1", "/", "guest", "guest", 5672);

            var exChangeName = typeof(CreateUserCommand).Assembly.GetName().Name; ;

            var responseRoutingKey = MessageUtils.CurrentResponseRoutingKey;

            var channelPools = new CommunicateChannelFactoryPool(endPoint);

            containerBuilder.RegisterInstance(channelPools);
            containerBuilder.RegisterInterface<IBinarySerializer, DefaultBinarySerializer>();

            DependencyResolver.SetResolver(new DefaultDependencyResolver(containerBuilder.Build()));

            var requestChannelPools = new RequestChannelPools();

            var commandTopicProvider = new UserTopicProvider();

            var eventTopicProvider = new UserEEventTopicProvider();

            var eventPublisher = new EventPublisher(requestChannelPools, eventTopicProvider);

            var commandProssor = new DefaultCommandProssor(mysqlEventStore, eventSouringRepository, commandInitializer, eventPublisher, snapshotStorage, binarySerializer);

            var messageHandler = new MessageRequestHandler(commandProssor);

            for (var i = 0; i < 5; i++)
            {
                var routingKey = string.Format("{0}_{1}_{2}", exChangeName, "command", i);

                var consumerContext = new ConsumerContext(exChangeName, routingKey, routingKey, responseRoutingKey, false, true);

                var consumer = new PushMessageConsumer(channelPools, binarySerializer, consumerContext, messageHandler);

                consumer.Start();

                Console.WriteLine("Started.");
            }

            for (var i = 0; i < 5; i++)
            {
                var routingKey = string.Format("{0}_{1}_{2}", exChangeName, "event", i);

                var consumerContext = new ConsumerContext(exChangeName, routingKey, routingKey, responseRoutingKey, false, true);

                var consumer = new PushMessageConsumer(channelPools, binarySerializer, consumerContext, messageHandler);

                consumer.Start();

                Console.WriteLine("Started.");
            }

            Console.WriteLine("begin to consumer the message.");

            Console.ReadLine();
        }
Exemple #5
0
        private static void Main(string[] args)
        {
            var binarySerializer = new DefaultBinarySerializer();

            var hostName = "127.0.0.1";
            var port = 5672;
            var userName = "******";
            var password = "******";
            var virtualName = "/";

            var endPoint = new RemoteEndpoint(hostName, virtualName, userName, password, port);

            var exChangeName = typeof(CreateUserCommand).Assembly.GetName().Name;

            var routingKey = MessageUtils.CurrentResponseRoutingKey;

            var responseRoutingKey = MessageUtils.CurrentResponseRoutingKey;

            var consumerContext = new ConsumerContext(exChangeName, responseRoutingKey, responseRoutingKey, routingKey, true);

            var channelPools = new CommunicateChannelFactoryPool(endPoint);

            var consumer = new PushMessageConsumer(channelPools, binarySerializer, consumerContext, new MessageResponseHandler());

            consumer.Start();

            var containerBuilder = new AutofacContainerBuilder();

            containerBuilder.RegisterInstance(channelPools);
            containerBuilder.RegisterInterface<IBinarySerializer, DefaultBinarySerializer>();

            DependencyResolver.SetResolver(new DefaultDependencyResolver(containerBuilder.Build()));

            var requestChannelPools = new RequestChannelPools();

            var commandTopicProvider = new UserTopicProvider();

            var commandService = new CommandService(requestChannelPools, commandTopicProvider);

            Console.WriteLine("begin to receive the result message");

            Stopwatch watch = new Stopwatch();
            watch.Start();

            for (var i = 0; i < 10000; i++)
            {
                var command = new CreateUserCommand(
                 "天涯狼" + DateTime.Now.ToString("yyyyMMddHHmmsss"),
                 DateTime.Now.ToString("yyyyMMddHHmmsss"),
                 true,
                 22);

                var commandResult = commandService.Send(command, 20);

                Console.WriteLine("message:{0} and number is {1}", commandResult.Message, i);
            }

            watch.Stop();

            Console.WriteLine("message:{0} ", watch.ElapsedMilliseconds);
            Console.ReadLine();
        }
Exemple #6
0
        private static void Main(string[] args)
        {
            // ObjectContainer.SetContainer(new AutofacContainerObject());

            //var applictionInitializer = new EventHandleProvider();

            //applictionInitializer.Initialize(Assembly.GetExecutingAssembly());

            //var commandInitializer = new CommandHandleProvider();

            //commandInitializer.Initialize(Assembly.GetExecutingAssembly());

            //ObjectContainer.RegisterInstance(applictionInitializer);
            //ObjectContainer.RegisterInstance(commandInitializer);

            //var dbConnection = new MySqlConnection(_mysqlConnection);

            //var persistence = new SnapshotPersistence(dbConnection);

            //var binarySerializer = new DefaultBinarySerializer();

            //var snapshotRepository = new SnapshotRepository(persistence, new SnapshotFactory(binarySerializer));

            //var eventPersistence = new EventStorePersistence(dbConnection);

            //var eventFactory = new EventStreamFactory(binarySerializer);

            //var eventStore = new EventStore(eventPersistence, eventFactory);

            //IRepository repository = new EventSouringRepository(eventStore, snapshotRepository);

            //var comamndHandler = ObjectContainer.Resolve<CommandHandleProvider>();

            var changePasswordCommand = new ChangePasswordCommand("90ca0d59-65e6-403b-82c5-8df967cc8e22", "2222222",
                "11111");

            //var commandContext = new CommandContext(repository);

            //var commandHanldeAction = comamndHandler.GetInternalCommandHandle(typeof(ChangePasswordCommand));
            //commandHanldeAction(commandContext, changePasswordCommand);

            //var aggregateRoots = commandContext.AggregateRoots;

            //IList<IEvent> unCommitEvents = null;

            //foreach (var item in aggregateRoots)
            //{
            //    unCommitEvents = item.Value.Commit();
            //}

            //var aggregateRoot = aggregateRoots.FirstOrDefault().Value;

            //eventStore.AppendToStream(aggregateRoot.AggregateRootId, new EventStream(aggregateRoot.Version, unCommitEvents));

            //snapshotRepository.Create(aggregateRoot);

            //Console.WriteLine("改方法执行完毕...");

            // TestBinSer();

            //var messageHandleResult = new MessageHandleResult()
            //{
            //    Message = "订单那等你给当地发给你",
            //    Status = MessageStatus.Success,
            //    MessageId = Guid.NewGuid().ToString(),
            //};

            IBinarySerializer binarySerializer = new DefaultBinarySerializer();

            var queueMessage = new MessageWrapper()
            {
                Message = changePasswordCommand,
            };

            var queues = binarySerializer.Serialize(queueMessage);

            var queueMessage1 = binarySerializer.Deserialize<MessageWrapper>(queues);

            for (var i = 0; i < 1000000; i++)
            {
                // Console.WriteLine(ObjectId.NewObjectId());
            }

            Console.Write("MachineName:{0},ProcessId:{1}", Environment.MachineName, Process.GetCurrentProcess().Id);
        }