static void SetTransportSpecificFlags(SettingsHolder settings, string poisonQueue)
        {
            //To satisfy requirements of various transports

            //MSMQ
            settings.Set("errorQueue", poisonQueue); //Not SetDefault Because MSMQ transport verifies if that value has been explicitly set

            //RabbitMQ
            settings.SetDefault("RabbitMQ.RoutingTopologySupportsDelayedDelivery", true);

            //SQS
            settings.SetDefault("NServiceBus.AmazonSQS.DisableSubscribeBatchingOnStart", true);

            //ASB
            var builder = new ConventionsBuilder(settings);

            builder.DefiningEventsAs(type => true);
            settings.Set(builder.Conventions);

            //ASQ and ASB
            var serializer = Tuple.Create(new NewtonsoftSerializer() as SerializationDefinition, new SettingsHolder());

            settings.SetDefault("MainSerializer", serializer);

            //SQS and ASQ
            bool isMessageType(Type t) => true;

            var ctor = typeof(MessageMetadataRegistry).GetConstructor(BindingFlags.NonPublic | BindingFlags.Public | BindingFlags.Instance, null, new[] { typeof(Func <Type, bool>) }, null);

#pragma warning disable CS0618 // Type or member is obsolete
            settings.SetDefault <MessageMetadataRegistry>(ctor.Invoke(new object[] { (Func <Type, bool>)isMessageType }));
#pragma warning restore CS0618 // Type or member is obsolete
        }
        public void Customize(EndpointConfiguration endpointConfiguration)
        {
            Log.Info("Customize...");

            var container = ContainerSetup.Create();

            var licensePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "..\\..\\..\\..\\..\\License.xml");

            endpointConfiguration.LicensePath(licensePath);
            endpointConfiguration.UseSerialization <JsonSerializer>();
            endpointConfiguration.Recoverability().Delayed(c => c.NumberOfRetries(0));
            endpointConfiguration.UseContainer <AutofacBuilder>(c => c.ExistingLifetimeScope(container));

            var routing = endpointConfiguration.UseTransport <MsmqTransport>()
                          .ConnectionString("deadLetter=false;journal=false")
                          .Routing();

            routing.RegisterPublisher(typeof(PaymentSucceededEvent), "Divergent.Finance");
            routing.RegisterPublisher(typeof(OrderSubmittedEvent), "Divergent.Sales");

            endpointConfiguration.UsePersistence <NHibernatePersistence>()
            .ConnectionString(ConfigurationManager.ConnectionStrings["Divergent.Shipping"].ToString());

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.AuditProcessedMessagesTo("audit");

            ConventionsBuilder conventions = endpointConfiguration.Conventions();

            conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Divergent") && t.Namespace.EndsWith("Commands") && t.Name.EndsWith("Command"));
            conventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Divergent") && t.Namespace.EndsWith("Events") && t.Name.EndsWith("Event"));

            endpointConfiguration.EnableInstallers();
        }
Exemplo n.º 3
0
 Usage(BusConfiguration busConfiguration)
 {
     #region DefiningEncryptedPropertiesAs
     ConventionsBuilder conventions = busConfiguration.Conventions();
     conventions.DefiningEncryptedPropertiesAs(info => info.Name.EndsWith("EncryptedProperty"));
     #endregion
 }
        private static IConventions CreateConventions()
        {
            var conventionsBuilder = new ConventionsBuilder();

            // Use JSON API standard member naming convention for JSON API resource attributes.
            // For example, FirstName in POCO becomes "first-name" as a JSON API attribute.
            conventionsBuilder.ApiAttributeNamingConventions()
            .AddStandardMemberNamingConvention();

            // Use JSON API standard member naming and plurization conventions of the POCO type
            // name as the JSON API type name.
            // For example, Article POCO type becomes "articles" as the JSON API type.
            conventionsBuilder.ApiTypeNamingConventions()
            .AddPluralNamingConvention()
            .AddStandardMemberNamingConvention();

            // Discover all public properties as JSON API resource attributes.
            // For example, FirstName property in POCO becomes an attribute of a JSON API resource.
            conventionsBuilder.ResourceTypeConventions()
            .AddPropertyDiscoveryConvention();

            var conventions = conventionsBuilder.Create();

            return(conventions);
        }
        public static void Bootstrap(IContainer container)
        {
            // Initialize container
            var configuration = new BusConfiguration();

            configuration.UseContainer <StructureMapBuilder>(c => c.ExistingContainer(container));

            // Define message conventions
            ConventionsBuilder conventions = configuration.Conventions();

            conventions.DefiningCommandsAs(MessageTypeConventions.EndsWith("Command"));
            conventions.DefiningEventsAs(MessageTypeConventions.EndsWith("Event"));
            conventions.DefiningMessagesAs(MessageTypeConventions.EndsWith("Message"));

            // Define features
            configuration.UseSerialization <JsonSerializer>();
            configuration.UsePersistence <InMemoryPersistence>();
            configuration.DisableFeature <Sagas>();
            configuration.DisableFeature <MessageDrivenSubscriptions>();
            configuration.DisableFeature <TimeoutManager>();

            // Add the bus to the container
            var bus = Bus.CreateSendOnly(configuration);

            container.Configure(c => c.ForSingletonOf <ISendOnlyBus>().Use(x => bus).Named("__NAME__"));
        }
        private void InitServiceBus(BusConfiguration config, IContainer container)
        {
            // Configure Logging
            NServiceBus.Logging.LogManager.Use <Log4NetFactory>();

            // Configure container
            config.UseContainer <StructureMapBuilder>(c => c.ExistingContainer(container));

            // Xml serialization makes for easy to read messages.
            config.UseSerialization <JsonSerializer>();

            //Define conventions
            ConventionsBuilder conventions = config.Conventions();

            conventions.DefiningCommandsAs(MessageTypeConventions.EndsWith("Command"));
            conventions.DefiningEventsAs(MessageTypeConventions.EndsWith("Event"));
            conventions.DefiningMessagesAs(MessageTypeConventions.EndsWith("Message"));

            // Keep it simple by default
            config.DisableFeature <SecondLevelRetries>();
            config.DisableFeature <AutoSubscribe>();
            config.DisableFeature <TimeoutManager>();
            config.DisableFeature <DataBus>();

            // Configure for MSMQ
            config.UseTransport <AzureServiceBusTransport>();
            config.PurgeOnStartup(false);

            // Configure Saga Persistence
            config.UsePersistence <InMemoryPersistence>();
        }
        void ConfigureRouter(Context c, RouterConfiguration cfg)
        {
            cfg.AddInterface <TestTransport>("Left", t => t.BrokerAlpha()).EnableMessageDrivenPublishSubscribe(subscriptionStorage);
            var leftIface = cfg.AddInterface <AzureServiceBusTransport>("Right", t =>
            {
                var connString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString");
                t.ConnectionString(connString);
                var settings = t.GetSettings();

                var builder = new ConventionsBuilder(settings);
                builder.DefiningEventsAs(EventConvention);
                settings.Set <NServiceBus.Conventions>(builder.Conventions);

                var topology = t.UseEndpointOrientedTopology();
                topology.EnableMigrationToForwardingTopology();
                topology.RegisterPublisher(typeof(MyAsbEvent), Conventions.EndpointNamingConvention(typeof(Publisher)));

                var serializer = Tuple.Create(new NewtonsoftSerializer() as SerializationDefinition, new SettingsHolder());
                settings.Set("MainSerializer", serializer);
            });

            leftIface.LimitMessageProcessingConcurrencyTo(1); //To ensure when tracer arrives the subscribe request has already been processed.;
            cfg.AddRule(_ => new SuppressTransactionScopeRule());
            cfg.UseStaticRoutingProtocol().AddForwardRoute("Left", "Right");
        }
Exemplo n.º 8
0
        public void Customize(EndpointConfiguration endpointConfiguration)
        {
            Log.Info("Customize...");

            var container = ContainerSetup.Create();

            endpointConfiguration.UseSerialization <JsonSerializer>();
            endpointConfiguration.DisableFeature <SecondLevelRetries>();
            endpointConfiguration.UseContainer <AutofacBuilder>(c => c.ExistingLifetimeScope(container));
            endpointConfiguration.UseTransport <MsmqTransport>()
            .ConnectionString("deadLetter=false;journal=false");
            //endpointConfiguration.UsePersistence<NHibernatePersistence>()
            //    .ConnectionString(ConfigurationManager.ConnectionStrings["Divergent.Customers"].ToString());
            endpointConfiguration.UsePersistence <InMemoryPersistence>();

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.AuditProcessedMessagesTo("audit");

            ConventionsBuilder conventions = endpointConfiguration.Conventions();

            conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Divergent") && t.Namespace.EndsWith("Commands") && t.Name.EndsWith("Command"));
            conventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Divergent") && t.Namespace.EndsWith("Events") && t.Name.EndsWith("Event"));

            endpointConfiguration.EnableInstallers();
        }
Exemplo n.º 9
0
        public NSBMessageBus(IMessageBusContainer container, IMessageBusConfiguration configuration)
        {
            NSBGlobalConfiguration.Config = configuration;

            _nsbConfiguration = new BusConfiguration();
            _nsbConfiguration.UseContainer <NSBContainer>(c => c.Configure(container, configuration));
            _nsbConfiguration.UseSerialization(typeof(NSBSerialiser));
            _nsbConfiguration.EndpointName(configuration.EndpointName);
            _nsbConfiguration.EnableInstallers();
            _nsbConfiguration.DisableFeature <AutoSubscribe>();
            _nsbConfiguration.UsePersistence <InMemoryPersistence>();
            //_nsbConfiguration.LoadMessageHandlers(configuration);
            _nsbConfiguration.CustomConfigurationSource(new NSBRouteConfiguration(configuration));
            _nsbConfiguration.RegisterComponents(c => c.ConfigureComponents(this, configuration));

            ConventionsBuilder builder = _nsbConfiguration.Conventions();

            builder.DefiningCommandsAs(t => configuration.MessageDefinitions.SingleOrDefault(md => md.MessageType == t && md.MessageAction == Core.MessageAction.Command) != null);
            builder.DefiningEventsAs(t => configuration.MessageDefinitions.SingleOrDefault(md => md.MessageType == t && md.MessageAction == Core.MessageAction.Event) != null);
            builder.DefiningMessagesAs(t => configuration.MessageDefinitions.SingleOrDefault(md => md.MessageType == t && md.MessageAction == Core.MessageAction.Message) != null);
            builder.DefiningExpressMessagesAs(t => configuration.MessageDefinitions.SingleOrDefault(md => md.MessageType == t && md.ExpressMe == true) != null);

            _factory = Bus.Create(_nsbConfiguration);
            _factory.Subscribe(configuration.MessageDefinitions);
        }
    object CreateTestConventions(SettingsHolder settings)
    {
        var builder = new ConventionsBuilder(settings);

        builder.DefiningMessagesAs(type => type.FullName.Contains("TestCases"));
        return(builder.Conventions);
    }
Exemplo n.º 11
0
        public void Customize(EndpointConfiguration endpointConfiguration)
        {
            Log.Info("Customize...");

            var providerAssemblies = ReflectionHelper.GetAssembliesPath("..\\..\\Providers", ".Data.dll");
            var container          = ContainerSetup.Create(providerAssemblies);

            var licensePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "License.xml");

            endpointConfiguration.UseSerialization <JsonSerializer>();
            endpointConfiguration.Recoverability().Delayed(c => c.NumberOfRetries(0));
            endpointConfiguration.UseContainer <AutofacBuilder>(c => c.ExistingLifetimeScope(container));
            endpointConfiguration.UseTransport <MsmqTransport>();
            endpointConfiguration.UsePersistence <InMemoryPersistence>();

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.AuditProcessedMessagesTo("audit");

            ConventionsBuilder conventions = endpointConfiguration.Conventions();

            conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Divergent") && t.Namespace.EndsWith("Commands") && t.Name.EndsWith("Command"));
            conventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Divergent") && t.Namespace.EndsWith("Events") && t.Name.EndsWith("Event"));

            endpointConfiguration.EnableInstallers();
        }
Exemplo n.º 12
0
    static BridgeConfiguration <AzureServiceBusTransport, TestTransport> PrepareBridgeConfiguration(ResubscriberComponent resubscriber)
    {
        var bridgeConfiguration = Bridge.Between <AzureServiceBusTransport>("Left", t =>
        {
            var connString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString");
            t.ConnectionString(connString);
            var settings = t.GetSettings();

            var builder = new ConventionsBuilder(settings);
            builder.DefiningEventsAs(x => x.Namespace == "Messages");
            settings.Set(builder.Conventions);

            var topology = t.UseEndpointOrientedTopology();
            topology.RegisterPublisher(typeof(MyAsbEvent), Conventions.EndpointNamingConvention(typeof(Publisher)));

            var serializer = Tuple.Create(new NewtonsoftSerializer() as SerializationDefinition, new SettingsHolder());
            settings.Set("MainSerializer", serializer);

            t.Transactions(TransportTransactionMode.SendsAtomicWithReceive);
        }).And <TestTransport>("Right", t =>
        {
            t.ConfigureNoNativePubSubBrokerA();
        });

        bridgeConfiguration.InterceptForwarding(resubscriber.InterceptMessageForwarding);
        bridgeConfiguration.LimitMessageProcessingConcurrencyTo(1); //To ensure when tracer arrives the subscribe request has already been processed.
        return(bridgeConfiguration);
    }
Exemplo n.º 13
0
        DefineExpress(EndpointConfiguration endpointConfiguration)
        {
            #region ExpressMessageConvention
            ConventionsBuilder builder = endpointConfiguration.Conventions();
            builder.DefiningExpressMessagesAs(t => t.Name.EndsWith("Express"));

            #endregion
        }
Exemplo n.º 14
0
        public static ConventionsBuilder MyDefaultConventions(this ConventionsBuilder conventionsBuilder)
        {
            conventionsBuilder = conventionsBuilder.DefiningMessagesAs(MessageTypeMatching.IsMessageType);
            conventionsBuilder = conventionsBuilder.DefiningCommandsAs(CommandMessageTypeMatching.IsCommandType);
            conventionsBuilder = conventionsBuilder.DefiningEventsAs(EventMessageTypeMatching.IsEventType);

            return(conventionsBuilder);
        }
Exemplo n.º 15
0
 public Usage()
 {
     #region DefiningEventsAs
     BusConfiguration   busConfiguration = new BusConfiguration();
     ConventionsBuilder conventions      = busConfiguration.Conventions();
     conventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Domain") && t.Name.EndsWith("Event"));
     #endregion
 }
Exemplo n.º 16
0
        Usage(BusConfiguration busConfiguration)
        {
            #region DefineMessageWithLargePayloadUsingConvention

            ConventionsBuilder conventions = busConfiguration.Conventions();
            conventions.DefiningDataBusPropertiesAs(p => p.Name.EndsWith("DataBus"));

            #endregion
        }
Exemplo n.º 17
0
 public static ConventionsBuilder ModuleConventions(this ConventionsBuilder builder)
 {
     return(builder
            .DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("ECommerce") && t.Namespace.Contains("Messages.Command"))
            .DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("ECommerce") && t.Namespace.Contains("Messages.Event"))
            .DefiningEncryptedPropertiesAs(p => p.Name.EndsWith("Encrypted"))
            .DefiningDataBusPropertiesAs(p => p.Name.EndsWith("DataBus"))
            .DefiningExpressMessagesAs(t => t.Name.EndsWith("Express")));
 }
        public DefineExpress()
        {
            #region ExpressMessageConvention

            BusConfiguration   busConfiguration = new BusConfiguration();
            ConventionsBuilder builder          = busConfiguration.Conventions();
            builder.DefiningExpressMessagesAs(t => t.Name.EndsWith("Express"));

            #endregion
        }
        public void Without_best_practice_enforcement_it_throws_if_specified_assembly_contains_only_commands()
        {
            //Enforce artificial conventions to make sure the is a single command (but no messages) in an assembly
            var conventionBuilder = new ConventionsBuilder(new SettingsHolder());
            conventionBuilder.DefiningCommandsAs(t => t == typeof(string));


            var source = new AssemblyPublisherSource(typeof(string).Assembly, PublisherAddress.CreateFromEndpointName("Destination"));

            Assert.That(() => source.GenerateWithoutBestPracticeEnforcement(conventionBuilder.Conventions).ToArray(), Throws.Exception.Message.Contains("Cannot configure publisher for assembly"));
        }
Exemplo n.º 20
0
        Usage(EndpointConfiguration endpointConfiguration)
        {
            #region DefiningEventsAs
            ConventionsBuilder conventions = endpointConfiguration.Conventions();
            conventions.DefiningEventsAs(t =>
                                         t.Namespace != null &&
                                         t.Namespace.StartsWith("Domain") &&
                                         t.Name.EndsWith("Event"));

            #endregion
        }
        public void Without_best_practice_enforcement_it_throws_if_specified_assembly_contains_only_commands()
        {
            //Enforce artificial conventions to make sure the is a single command (but no messages) in an assembly
            var conventionBuilder = new ConventionsBuilder(new SettingsHolder());

            conventionBuilder.DefiningCommandsAs(t => t == typeof(string));


            var source = new AssemblyPublisherSource(typeof(string).Assembly, PublisherAddress.CreateFromEndpointName("Destination"));

            Assert.That(() => source.GenerateWithoutBestPracticeEnforcement(conventionBuilder.Conventions).ToArray(), Throws.Exception.Message.Contains("Cannot configure publisher for assembly"));
        }
Exemplo n.º 22
0
        public void Customize(BusConfiguration configuration)
        {
            configuration.EndpointName("dummypublisher");
            configuration.UseTransport <MsmqTransport>();
            configuration.UseSerialization <JsonSerializer>();
            configuration.UsePersistence <InMemoryPersistence>();

            ConventionsBuilder conventions = configuration.Conventions();

            conventions.DefiningCommandsAs(c => c.Namespace != null && c.Namespace == "Messages" && c.Name.EndsWith("Command"));
            conventions.DefiningEventsAs(c => c.Namespace != null && c.Namespace == "Messages" && c.Name.EndsWith("Event"));
        }
Exemplo n.º 23
0
        protected override async Task ExecuteAsync(CancellationToken token)
        {
            const string EndpointName          = "endpoint name";
            var          endpointConfiguration = new EndpointConfiguration(EndpointName);

            endpointConfiguration.UniquelyIdentifyRunningInstance().UsingNames(EndpointName, Environment.MachineName);


            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.AuditProcessedMessagesTo("audit");

            endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

            ConventionsBuilder conventions = endpointConfiguration.Conventions();

            conventions
            .DefiningEventsAs(_ => _.Name.EndsWith("Event"))
            .DefiningCommandsAs(_ => _.Name.EndsWith("Command"))
            .DefiningMessagesAs(_ => _.Name.EndsWith("Message"));

            TransportExtensions <SqlServerTransport> transport =
                endpointConfiguration.UseTransport <SqlServerTransport>();

            NServiceBus.Transport.SQLServer.SubscriptionSettings
                subscriptionSettings = transport.SubscriptionSettings();
            subscriptionSettings.DisableSubscriptionCache();
            subscriptionSettings.SubscriptionTableName("subscriptions", "transportSchema");

            transport.Routing().RouteToEndpoint(
                Assembly.GetAssembly(typeof(MyCommand)),
                EndpointName);


            DelayedDeliverySettings delayedDeliverySettings = transport.NativeDelayedDelivery();

            delayedDeliverySettings.DisableTimeoutManagerCompatibility();

            transport
            .Transactions(TransportTransactionMode.ReceiveOnly)
            .ConnectionString("Data Source=sqlserver;Initial Catalog=transport;User ID=worker;Password=password;Max Pool Size=100;")
            .TransactionScopeOptions(TimeSpan.FromSeconds(30), IsolationLevel.ReadCommitted)
            .DefaultSchema("transportSchema");

            this.endpoint = await Endpoint.Start(endpointConfiguration);

            while (!token.IsCancellationRequested)
            {
                await Task.Delay(1000, token);
            }
        }
Exemplo n.º 24
0
        void MessageConventions(BusConfiguration busConfiguration)
        {
            #region 4to5MessageConventions

            ConventionsBuilder conventions = busConfiguration.Conventions();
            conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace == "MyNamespace" && t.Namespace.EndsWith("Commands"));
            conventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace == "MyNamespace" && t.Namespace.EndsWith("Events"));
            conventions.DefiningMessagesAs(t => t.Namespace != null && t.Namespace == "Messages");
            conventions.DefiningEncryptedPropertiesAs(p => p.Name.StartsWith("Encrypted"));
            conventions.DefiningDataBusPropertiesAs(p => p.Name.EndsWith("DataBus"));
            conventions.DefiningExpressMessagesAs(t => t.Name.EndsWith("Express"));
            conventions.DefiningTimeToBeReceivedAs(t => t.Name.EndsWith("Expires") ? TimeSpan.FromSeconds(30) : TimeSpan.MaxValue);

            #endregion
        }
Exemplo n.º 25
0
        public static IConventions CreateConventions()
        {
            var conventionsBuilder = new ConventionsBuilder();

            conventionsBuilder.ApiAttributeNamingConventions()
            .AddStandardMemberNamingConvention();
            conventionsBuilder.ApiTypeNamingConventions()
            .AddPluralNamingConvention()
            .AddStandardMemberNamingConvention();
            conventionsBuilder.ResourceTypeConventions()
            .AddPropertyDiscoveryConvention();

            var conventions = conventionsBuilder.Create();

            return(conventions);
        }
    public static void ApplyCustomConventions(this BusConfiguration busConfiguration)
    {
        ConventionsBuilder conventions = busConfiguration.Conventions();

        conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith("Commands"));
        conventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace.EndsWith("Events"));
        conventions.DefiningMessagesAs(t => t.Namespace == "Messages");
        conventions.DefiningEncryptedPropertiesAs(p => p.Name.StartsWith("Encrypted"));
        conventions.DefiningDataBusPropertiesAs(p => p.Name.EndsWith("DataBus"));
        conventions.DefiningExpressMessagesAs(t => t.Name.EndsWith("Express"));
        conventions
        .DefiningTimeToBeReceivedAs(t => t.Name.EndsWith("Expires")
                ? TimeSpan.FromSeconds(30)
                : TimeSpan.MaxValue
                                    );
    }
Exemplo n.º 27
0
        private void ConfigureConventions(DocumentContextBase documentContextBase)
        {
            Contract.Requires(documentContextBase != null);

            // If we already have the conventions, no need to create the conventions.
            if (this.GetConventions() != null)
            {
                return;
            }

            var conventionsBuilder = new ConventionsBuilder();

            documentContextBase.OnConventionsCreating(conventionsBuilder);

            var conventions = conventionsBuilder.Create();

            this.SetConventions(conventions);
        }
Exemplo n.º 28
0
 public static void ConfigureConventions(ConventionsBuilder conventions)
 {
     conventions.DefiningCommandsAs(
         type =>
     {
         return(type.Namespace != null &&
                type.Namespace.EndsWith("Commands"));
     });
     conventions.DefiningEventsAs(
         type =>
     {
         return(type.Namespace != null &&
                type.Namespace.EndsWith("Events"));
     });
     conventions.DefiningMessagesAs(
         type =>
     {
         return(type.Namespace == "Messages.Message");
     });
     conventions.DefiningDataBusPropertiesAs(
         property =>
     {
         return(property.Name.EndsWith("DataBus"));
     });
     conventions.DefiningExpressMessagesAs(
         type =>
     {
         return(type.Name.EndsWith("Express"));
     });
     //conventions.DefiningEncryptedPropertiesAs(p =>
     //{
     //    return p.Name.EndsWith("Secret");
     //});
     conventions.DefiningTimeToBeReceivedAs(
         type =>
     {
         if (type.Name.EndsWith("Expires"))
         {
             return(TimeSpan.FromSeconds(30));
         }
         return(TimeSpan.MaxValue);
     });
 }
Exemplo n.º 29
0
        public static void ApplyCustomConventions(this EndpointConfiguration endpointConfiguration)
        {
            ConventionsBuilder conventions = endpointConfiguration.Conventions();

            conventions.DefiningCommandsAs(
                type =>
            {
                return(type.Namespace != null && type.Namespace.EndsWith(CustomConventionsEnum.Commands.ToString()));
            });
            conventions.DefiningEventsAs(
                type =>
            {
                return(type.Namespace != null && (type.Namespace.EndsWith(CustomConventionsEnum.Events.ToString())));
            });
            conventions.DefiningMessagesAs(
                type =>
            {
                return(type.Namespace != null && type.Namespace.EndsWith(CustomConventionsEnum.Messages.ToString()));
            });
        }
Exemplo n.º 30
0
        static void Main(string[] args)
        {
            BusConfiguration configuration = new BusConfiguration();

            configuration.UseTransport <MsmqTransport>();
            configuration.UseSerialization <JsonSerializer>();

            ConventionsBuilder conventions = configuration.Conventions();

            conventions.DefiningCommandsAs(c => c.Namespace != null && c.Namespace == "Messages" && c.Name.EndsWith("Command"));

            using (ISendOnlyBus bus = Bus.CreateSendOnly(configuration))
            {
                Console.ForegroundColor = ConsoleColor.Green;
                Console.WriteLine("When you're ready, press 1 to send the command!");
                Console.WriteLine("Press any other key to exit");

                while (true)
                {
                    var keyPressed = Console.ReadKey();
                    Console.WriteLine();

                    if (keyPressed.Key == ConsoleKey.D1)
                    {
                        SendMessageCommand cmd = new SendMessageCommand()
                        {
                            EventId = Guid.NewGuid().ToString()
                        };
                        Console.WriteLine($"Sending SendMessageCommand with id {cmd.EventId}");
                        bus.Send(cmd);
                    }
                    else
                    {
                        return;
                    }
                }
            }
        }
Exemplo n.º 31
0
        public void Customize(EndpointConfiguration endpointConfiguration)
        {
            Log.Info("Customize...");

            var providerAssemblies = ReflectionHelper.GetAssembliesPath("..\\..\\Providers", ".Data.dll");
            var container          = ContainerSetup.Create(providerAssemblies);

            endpointConfiguration.UseSerialization <JsonSerializer>();
            endpointConfiguration.DisableFeature <SecondLevelRetries>();
            endpointConfiguration.UseContainer <AutofacBuilder>(c => c.ExistingLifetimeScope(container));
            endpointConfiguration.UseTransport <MsmqTransport>();
            endpointConfiguration.UsePersistence <InMemoryPersistence>();

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.AuditProcessedMessagesTo("audit");

            ConventionsBuilder conventions = endpointConfiguration.Conventions();

            conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.StartsWith("Divergent") && t.Namespace.EndsWith("Commands") && t.Name.EndsWith("Command"));
            conventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace.StartsWith("Divergent") && t.Namespace.EndsWith("Events") && t.Name.EndsWith("Event"));

            endpointConfiguration.EnableInstallers();
        }