Esempio n. 1
0
        private static int GetConfiguredNumberOfWorkers()
        {
            const int defaultNumberOfWorkers = 1;

            return RebusConfigurationSection
                .GetConfigurationValueOrDefault(s => s.Workers, defaultNumberOfWorkers)
                .GetValueOrDefault(defaultNumberOfWorkers);
        }
        /// <summary>
        /// Configures that message bodies should be encrypted/decrypted with a base 64-encoded key from the
        /// &lt;rijndael&gt; element in the Rebus configuration section
        /// </summary>
        public static void EncryptMessageBodies(this DecoratorsConfigurer configurer)
        {
            try
            {
                var section = RebusConfigurationSection.LookItUp();

                var rijndael = section.RijndaelSection;

                if (rijndael == null)
                {
                    throw new ConfigurationErrorsException(string.Format(@"Could not find encryption settings in Rebus configuration section. Did you forget the 'rijndael' element?

{0}", GenerateRijndaelHelp()));
                }

                if (string.IsNullOrEmpty(rijndael.Key))
                {
                    throw new ConfigurationErrorsException(string.Format(@"Could not find key settings in Rijndael element - did you forget the 'key' attribute?

{0}", GenerateRijndaelHelp()));
                }

                EncryptMessageBodies(configurer, rijndael.Key);
            }
            catch (ConfigurationErrorsException e)
            {
                throw new ConfigurationException(
                          @"
An error occurred when trying to parse out the configuration of the RebusConfigurationSection:

{0}

-

For this way of configuring input queue to work, you need to supply a correct configuration
section declaration in the <configSections> element of your app.config/web.config - like so:

    <configSections>
        <section name=""rebus"" type=""Rebus.Configuration.RebusConfigurationSection, Rebus"" />
        <!-- other stuff in here as well -->
    </configSections>

-and then you need a <rebus> element some place further down the app.config/web.config,
like so:

    <rebus inputQueue=""my.service.input.queue"">
        <rijndael key=""base64 encoded key""/>
    </rebus>

Note also, that specifying the input queue name with the 'inputQueue' attribute is optional.

A more full example configuration snippet can be seen here:

{1}
",
                          e, RebusConfigurationSection.ExampleSnippetForErrorMessages);
            }
        }
Esempio n. 3
0
        /// <summary>
        /// Constructs the error tracker with the given settings
        /// </summary>
        /// <param name="messageTrackerMaxAge">How long messages will be supervised by the ErrorTracker</param>
        /// <param name="expiredMessageTrackersCheckInterval">This is the interval that will last between checking whether delivery attempts have been tracked for too long</param>
        /// <param name="errorQueueAddress">This is the address of the error queue to which messages should be forwarded whenever they are deemed poisonous</param>
        public ErrorTracker(TimeSpan messageTrackerMaxAge, TimeSpan expiredMessageTrackersCheckInterval, string errorQueueAddress)
        {
            this.errorQueueAddress = errorQueueAddress;
            StartTimeoutTracker(messageTrackerMaxAge, expiredMessageTrackersCheckInterval);

            MaxRetries = Math.Max(0, RebusConfigurationSection
                                  .GetConfigurationValueOrDefault(s => s.MaxRetries, 5)
                                  .GetValueOrDefault(5));
        }
Esempio n. 4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="timeoutSpan">How long messages will be supervised by the ErrorTracker</param>
        /// <param name="timeoutCheckInterval">This is the interval that will last between checking whether delivery attempts have been tracked for too long</param>
        /// <param name="errorQueueAddress">This is the address of the error queue to which messages should be forwarded whenever they are deemed poisonous</param>
        public ErrorTracker(TimeSpan timeoutSpan, TimeSpan timeoutCheckInterval, string errorQueueAddress)
        {
            this.errorQueueAddress = errorQueueAddress;
            StartTimeoutTracker(timeoutSpan, timeoutCheckInterval);

            MaxRetries = Math.Max(0, RebusConfigurationSection
                                  .GetConfigurationValueOrDefault(s => s.MaxRetries, 5)
                                  .GetValueOrDefault(5));
        }
Esempio n. 5
0
        public void CanDetermineNumberOfWorkersFromExtensionMethod()
        {
            // arrange

            // act
            var workers = RebusConfigurationSection.GetConfigurationValueOrDefault(x => x.Workers, 0);

            // assert
            workers.ShouldBe(2);
        }
Esempio n. 6
0
        public IBus Start()
        {
            const int defaultNumberOfWorkers = 1;

            var numberOfWorkers = RebusConfigurationSection
                                  .GetConfigurationValueOrDefault(s => s.Workers, defaultNumberOfWorkers)
                                  .GetValueOrDefault(defaultNumberOfWorkers);

            return(Start(numberOfWorkers));
        }
        public static void UseRabbitMqAndGetInputQueueNameFromAppConfig(this TransportConfigurer configurer, string connectionString)
        {
            try
            {
                var section = RebusConfigurationSection.LookItUp();

                var inputQueueName = section.InputQueue;

                if (string.IsNullOrEmpty(inputQueueName))
                {
                    throw new ConfigurationErrorsException("Could not get input queue name from Rebus configuration section. Did you forget the 'inputQueue' attribute?");
                }

                var errorQueueName = section.ErrorQueue;

                if (string.IsNullOrEmpty(errorQueueName))
                {
                    throw new ConfigurationErrorsException("Could not get input queue name from Rebus configuration section. Did you forget the 'errorQueue' attribute?");
                }

                DoIt(configurer, connectionString, inputQueueName, errorQueueName);
            }
            catch (ConfigurationErrorsException e)
            {
                throw new ConfigurationException(
                          @"
An error occurred when trying to parse out the configuration of the RebusConfigurationSection:

{0}

-

For this way of configuring input queue to work, you need to supply a correct configuration
section declaration in the <configSections> element of your app.config/web.config - like so:

    <configSections>
        <section name=""rebus"" type=""Rebus.Configuration.RebusConfigurationSection, Rebus"" />
        <!-- other stuff in here as well -->
    </configSections>

-and then you need a <rebus> element some place further down the app.config/web.config,
like so:

    <rebus inputQueue=""my.service.input.queue"" errorQueue=""my.service.error.queue"" />

Note also, that specifying the input queue name with the 'inputQueue' attribute is optional.

A more full example configuration snippet can be seen here:

{1}
",
                          e, RebusConfigurationSection.ExampleSnippetForErrorMessages);
            }
        }
        public void CanReadAuditQueueAttribute()
        {
            using (AppConfig.Change(GetPathOf("app.3.config")))
            {
                var section = RebusConfigurationSection.LookItUp();

                section.InputQueue.ShouldBe("input");
                section.ErrorQueue.ShouldBe("error");
                section.AuditQueue.ShouldBe("audit");
            }
        }
        public static RabbitMqOptions UseRabbitMqFromConfigWithLocalName(this RebusTransportConfigurer configurer, string connectionString, string separator)
        {
            var section = RebusConfigurationSection.LookItUp();

            section.VerifyPresenceOfInputQueueConfig();
            section.VerifyPresenceOfErrorQueueConfig();
            var hostname   = GetHostName();
            var inputQueue = string.Format("{0}{2}{1}", section.InputQueue, hostname, separator);
            var errorQueue = string.Format("{0}{2}{1}", section.ErrorQueue, hostname, separator);

            return(configurer.UseRabbitMq(connectionString, inputQueue, errorQueue));
        }
Esempio n. 10
0
        public void CanReadSection_AlsoWorksWhenRijndaelSectionIsOmitted()
        {
            using (AppConfig.Change(GetPathOf("app.2.config")))
            {
                var section = RebusConfigurationSection.LookItUp();

                section.InputQueue.ShouldBe("input");
                section.ErrorQueue.ShouldBe("error");
                section.Workers.ShouldBe(1);

                var rijndaelSection = section.RijndaelSection;
                rijndaelSection.Key.ShouldBe("");
            }
        }
        /// <summary>
        /// Specifies that you want to use Sql Server to both send and receive messages. The input
        /// queue name will be deduced from the Rebus configuration section in the application
        /// configuration file. The input queue will be automatically created if it doesn't exist.
        /// </summary>
        public static SqlServerMessageQueueOptions UseSqlServerAndGetInputQueueNameFromAppConfig(this RebusTransportConfigurer configurer, string connectionStringOrConnectionStringName, string MessageTableName = null)
        {
            try
            {
                string messageTableNameToUse = string.IsNullOrEmpty(MessageTableName) ? DefaultMessagesTableName : MessageTableName;

                var section = RebusConfigurationSection.LookItUp();

                section.VerifyPresenceOfInputQueueConfig();
                section.VerifyPresenceOfErrorQueueConfig();

                var inputQueueName = section.InputQueue;
                var errorQueueName = section.ErrorQueue;

                return(DoIt(connectionStringOrConnectionStringName, configurer, messageTableNameToUse, inputQueueName, errorQueueName));
            }
            catch (ConfigurationErrorsException e)
            {
                throw new ConfigurationException(
                          @"
An error occurred when trying to parse out the configuration of the RebusConfigurationSection:

{0}

-

For this way of configuring input queue to work, you need to supply a correct configuration
section declaration in the <configSections> element of your app.config/web.config - like so:

    <configSections>
        <section name=""rebus"" type=""Rebus.Configuration.RebusConfigurationSection, Rebus"" />
        <!-- other stuff in here as well -->
    </configSections>

-and then you need a <rebus> element some place further down the app.config/web.config,
like so:

    <rebus inputQueue=""my.service.input.queue"" errorQueue=""my.service.error.queue"" />

Note also, that specifying the input queue name with the 'inputQueue' attribute is optional.

A more full example configuration snippet can be seen here:

{1}
",
                          e, RebusConfigurationSection.ExampleSnippetForErrorMessages);
            }
        }
        /// <summary>
        /// Specifies that you want to use the file system to both send and receive messages. The input queue name will be deduced from the Rebus configuration
        /// section in the application configuration file. The input queue will be automatically created if it doesn't exist.
        /// </summary>
        public static void UseTheFileSystemAndGetInputQueueNameFromAppConfig(this RebusTransportConfigurer configurer, string baseDirectory)
        {
            try
            {
                var section = RebusConfigurationSection.LookItUp();

                section.VerifyPresenceOfInputQueueConfig();
                section.VerifyPresenceOfErrorQueueConfig();

                var inputQueueName = section.InputQueue;
                var errorQueueName = section.ErrorQueue;

                DoIt(configurer, baseDirectory, inputQueueName, errorQueueName);
            }
            catch (ConfigurationErrorsException e)
            {
                throw new ConfigurationException(
                          @"
An error occurred when trying to parse out the configuration of the RebusConfigurationSection:

{0}

-

For this way of configuring input queue to work, you need to supply a correct configuration
section declaration in the <configSections> element of your app.config/web.config - like so:

    <configSections>
        <section name=""rebus"" type=""Rebus.Configuration.RebusConfigurationSection, Rebus"" />
        <!-- other stuff in here as well -->
    </configSections>

-and then you need a <rebus> element some place further down the app.config/web.config,
like so:

    <rebus inputQueue=""my_service_input_queue"" errorQueue=""my_service_error_queue"" />

Note also, that specifying the input queue name with the 'inputQueue' attribute is optional.

A more full example configuration snippet can be seen here:

{1}
",
                          e, RebusConfigurationSection.ExampleSnippetForErrorMessages);
            }
        }
        public void CanReadSection()
        {
            using (AppConfig.Change(GetPathOf("app.1.config")))
            {
                var section = RebusConfigurationSection.LookItUp();

                section.InputQueue.ShouldBe("this.is.my.input.queue");
                section.ErrorQueue.ShouldBe("this.is.my.error.queue");
                section.Workers.ShouldBe(5);

                section.Address.ShouldBe("10.0.0.9");

                var rijndaelSection = section.RijndaelSection;
                rijndaelSection.ShouldNotBe(null);
                rijndaelSection.Iv.ShouldBe("OLYKdaDyETlu7NbDMC45dA==");
                rijndaelSection.Key.ShouldBe("oA/ZUnFsR9w1qEatOByBSXc4woCuTxmR99tAuQ56Qko=");
            }
        }
Esempio n. 14
0
        static RabbitMqOptions DoItWithAppConfig(RebusTransportConfigurer configurer, string connectionString, bool ensureExchangeIsDeclared)
        {
            try
            {
                var section = RebusConfigurationSection.LookItUp();

                section.VerifyPresenceOfInputQueueConfig();
                section.VerifyPresenceOfErrorQueueConfig();

                var inputQueueName = section.InputQueue;
                var errorQueueName = section.ErrorQueue;

                return(DoIt(configurer, connectionString, inputQueueName, errorQueueName, ensureExchangeIsDeclared));
            }
            catch (ConfigurationErrorsException e)
            {
                throw new ConfigurationException(
                          @"
An error occurred when trying to parse out the configuration of the RebusConfigurationSection:

{0}

-

For this way of configuring input queue to work, you need to supply a correct configuration section declaration in the <configSections> element of your app.config/web.config - like so:

    <configSections>
        <section name=""rebus"" type=""Rebus.Configuration.RebusConfigurationSection, Rebus"" />
        <!-- other stuff in here as well -->
    </configSections>

-and then you need a <rebus> element some place further down the app.config/web.config, like so:

    <rebus inputQueue=""my.service.input.queue"" errorQueue=""my.service.error.queue"" />

Note also, that specifying the input queue name with the 'inputQueue' attribute is optional.

A more full example configuration snippet can be seen here:

{1}
",
                          e, RebusConfigurationSection.ExampleSnippetForErrorMessages);
            }
        }
Esempio n. 15
0
        public void CanReadSection()
        {
            using (AppConfig.Change(GetPathOf("app.1.config")))
            {
                var section = RebusConfigurationSection.LookItUp();

                section.InputQueue.ShouldBe("this.is.my.input.queue");
                section.ErrorQueue.ShouldBe("this.is.my.error.queue");
                section.TimeoutManagerAddress.ShouldBe("somewhere_else");
                section.Workers.ShouldBe(5);
                section.MaxRetries.ShouldBe(6);

                section.Address.ShouldBe("10.0.0.9");

                var rijndaelSection = section.RijndaelSection;
                rijndaelSection.ShouldNotBe(null);
                rijndaelSection.Key.ShouldBe("oA/ZUnFsR9w1qEatOByBSXc4woCuTxmR99tAuQ56Qko=");
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Constructs the bus with the specified ways of achieving its goals.
        /// </summary>
        /// <param name="activateHandlers">The bus will use this to construct handlers for received messages.</param>
        /// <param name="sendMessages">Will be used to send transport messages when you send, publish, and reply.</param>
        /// <param name="receiveMessages">Will be used to receive transport messages. If the bus is configured to run with multiple threads, this one should be reentrant.</param>
        /// <param name="storeSubscriptions">Will be used to store subscription information. Is only relevant if the bus is a publisher, i.e. it publishes messages and other services assume they can subscribe to its messages.</param>
        /// <param name="storeSagaData">Will be used to store saga data. Is only relevant if one or more handlers are derived from <see cref="Saga"/>.</param>
        /// <param name="determineMessageOwnership">Will be used to resolve a destination in cases where the message destination is not explicitly specified as part of a send/subscribe operation.</param>
        /// <param name="serializeMessages">Will be used to serialize and deserialize transport messages.</param>
        /// <param name="inspectHandlerPipeline">Will be called to inspect the pipeline of handlers constructed to handle an incoming message.</param>
        /// <param name="errorTracker">Will be used to track failed delivery attempts.</param>
        /// <param name="storeTimeouts">Optionally provides an internal timeout manager to be used instead of sending timeout requests to an external timeout manager</param>
        /// <param name="configureAdditionalBehavior"></param>
        public RebusBus(
            IActivateHandlers activateHandlers, ISendMessages sendMessages, IReceiveMessages receiveMessages, IStoreSubscriptions storeSubscriptions, IStoreSagaData storeSagaData,
            IDetermineMessageOwnership determineMessageOwnership, ISerializeMessages serializeMessages, IInspectHandlerPipeline inspectHandlerPipeline, IErrorTracker errorTracker,
            IStoreTimeouts storeTimeouts, ConfigureAdditionalBehavior configureAdditionalBehavior)
        {
            this.activateHandlers            = activateHandlers;
            this.sendMessages                = sendMessages;
            this.receiveMessages             = receiveMessages;
            this.storeSubscriptions          = storeSubscriptions;
            this.determineMessageOwnership   = determineMessageOwnership;
            this.serializeMessages           = serializeMessages;
            this.storeSagaData               = storeSagaData;
            this.inspectHandlerPipeline      = inspectHandlerPipeline;
            this.errorTracker                = errorTracker;
            this.storeTimeouts               = storeTimeouts;
            this.configureAdditionalBehavior = configureAdditionalBehavior;

            batch   = new RebusBatchOperations(determineMessageOwnership, storeSubscriptions, this);
            routing = new RebusRouting(this);

            rebusId       = Interlocked.Increment(ref rebusIdCounter);
            continuations = new RebusSynchronizationContext();

            log.Info("Rebus bus {0} created", rebusId);

            if (storeTimeouts == null)
            {
                var timeoutManagerEndpointAddress = RebusConfigurationSection
                                                    .GetConfigurationValueOrDefault(s => s.TimeoutManagerAddress, "rebus.timeout");

                log.Info("Using external timeout manager with input queue '{0}'", timeoutManagerEndpointAddress);
                timeoutManagerAddress = timeoutManagerEndpointAddress;
            }
            else
            {
                log.Info("Using internal timeout manager");
                timeoutManagerAddress = this.receiveMessages.InputQueueAddress;
                dueTimeoutScheduler   = new DueTimeoutScheduler(storeTimeouts, new DeferredMessageReDispatcher(this));
            }
        }
Esempio n. 17
0
 static string GetTimeoutManagerAddress()
 {
     return(RebusConfigurationSection
            .GetConfigurationValueOrDefault(s => s.TimeoutManagerAddress, "rebus.timeout"));
 }
Esempio n. 18
0
 string GetMachineAddress()
 {
     return(RebusConfigurationSection.GetConfigurationValueOrDefault(s => s.Address, Environment.MachineName));
 }
        void PopulateMappings(RebusConfigurationSection configurationSection)
        {
            //ensure that all assembly mappings are processed first,
            //so that explicit type mappings will take precendence
            var mappingElements = configurationSection.MappingsCollection
                .OrderBy(c => !c.IsAssemblyName);

            foreach (var element in mappingElements)
            {
                if (element.IsAssemblyName)
                {
                    var assemblyName = element.Messages;

                    Log.Info("Mapping assembly: {0}", assemblyName);

                    var assembly = LoadAssembly(assemblyName);

                    foreach (var type in assembly.GetTypes())
                    {
                        Map(type, element.Endpoint);
                    }
                }
                else
                {
                    var typeName = element.Messages;

                    Log.Info("Mapping type: {0}", typeName);

                    var messageType = Type.GetType(typeName);

                    if (messageType == null)
                    {
                        throw new ConfigurationException(
                            @"Could not find the message type {0}. If you choose to map a specific message type,
            please ensure that the type is available for Rebus to load. This requires that the
            assembly can be found in Rebus' current runtime directory, that the type is available,
            and that any (of the optional) version and key requirements are matched",
                            typeName);
                    }

                    Map(messageType, element.Endpoint);
                }
            }
        }
        public static void UseEncryptedMsmqAndGetConfigurationFromAppConfig(this TransportConfigurer configurer)
        {
            try
            {
                var section = RebusConfigurationSection.LookItUp();

                var inputQueueName = section.InputQueue;

                if (string.IsNullOrEmpty(inputQueueName))
                {
                    throw new ConfigurationErrorsException("Could not get input queue name from Rebus configuration section. Did you forget the 'inputQueue' attribute?");
                }

                var errorQueueName = section.ErrorQueue;

                if (string.IsNullOrEmpty(errorQueueName))
                {
                    throw new ConfigurationErrorsException("Could not get error queue name from Rebus configuration section. Did you forget the 'errorQueue' attribute?");
                }

                var rijndael = section.RijndaelSection;

                if (rijndael == null)
                {
                    throw new ConfigurationErrorsException("Could not find encryption settings in Rebus configuration section. Did you forget the 'rijndael' element?");
                }

                if (string.IsNullOrEmpty(rijndael.Iv))
                {
                    throw new ConfigurationErrorsException("Could not find initialization vector settings in Rijndael element - did you forget the 'iv' attribute?");
                }

                if (string.IsNullOrEmpty(rijndael.Key))
                {
                    throw new ConfigurationErrorsException("Could not find key settings in Rijndael element - did you forget the 'key' attribute?");
                }

                DoItEncrypted(configurer, inputQueueName, rijndael.Iv, rijndael.Key, errorQueueName);
            }
            catch (ConfigurationErrorsException e)
            {
                throw new ConfigurationException(
                          @"
An error occurred when trying to parse out the configuration of the RebusConfigurationSection:

{0}

-

For this way of configuring input queue to work, you need to supply a correct configuration
section declaration in the <configSections> element of your app.config/web.config - like so:

    <configSections>
        <section name=""rebus"" type=""Rebus.Configuration.RebusConfigurationSection, Rebus"" />
        <!-- other stuff in here as well -->
    </configSections>

-and then you need a <rebus> element some place further down the app.config/web.config,
like so:

    <rebus InputQueue=""my.service.input.queue"">
        <rijndael iv=""initialization vector here"" key=""key here""/>
    </rebus>

Note also, that specifying the input queue name with the 'inputQueue' attribute is optional.

A more full example configuration snippet can be seen here:

{1}
",
                          e, RebusConfigurationSection.ExampleSnippetForErrorMessages);
            }
        }