コード例 #1
2
        protected override async Task Given(AllDependencyResolversTestContext context)
        {

            await base.Given(context);

            var clock = new SystemClock();
            var typeProvider = new TestHarnessTypeProvider(new[] {GetType().Assembly}, new[] {GetType().Namespace});
            var serializer = new DataContractSerializer(typeProvider);
            var replyQueueNameSetting = new ReplyQueueNameSetting(
                new ApplicationNameSetting {Value = "TestApplication"},
                new InstanceNameSetting {Value = "TestInstance"});

            var handlerMap = new HandlerMapper(typeProvider).GetFullHandlerMap(typeof (IHandleCommand<>));

            _brokeredMessageFactory = new BrokeredMessageFactory(new MaxLargeMessageSizeSetting(),
                                                                 new MaxSmallMessageSizeSetting(),
                                                                 replyQueueNameSetting,
                                                                 clock,
                                                                 new NullCompressor(),
                                                                 new DispatchContextManager(),
                                                                 new UnsupportedLargeMessageBodyStore(),
                                                                 serializer,
                                                                 typeProvider);

            _commandDispatcher = new CommandMessageDispatcher(_brokeredMessageFactory,
                                                              new SystemClock(),
                                                              Subject,
                                                              new NullInboundInterceptorFactory(),
                                                              new NullLogger(),
                                                              handlerMap);
        }
コード例 #2
0
ファイル: BusBuilder.cs プロジェクト: nblumhardt/Nimbus
        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var replyQueueName = string.Format("InputQueue.{0}.{1}", configuration.ApplicationName, configuration.InstanceName);

            var namespaceManager = NamespaceManager.CreateFromConnectionString(configuration.ConnectionString);
            var messagingFactory = MessagingFactory.CreateFromConnectionString(configuration.ConnectionString);

            var messagePumps = new List<IMessagePump>();

            var queueManager = new QueueManager(namespaceManager, messagingFactory, configuration.MaxDeliveryAttempts);

            var clock = new SystemClock();
            var requestResponseCorrelator = new RequestResponseCorrelator(clock);

            var messageSenderFactory = new MessageSenderFactory(messagingFactory);
            var topicClientFactory = new TopicClientFactory(messagingFactory);
            var commandSender = new BusCommandSender(messageSenderFactory);
            var requestSender = new BusRequestSender(messageSenderFactory, replyQueueName, requestResponseCorrelator, clock, configuration.DefaultTimeout);
            var multicastRequestSender = new BusMulticastRequestSender(topicClientFactory, replyQueueName, requestResponseCorrelator, clock);
            var eventSender = new BusEventSender(topicClientFactory);

            if (configuration.Debugging.RemoveAllExistingNamespaceElements)
            {
                RemoveAllExistingNamespaceElements(namespaceManager);
            }

            var queueCreationTasks = new[]
            {
                Task.Run(() => CreateMyInputQueue(queueManager, replyQueueName)),
                Task.Run(() => CreateCommandQueues(configuration, queueManager)),
                Task.Run(() => CreateRequestQueues(configuration, queueManager)),
                Task.Run(() => CreateMulticastRequestTopics(configuration, queueManager)),
                Task.Run(() => CreateEventTopics(configuration, queueManager)),
            };
            Task.WaitAll(queueCreationTasks);

            //FIXME do these in parallel
            CreateResponseMessagePump(configuration, messagingFactory, replyQueueName, requestResponseCorrelator, messagePumps);
            CreateCommandMessagePumps(configuration, messagingFactory, messagePumps);
            CreateRequestMessagePumps(configuration, messagingFactory, messagePumps);
            CreateMulticastRequestMessagePumps(configuration, queueManager, messagingFactory, messagePumps);
            CreateMulticastEventMessagePumps(configuration, queueManager, messagingFactory, messagePumps);
            CreateCompetingEventMessagePumps(configuration, queueManager, messagingFactory, messagePumps);

            var commandDeadLetterQueue = new DeadLetterQueue(queueManager);
            var requestDeadLetterQueue = new DeadLetterQueue(queueManager);
            var deadLetterQueues = new DeadLetterQueues(commandDeadLetterQueue, requestDeadLetterQueue);

            var bus = new Bus(commandSender, requestSender, multicastRequestSender, eventSender, messagePumps, deadLetterQueues);
            return bus;
        }
コード例 #3
0
ファイル: BusBuilder.cs プロジェクト: nhuhuynh/Nimbus
        internal static Bus Build(BusBuilderConfiguration configuration)
        {
            var logger = configuration.Logger;

            logger.Debug("Constructing bus...");

            var replyQueueName = string.Format("InputQueue.{0}.{1}", configuration.ApplicationName, configuration.InstanceName);

            var namespaceManager = NamespaceManager.CreateFromConnectionString(configuration.ConnectionString);
            var versionInfo = namespaceManager.GetVersionInfo();

            var messagingFactory = MessagingFactory.CreateFromConnectionString(configuration.ConnectionString);

            var messagePumps = new List<IMessagePump>();

            var queueManager = new QueueManager(namespaceManager, messagingFactory, configuration.MaxDeliveryAttempts, logger);

            var clock = new SystemClock();
            var requestResponseCorrelator = new RequestResponseCorrelator(clock, logger);

            var messageSenderFactory = new MessageSenderFactory(messagingFactory);
            var topicClientFactory = new TopicClientFactory(messagingFactory);
            var commandSender = new BusCommandSender(messageSenderFactory, clock, configuration.CommandTypes);
            var requestSender = new BusRequestSender(messageSenderFactory, replyQueueName, requestResponseCorrelator, clock, configuration.DefaultTimeout, configuration.RequestTypes, logger);
            var multicastRequestSender = new BusMulticastRequestSender(topicClientFactory, replyQueueName, requestResponseCorrelator, clock, configuration.RequestTypes);
            var eventSender = new BusEventSender(topicClientFactory, configuration.EventTypes);

            if (configuration.Debugging.RemoveAllExistingNamespaceElements)
            {
                RemoveAllExistingNamespaceElements(namespaceManager, logger);
            }

            logger.Debug("Creating queues and topics");

            var queueCreationTasks =
                new[]
                {
                    Task.Run(() => CreateMyInputQueue(queueManager, replyQueueName, logger)),
                    Task.Run(() => CreateCommandQueues(configuration, queueManager, logger)),
                    Task.Run(() => CreateRequestQueues(configuration, queueManager, logger)),
                    Task.Run(() => CreateMulticastRequestTopics(configuration, queueManager, logger)),
                    Task.Run(() => CreateEventTopics(configuration, queueManager, logger))
                };
            Task.WaitAll(queueCreationTasks);
            logger.Debug("Queues and topics are all created.");

            logger.Debug("Creating message pumps and subscriptions.");
            var messagePumpCreationTasks =
                new[]
                {
                    Task.Run(() => CreateResponseMessagePump(configuration, messagingFactory, replyQueueName, requestResponseCorrelator, messagePumps, logger)),
                    Task.Run(() => CreateCommandMessagePumps(configuration, messagingFactory, messagePumps, logger)),
                    Task.Run(() => CreateRequestMessagePumps(configuration, messagingFactory, messagePumps, logger)),
                    Task.Run(() => CreateMulticastRequestMessagePumps(configuration, queueManager, messagingFactory, messagePumps, logger)),
                    Task.Run(() => CreateMulticastEventMessagePumps(configuration, queueManager, messagingFactory, messagePumps, logger)),
                    Task.Run(() => CreateCompetingEventMessagePumps(configuration, queueManager, messagingFactory, messagePumps, logger))
                };
            messagePumpCreationTasks.WaitAll();
            logger.Debug("Message pumps and subscriptions are all created.");

            var commandDeadLetterQueue = new DeadLetterQueue(queueManager);
            var requestDeadLetterQueue = new DeadLetterQueue(queueManager);
            var deadLetterQueues = new DeadLetterQueues(commandDeadLetterQueue, requestDeadLetterQueue);

            var bus = new Bus(commandSender, requestSender, multicastRequestSender, eventSender, messagePumps, deadLetterQueues);

            logger.Debug("Bus built. Job done!");

            return bus;
        }