예제 #1
0
        private MessageDispatcher CreateAndStartDispatcher(IDispatcherTaskSchedulerFactory taskSchedulerFactory)
        {
            var messageDispatcher = new MessageDispatcher(_pipeManagerMock.Object, new IMessageHandlerInvokerLoader[]
            {
                new SyncMessageHandlerInvokerLoader(_containerMock.Object),
                new AsyncMessageHandlerInvokerLoader(_containerMock.Object),
            }, taskSchedulerFactory);

            messageDispatcher.ConfigureAssemblyFilter(x => x == GetType().Assembly);
            messageDispatcher.ConfigureHandlerFilter(type => type != typeof(SyncMessageHandlerInvokerLoaderTests.WrongAsyncHandler));
            messageDispatcher.Start();
            return messageDispatcher;
        }
예제 #2
0
        public void Setup()
        {
            _containerMock = new Mock<IContainer>();
            _containerMock.Setup(x => x.GetInstance(It.IsAny<Type>())).Returns<Type>(Activator.CreateInstance);

            _invocation = null;
            _pipeManagerMock = new Mock<IPipeManager>();
            _pipeManagerMock.Setup(x => x.BuildPipeInvocation(It.IsAny<IMessageHandlerInvoker>(), It.IsAny<IMessage>(), It.IsAny<MessageContext>()))
                            .Returns<IMessageHandlerInvoker, IMessage, MessageContext>((invoker, message, messageContext) =>
                            {
                                _invocation = new TestPipeInvocation(message, messageContext, invoker);
                                return _invocation;
                            });

            _taskSchedulerFactory = new DispatcherTaskSchedulerFactory();

            _messageDispatcher = CreateAndStartDispatcher(_taskSchedulerFactory);
        }
예제 #3
0
        public IBus CreateBus()
        {
            if (_configuration == null)
                throw new InvalidOperationException("The CreateBus() method was called with no configuration (Call .WithConfiguration(...) first)");
            Container.Configure(x => x.AddRegistry<ZebusRegistry>());
            Container.Configure(x =>
            {
                x.ForSingletonOf<IBusConfiguration>().Use(_configuration);
                x.ForSingletonOf<IZmqTransportConfiguration>().Use(_transportConfiguration);
                x.ForSingletonOf<IMessageDispatcher>().Use("MessageDispatcher factory", ctx =>
                {
                    var dispatcher = new MessageDispatcher(ctx.GetInstance<IPipeManager>(), ctx.GetAllInstances<IMessageHandlerInvokerLoader>().ToArray(), ctx.GetInstance<IDispatcherTaskSchedulerFactory>());
                    dispatcher.ConfigureHandlerFilter(assembly => _scanTargets.Any(scanTarget => scanTarget.Matches(assembly)));
                    dispatcher.ConfigureAssemblyFilter(type => _scanTargets.Any(scanTarget => scanTarget.Matches(type)));

                    return dispatcher;
                });
            });

            foreach (var configurationAction in _configurationActions)
            {
                Container.Configure(configurationAction);
            }

            var bus = Container.GetInstance<IBus>();
            bus.Configure(PeerId, _environment);
            return bus;
        }
예제 #4
0
        private void Dispatch(IMessage message, MessageContext context, MessageDispatcher dispatcher = null)
        {
            _dispatchResultRef = null;

            var dispatch = new MessageDispatch(context, message, (x, r) => _dispatchResultRef = new DispatchResultRef(r));
            (dispatcher ?? _messageDispatcher).Dispatch(dispatch);
        }
예제 #5
0
 private void Dispatch(IMessage message, MessageDispatcher dispatcher = null)
 {
     var messageContext = MessageContext.CreateTest("u.name");
     Dispatch(message, messageContext.WithDispatchQueueName(DispatchQueueNameScanner.DefaultQueueName), dispatcher);
 }