コード例 #1
0
        public override void Configure(FeatureConfigurationContext context, string connectionStringWithSchema)
        {
            context.Pipeline.Register <ReadIncomingCallbackAddressBehavior.Registration>();

            var useCallbackReceiver = context.Settings.Get <bool>(UseCallbackReceiverSettingKey);
            var maxConcurrencyForCallbackReceiver = context.Settings.Get <int>(MaxConcurrencyForCallbackReceiverSettingKey);
            var queueName     = context.Settings.EndpointName();
            var callbackQueue = string.Format("{0}.{1}", queueName, RuntimeEnvironment.MachineName);

            if (useCallbackReceiver)
            {
                var callbackAddress = Address.Parse(callbackQueue);

                context.Container.ConfigureComponent <CallbackQueueCreator>(DependencyLifecycle.InstancePerCall)
                .ConfigureProperty(p => p.Enabled, true)
                .ConfigureProperty(p => p.CallbackQueueAddress, callbackAddress);

                context.Pipeline.Register <SetOutgoingCallbackAddressBehavior.Registration>();
                context.Container.ConfigureComponent(c => new OutgoingCallbackAddressSetter(callbackQueue), DependencyLifecycle.SingleInstance);
            }
            context.Container.RegisterSingleton(new SecondaryReceiveConfiguration(workQueue =>
            {
                //if this isn't the main queue we shouldn't use callback receiver
                if (!useCallbackReceiver || workQueue != queueName)
                {
                    return(SecondaryReceiveSettings.Disabled());
                }

                return(SecondaryReceiveSettings.Enabled(callbackQueue, maxConcurrencyForCallbackReceiver));
            }));
        }
コード例 #2
0
        public void SetUp()
        {
            routingTopology  = new ConventionalRoutingTopology(true);
            receivedMessages = new BlockingCollection <TransportMessage>();

            var config = new ConnectionConfiguration();

            config.ParseHosts("localhost:5672");

            var connectionFactory = new RabbitMqConnectionFactory(config);

            connectionManager = new RabbitMqConnectionManager(connectionFactory, config);

            publishChannel = connectionManager.GetPublishConnection().CreateModel();

            var channelProvider = new FakeChannelProvider(publishChannel);

            sender = new RabbitMqMessageSender(routingTopology, channelProvider, new IncomingContext(null, null));

            dequeueStrategy = new RabbitMqDequeueStrategy(connectionManager, new RepeatedFailuresOverTimeCircuitBreaker("UnitTest", TimeSpan.FromMinutes(2), e => {}),
                                                          new ReceiveOptions(s => SecondaryReceiveSettings.Enabled(CallbackQueue, 1), new MessageConverter(), 1, 1000, false, "Unit test"));


            MakeSureQueueAndExchangeExists(ReceiverQueue);


            MessagePublisher = new RabbitMqMessagePublisher
            {
                ChannelProvider = channelProvider,
                RoutingTopology = routingTopology
            };
            subscriptionManager = new RabbitMqSubscriptionManager
            {
                ConnectionManager = connectionManager,
                EndpointQueueName = ReceiverQueue,
                RoutingTopology   = routingTopology
            };

            dequeueStrategy.Init(Address.Parse(ReceiverQueue), new TransactionSettings(true, TimeSpan.FromSeconds(30), IsolationLevel.ReadCommitted, 5, false, false), m =>
            {
                receivedMessages.Add(m);
                return(true);
            }, (s, exception) => { });

            dequeueStrategy.Start(MaximumConcurrency);
        }
コード例 #3
0
        protected override void Configure(FeatureConfigurationContext context, string connectionString)
        {
            var useCallbackReceiver = context.Settings.Get <bool>(UseCallbackReceiverSettingKey);
            var maxConcurrencyForCallbackReceiver = context.Settings.Get <int>(MaxConcurrencyForCallbackReceiver);
            var queueName               = GetLocalAddress(context.Settings);
            var callbackQueue           = string.Format("{0}.{1}", queueName, RuntimeEnvironment.MachineName);
            var connectionConfiguration = new ConnectionStringParser(context.Settings).Parse(connectionString);

            //MessageConverter messageConverter;

            //if (context.Settings.HasSetting(CustomMessageIdStrategy))
            //{
            //    messageConverter = new MessageConverter(context.Settings.Get<Func<BasicDeliverEventArgs, string>>(CustomMessageIdStrategy));
            //}
            //else
            //{
            //    messageConverter = new MessageConverter();
            //}

            string hostDisplayName;

            if (!context.Settings.TryGet("NServiceBus.HostInformation.DisplayName", out hostDisplayName))//this was added in 5.1.2 of the core
            {
                hostDisplayName = RuntimeEnvironment.MachineName;
            }

            var consumerTag = string.Format("{0} - {1}", hostDisplayName, context.Settings.EndpointName());

            var receiveOptions = new ReceiveOptions(workQueue =>
            {
                //if this isn't the main queue we shouldn't use callback receiver
                if (!useCallbackReceiver || workQueue != queueName)
                {
                    return(SecondaryReceiveSettings.Disabled());
                }
                return(SecondaryReceiveSettings.Enabled(callbackQueue, maxConcurrencyForCallbackReceiver));
            },
                                                    null, //messageConverter,
                                                    connectionConfiguration.PrefetchCount,
                                                    connectionConfiguration.DequeueTimeout * 1000,
                                                    context.Settings.GetOrDefault <bool>("Transport.PurgeOnStartup"),
                                                    consumerTag);



            context.Container.RegisterSingleton(connectionConfiguration);

            context.Container.ConfigureComponent(builder => new KafkaDequeueStrategy(
                                                     builder.Build <IManageKafkaConnections>(),
                                                     SetupCircuitBreaker(builder.Build <CriticalError>()),
                                                     receiveOptions), DependencyLifecycle.InstancePerCall);


            context.Container.ConfigureComponent <OpenPublishChannelBehavior>(DependencyLifecycle.InstancePerCall);

            context.Pipeline.Register <OpenPublishChannelBehavior.Registration>();
            context.Pipeline.Register <ReadIncomingCallbackAddressBehavior.Registration>();

            context.Container.ConfigureComponent(b => new KafkaMessageSender(b.Build <IRoutingTopology>(), b.Build <IChannelProvider>(), b.Build <PipelineExecutor>().CurrentContext), DependencyLifecycle.InstancePerCall);

            if (useCallbackReceiver)
            {
                context.Container.ConfigureComponent <CallbackQueueCreator>(DependencyLifecycle.InstancePerCall)
                .ConfigureProperty(p => p.Enabled, true)
                .ConfigureProperty(p => p.CallbackQueueAddress, Address.Parse(callbackQueue));

                //context.Pipeline.Register<ForwardCallbackQueueHeaderBehavior.Registration>();
                context.Pipeline.Register <SetOutgoingCallbackAddressBehavior.Registration>();
                context.Container.ConfigureComponent <SetOutgoingCallbackAddressBehavior>(DependencyLifecycle.SingleInstance)
                .ConfigureProperty(p => p.CallbackQueue, callbackQueue);
            }

            context.Container.ConfigureComponent <ChannelProvider>(DependencyLifecycle.InstancePerCall)
            .ConfigureProperty(p => p.UsePublisherConfirms, connectionConfiguration.UsePublisherConfirms)
            .ConfigureProperty(p => p.MaxWaitTimeForConfirms, connectionConfiguration.MaxWaitTimeForConfirms);

            context.Container.ConfigureComponent <KafkaDequeueStrategy>(DependencyLifecycle.InstancePerCall);
            context.Container.ConfigureComponent <KafkaMessagePublisher>(DependencyLifecycle.InstancePerCall);

            context.Container.ConfigureComponent <KafkaSubscriptionManager>(DependencyLifecycle.SingleInstance)
            .ConfigureProperty(p => p.EndpointQueueName, queueName);

            context.Container.ConfigureComponent <KafkaQueueCreator>(DependencyLifecycle.InstancePerCall);

            if (context.Settings.HasSetting <IRoutingTopology>())
            {
                context.Container.RegisterSingleton(context.Settings.Get <IRoutingTopology>());
            }
            else
            {
                //var durable = GetDurableMessagesEnabled(context.Settings);

                //IRoutingTopology topology;

                //DirectRoutingTopology.Conventions conventions;


                //if (context.Settings.TryGet(out conventions))
                //{
                //    topology = new DirectRoutingTopology(conventions, durable);
                //}
                //else
                //{
                //    topology = new ConventionalRoutingTopology(durable);
                //}


                //context.Container.RegisterSingleton(topology);
            }

            if (context.Settings.HasSetting("IManageKafkaConnections"))
            {
                context.Container.ConfigureComponent(context.Settings.Get <Type>("IManageKafkaConnections"), DependencyLifecycle.SingleInstance);
            }
            else
            {
                context.Container.ConfigureComponent <KafkaConnectionManager>(DependencyLifecycle.SingleInstance);

                context.Container.ConfigureComponent(builder => new KafkaConnectionFactory(builder.Build <ConnectionConfiguration>()), DependencyLifecycle.InstancePerCall);
            }
        }
コード例 #4
0
        public RealSimulator(string address, string connectionString)
        {
            this.address = address;
            var localConnectionParams = new LocalConnectionParams(null, connectionString, "dbo");

            new SqlServerQueueCreator(new DefaultConnectionStringProvider(localConnectionParams), ConnectionFactory.Default()).CreateQueueIfNecessary(Address.Parse(address), null);

            var transportNotifications = new TransportNotifications();

            taskStarted = transportNotifications.ReceiveTaskStarted.Subscribe(x => AddMessage("Thread started"));
            taskEnded   = transportNotifications.ReceiveTaskStopped.Subscribe(x => AddMessage("Thread died"));

            var purgeExpiredMessagesParams = new PurgeExpiredMessagesParams
            {
                PurgeTaskDelay = Timeout.InfiniteTimeSpan,
                PurgeBatchSize = 1
            };

            dequeueStrategy = new SqlServerPollingDequeueStrategy(localConnectionParams,
                                                                  new ReceiveStrategyFactory(new DummyConnectionStore(), localConnectionParams, Address.Parse("error"), ConnectionFactory.Default()),
                                                                  new QueuePurger(new SecondaryReceiveConfiguration(_ => SecondaryReceiveSettings.Disabled()), localConnectionParams, ConnectionFactory.Default()),
                                                                  new SecondaryReceiveConfiguration(_ => SecondaryReceiveSettings.Disabled()),
                                                                  transportNotifications,
                                                                  new RepeatedFailuresOverTimeCircuitBreaker("A", TimeSpan.FromDays(1000), _ => { }),
                                                                  ConnectionFactory.Default(),
                                                                  purgeExpiredMessagesParams);

            dequeueStrategy.Init(Address.Parse(address), new TransactionSettings(true, TimeSpan.FromMinutes(2), System.Transactions.IsolationLevel.ReadCommitted, 1, false, false),
                                 ProcessMessage, (message, exception) => { });

            sender = new SqlServerMessageSender(new DefaultConnectionStringProvider(localConnectionParams), new DummyConnectionStore(), new DummyCallbackAddressStore(), ConnectionFactory.Default());
        }
コード例 #5
0
        void SetupQueueListener(string queueName)
        {
            receivedMessages = new BlockingCollection <TransportMessage>();
            dequeueStrategy  = new RabbitMqDequeueStrategy(connectionManager, null, new ReceiveOptions(s => SecondaryReceiveSettings.Disabled(), new MessageConverter(), 1, 1000, true, "Cluster test"));
            dequeueStrategy.Init(Address.Parse(queueName), new TransactionSettings(true, TimeSpan.FromSeconds(30), IsolationLevel.ReadCommitted, 5, false, false), m =>
            {
                receivedMessages.Add(m);
                return(true);
            }, (s, exception) =>
            {
            });

            dequeueStrategy.Start(1);
        }