示例#1
0
        public void DefaultSerializersAdded_WhenNotSpecifiedByHost()
        {
            var settings     = new BrokerSettings();
            var mockExchange = new Mock <IMessageBroker>();
            MessageBrokerState brokerConfig = null;

            mockExchange.Setup(b => b.Initialize(It.IsAny <MessageBrokerState>()))
            .Callback <MessageBrokerState>(cfg => brokerConfig = cfg);

            ModuleTest.Arrange(config =>
            {
                config.AddPlugin <MockAppHostPlugin>();
            })
            .Act(c =>
            {
                AddTestMocks(c, settings, mockExchange.Object);
                c.Build().Start();
            });

#if NETCOREAPP1_0
            brokerConfig.SerializationMgr.Serializers.Should().HaveCount(1);
            brokerConfig.SerializationMgr.Serializers.Select(s => s.ContentType).Should().Contain(SerializerTypes.Json);
#endif

#if NET461
            brokerConfig.SerializationMgr.Serializers.Should().HaveCount(3);
            brokerConfig.SerializationMgr.Serializers.Select(s => s.ContentType).Should().Contain(SerializerTypes.Json);
            brokerConfig.SerializationMgr.Serializers.Select(s => s.ContentType).Should().Contain(SerializerTypes.Binary);
            brokerConfig.SerializationMgr.Serializers.Select(s => s.ContentType).Should().Contain(SerializerTypes.MessagePack);
#endif
        }
示例#2
0
        // -------------------------- UNIT-TEST SETUP -------------------------------------------

        // Returns a test setup containing a configured MessageBrokerState instance and mocked
        // ConnectionManager.  This simulates the state built by the MessageBrokerModule that is
        // used to initialize a MessageBroker instance and passed to the internal initialization
        // classes to which it delegates.
        public static BrokerStateSetup SetupBrokerState(BrokerSettings brokerSettings = null)
        {
            var serializer  = new JsonBrokerSerializer();
            var brokerState = new MessageBrokerState
            {
                BrokerSettings = brokerSettings ?? new BrokerSettings
                {
                    Connections = new List <BrokerConnectionSettings>
                    {
                        new BrokerConnectionSettings {
                            BrokerName = "MockTestBrokerName", HostName = "TestHost"
                        }
                    }
                }
            };

            var serializers = new Dictionary <string, IBrokerSerializer>
            {
                { serializer.ContentType, serializer }
            };

            var mockConnMgr = new MockConnectionManager(
                new TestLoggerFactory(),
                brokerState.BrokerSettings,
                new Dictionary <string, object>());

            brokerState.ConnectionMgr    = mockConnMgr;
            brokerState.SerializationMgr = new SerializationManager(serializers);
            return(new BrokerStateSetup
            {
                BrokerState = brokerState,
                MockConnMgr = mockConnMgr
            });
        }
示例#3
0
        public void ExchangeDefinitions_Discovered()
        {
            var settings     = new BrokerSettings();
            var mockExchange = new Mock <IMessageBroker>();
            MessageBrokerState brokerState = null;

            mockExchange.Setup(b => b.Initialize(It.IsAny <MessageBrokerState>()))
            .Callback <MessageBrokerState>(s => brokerState = s);

            // Define the broker connection and an externally defined queue route key.
            settings.Connections = new List <BrokerConnectionSettings>
            {
                new BrokerConnectionSettings {
                    BrokerName      = "MockTestBrokerName",
                    QueueProperties = new QueuePropertiesSettings[] {
                        new QueuePropertiesSettings {
                            QueueName = "MockTestQueueName", RouteKeys = new [] { "RouteKeyTwo" }
                        }
                    }
                }
            };

            ModuleTest.Arrange(config =>
            {
                config.AddPlugin <MockAppHostPlugin>()
                .AddPluginType <MockTopicExchange>()
                .AddPluginType <MockExchange>();
            })
            .Act(c =>
            {
                c.WithConfig((MessagingConfig config) =>
                {
                    config.AddMessagePublisher <RabbitMqMessagePublisher>();
                });

                AddTestMocks(c, settings, mockExchange.Object);
                c.Build().Start();
            });

            // Verify that module initialized the message broker with the exchanges:
            brokerState.Should().NotBeNull();
            brokerState.BrokerSettings.Should().NotBeNull();
            brokerState.Exchanges.Should().NotBeNull();
            // metadata.Connections.Should().NotBeNull();

            // Verify that the correct exchanges were determined.
            brokerState.Exchanges.Should().HaveCount(2);
            brokerState.Exchanges.Should().Contain(e => e.ExchangeName == "MockDirectExchangeName");
            brokerState.Exchanges.Should().Contain(e => e.ExchangeName == "MockTopicExchangeName");

            // Verify that the externally defined route key was added to the queue:
            var directExchange = brokerState.Exchanges.First(e => e.ExchangeName == "MockDirectExchangeName");
            var queue          = directExchange.Queues.FirstOrDefault();

            queue.Should().NotBeNull();
            queue.RouteKeys.Should().HaveCount(1);
            queue.RouteKeys.Should().Contain(k => k == "RouteKeyTwo");
        }
示例#4
0
 public ExchangeConsumerInit(
     ILoggerFactory loggerFactory,
     IMessagingModule messagingModule,
     MessageBrokerState brokerState)
 {
     _logger           = loggerFactory.CreateLogger <ExchangePublisherInit>();
     _messagingModule  = messagingModule;
     _brokerState      = brokerState;
     _connMgr          = brokerState.ConnectionMgr;
     _serializationMgr = brokerState.SerializationMgr;
 }
        public RpcExchangePublisherInit(
            ILoggerFactory loggerFactory,
            MessageBrokerState brokerState)
        {
            _logger           = loggerFactory.CreateLogger <RpcExchangeConsumerInit>();
            _brokerState      = brokerState;
            _connMgr          = brokerState.ConnectionMgr;
            _serializationMgr = brokerState.SerializationMgr;

            _rpcMessagePublishers = new List <RpcMessagePublisher>();
        }
示例#6
0
            // Initializes the message broker instance with the specified broker-state
            // and optional message-consumer.
            public void Initialize(MessageBrokerState brokerState, MessageConsumer consumer = null)
            {
                _messageConsumer = consumer;

                this.Instance.Initialize(brokerState);
                this.Instance.ConfigurePublishers();

                if (_messageConsumer != null)
                {
                    this.Instance.BindConsumers(new[] { _messageConsumer });
                }
            }
        public ExchangePublisherInit(
            ILoggerFactory loggerFactory,
            MessageBrokerState brokerState,
            IEntityScriptingService scriptiongSrv)
        {
            _logger           = loggerFactory.CreateLogger <ExchangePublisherInit>();
            _brokerState      = brokerState;
            _connMgr          = brokerState.ConnectionMgr;
            _serializationMgr = brokerState.SerializationMgr;
            _scriptingSrv     = scriptiongSrv;

            // Messages can have one or more associated exchanges.  When a message is published,
            // a lookup is completed to determine if there is an exchange associated with the message.
            _messageExchanges = brokerState.Exchanges.ToLookup(
                k => k.MessageType,
                e => new MessageExchangeDefinition(e, e.MessageType));
        }