Ejemplo n.º 1
0
        public MessageConnection(RemoteEndpoint endpoint)
        {
            _endpoint = endpoint;

            Initializer();
        }
Ejemplo n.º 2
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();
        }
Ejemplo n.º 3
0
 public static void SetChannelPools(RemoteEndpoint endpoint)
 {
     ChannelPools = new CommunicateChannelFactoryPool(endpoint);
 }
Ejemplo n.º 4
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();
        }
        public CommunicateChannelFactoryPool(RemoteEndpoint endpoint)
        {
            _endpoint = endpoint;

            _channelPools = new List<CommunicateChannelFactory>();
        }
Ejemplo n.º 6
0
        public CommunicateChannelFactory(RemoteEndpoint endpoint)
        {
            _endpoint = endpoint;

            _channelPools = new ConcurrentDictionary<string, ICommunicateChannel>();
        }