Example #1
0
        void PossiblyInitializeFromConfigurationSection()
        {
            var config = RebusConfigurationSection.LookItUp(returnNullIfNotFound: true);

            if (config == null)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(config.AuditQueue))
            {
                PerformMessageAudit(config.AuditQueue);
            }
        }
Example #2
0
        void PossiblyInitializeFromConfigurationSection()
        {
            var config = RebusConfigurationSection.LookItUp();

            if (config == null)
            {
                return;
            }

            if (!string.IsNullOrWhiteSpace(config.AuditQueue))
            {
                PerformMessageAudit(config.AuditQueue);
            }
            BackoffBehavior = BackoffBehavior.Default();
        }
        /// <summary>
        /// Constructs the endpoint mapper, using the specified type filter to determine whether an encountered
        /// type should be mapped. Can be used to avoid mapping e.g. factories and stuff if you want to put
        /// helper classes inside your message assembly
        /// </summary>
        public DetermineMessageOwnershipFromRebusConfigurationSection(Func <Type, bool> typeFilter)
        {
            this.typeFilter = typeFilter;

            try
            {
                var section = RebusConfigurationSection.LookItUp();

                PopulateMappings(section);
            }
            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 endpoint mappings 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:

{1}

This example shows how it's possible to map all types from an entire assembly to an endpoint. 

This is the preferred way of mapping message types, because it is a sign that you have structured your code
in a nice 1-message-assembly-to-1-endpoint kind of way, which requires the least amount of configuration
and maintenance on your part.

You CAN, however, map a single type at a time, and these explicit mappings WILL OVERRIDE assembly
mappings. So if you map an entire assembly to an endpoint, and you map one of the types from that
assembly to another endpoint explicitly, the explicit mapping will be the one taking effect.

Note also, that specifying the input queue name with the 'inputQueue' attribute is optional.
",
                          e, RebusConfigurationSection.ExampleSnippetForErrorMessages);
            }
        }
        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);
                }
            }
        }