Esempio n. 1
0
    static async Task Main()
    {
        //required to prevent possible occurrence of .NET Core issue https://github.com/dotnet/coreclr/issues/12668
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
        Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");

        Console.Title = "Samples.MultipleDeserializers.ReceivingEndpoint";

        #region configAll

        var endpointConfiguration = new EndpointConfiguration("Samples.MultipleDeserializers.ReceivingEndpoint");

        // Xml
        endpointConfiguration.UseSerialization <XmlSerializer>();

        // External Newtonsoft Json
        var externalNewtonsoftJson = endpointConfiguration.AddDeserializer <NewtonsoftSerializer>();
        externalNewtonsoftJson.ContentTypeKey("NewtonsoftJson");

        // External Newtonsoft Bson
        var externalNewtonsoftBson = endpointConfiguration.AddDeserializer <NewtonsoftSerializer>();
        externalNewtonsoftBson.ReaderCreator(stream => new BsonDataReader(stream));
        externalNewtonsoftBson.WriterCreator(stream => new BsonDataWriter(stream));
        externalNewtonsoftBson.ContentTypeKey("NewtonsoftBson");

        // Jil
        var jil = endpointConfiguration.AddDeserializer <JilSerializer>();
        jil.ContentTypeKey("Jil");

        // Message Pack
        endpointConfiguration.AddDeserializer <MessagePackSerializer>();

        // Wire
        endpointConfiguration.AddDeserializer <WireSerializer>();

        // register the mutator so the the message on the wire is written
        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent <IncomingMessageBodyWriter>(DependencyLifecycle.InstancePerCall);
        });

        #endregion

        endpointConfiguration.UsePersistence <LearningPersistence>();
        endpointConfiguration.UseTransport <LearningTransport>();

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Esempio n. 2
0
    static async Task AsyncMain()
    {
        Console.Title = "Samples.MultipleDeserializers.ReceivingEndpoint";

        #region configAll

        var endpointConfiguration = new EndpointConfiguration("Samples.MultipleDeserializers.ReceivingEndpoint");

        // Xml
        endpointConfiguration.UseSerialization <XmlSerializer>();

        // External Newtonsoft Json
        var externalNewtonsoftJson = endpointConfiguration.AddDeserializer <NewtonsoftSerializer>();
        externalNewtonsoftJson.ContentTypeKey("NewtonsoftJson");

        // External Newtonsoft Bson
        var externalNewtonsoftBson = endpointConfiguration.AddDeserializer <NewtonsoftSerializer>();
        externalNewtonsoftBson.ReaderCreator(stream => new BsonDataReader(stream));
        externalNewtonsoftBson.WriterCreator(stream => new BsonDataWriter(stream));
        externalNewtonsoftBson.ContentTypeKey("NewtonsoftBson");

        // Jil
        var jil = endpointConfiguration.AddDeserializer <JilSerializer>();
        jil.ContentTypeKey("Jil");

        // Message Pack
        endpointConfiguration.AddDeserializer <MessagePackSerializer>();

        // Wire
        endpointConfiguration.AddDeserializer <WireSerializer>();

        // register the mutator so the the message on the wire is written
        endpointConfiguration.RegisterComponents(
            registration: components =>
        {
            components.ConfigureComponent <IncomingMessageBodyWriter>(DependencyLifecycle.InstancePerCall);
        });

        #endregion

        endpointConfiguration.UsePersistence <LearningPersistence>();
        endpointConfiguration.UseTransport <LearningTransport>();

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Esempio n. 3
0
        private static async Task Main()
        {
            LogManager.Use <NLogFactory>();
            NLog.LogManager.Configuration.DefaultCultureInfo = CultureInfo.InvariantCulture;
            log = LogManager.GetLogger <Program>();

            Console.Title = "ClientUI";

            var endpointConfiguration = new EndpointConfiguration("ClientUI");

            endpointConfiguration.AuditProcessedMessagesTo("audit");

            var transport = endpointConfiguration.UseTransport <LearningTransport>();

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.EnableInstallers();

            var routing = transport.Routing();

            routing.RouteToEndpoint(typeof(PlaceOrder), "Sales");

            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.AddDeserializer <XmlSerializer>();

            var endpointInstance = await Endpoint.Start(endpointConfiguration)
                                   .ConfigureAwait(false);

            await RunLoop(endpointInstance)
            .ConfigureAwait(false);

            await endpointInstance.Stop()
            .ConfigureAwait(false);
        }
Esempio n. 4
0
    static async Task Main()
    {
        Console.Title = "Samples.Azure.ServiceBus.MsmqEndpoint";

        var endpointConfiguration = new EndpointConfiguration("Samples.Azure.ServiceBus.MsmqEndpoint");

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.EnableInstallers();
        endpointConfiguration.UsePersistence <InMemoryPersistence>();
        endpointConfiguration.UseSerialization <XmlSerializer>();
        endpointConfiguration.AddDeserializer <NewtonsoftSerializer>();
        var routing = endpointConfiguration.UseTransport <MsmqTransport>().Routing();

        var bridge = routing.ConnectToBridge("Bridge-MSMQ");

        bridge.RegisterPublisher(typeof(OtherEvent), "Samples.Azure.ServiceBus.AsbEndpoint");

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        Console.WriteLine("Press any key to exit");
        Console.ReadKey();

        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
        public void Customize(EndpointConfiguration endpointConfiguration)
        {
            var asbConnectionString = Environment.GetEnvironmentVariable("NSBCompat_ASBConnectionString");

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.EnableInstallers();
            endpointConfiguration.UsePersistence <InMemoryPersistence>();
            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.AddDeserializer <XmlSerializer>();

            var transport = endpointConfiguration.UseTransport <AzureServiceBusTransport>();

            transport.ConnectionString(asbConnectionString);
            transport.UseForwardingTopology();

            var routing = transport.Routing();
            var bridge  = routing.ConnectToBridge("payments.bridge.endpoint.asb");

            var conventions = endpointConfiguration.Conventions();

            conventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith("Commands"));
            conventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace.EndsWith("Events"));

            bridge.RouteToEndpoint(typeof(RefundPayment), "Payments.Endpoint.Distributor");
        }
Esempio n. 6
0
    static async Task Main()
    {
        Console.Title = "Samples.Azure.ServiceBus.MsmqEndpoint";

        var endpointConfiguration = new EndpointConfiguration("Samples.Azure.ServiceBus.MsmqEndpoint");

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.EnableInstallers();
        endpointConfiguration.UsePersistence <InMemoryPersistence>();
        endpointConfiguration.UseSerialization <XmlSerializer>();
        endpointConfiguration.AddDeserializer <JsonSerializer>();
        var recoverability = endpointConfiguration.Recoverability();

        recoverability.DisableLegacyRetriesSatellite();
        endpointConfiguration.UseTransport <MsmqTransport>();

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        Console.WriteLine("Press any key to exit");
        Console.ReadKey();

        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Esempio n. 7
0
        static EndpointConfiguration CreateConfiguration()
        {
            var endpointConfiguration = new EndpointConfiguration("Sales");

            endpointConfiguration.AuditProcessedMessagesTo("audit");

            var transport = endpointConfiguration.UseTransport <LearningTransport>();

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.EnableInstallers();

            var recoverability = endpointConfiguration.Recoverability();

            recoverability.Delayed(delayed => delayed.NumberOfRetries(0));

            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.AddDeserializer <XmlSerializer>();

            var conventions = endpointConfiguration.Conventions();

            conventions.DefiningEventsAs(
                type =>
                type == typeof(OrderPlaced)
                );

            return(endpointConfiguration);
        }
Esempio n. 8
0
        static async Task Main()
        {
            Console.Title = "ClientUI";

            var endpointConfiguration = new EndpointConfiguration("ClientUI");

            endpointConfiguration.AuditProcessedMessagesTo("audit");

            var transport = endpointConfiguration.UseTransport <LearningTransport>();

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.EnableInstallers();

            var routing = transport.Routing();

            routing.RouteToEndpoint(typeof(PlaceOrder), "Sales");

            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.AddDeserializer <XmlSerializer>();

            var endpointInstance = await Endpoint.Start(endpointConfiguration)
                                   .ConfigureAwait(false);

            await RunLoop(endpointInstance)
            .ConfigureAwait(false);

            await endpointInstance.Stop()
            .ConfigureAwait(false);
        }
    private static EndpointConfiguration CreateConfiguration()
    {
        var endpointConfiguration = new EndpointConfiguration("Shipping");

        endpointConfiguration.AuditProcessedMessagesTo("audit");

        var transport = endpointConfiguration.UseTransport <LearningTransport>();

        endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
        endpointConfiguration.AddDeserializer <XmlSerializer>();

        var conventions = endpointConfiguration.Conventions();

        conventions.DefiningEventsAs(
            type => type.Namespace != null && type.Namespace.EndsWith(".Events") ||
            typeof(IEvent).IsAssignableFrom(type)
            );

        endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

        var displayName = Dns.GetHostName();
        var identifier  = StringToGuid("Shipping@" + displayName);

        var endpointIdentity = endpointConfiguration.UniquelyIdentifyRunningInstance();

        endpointIdentity.UsingCustomDisplayName(displayName);
        endpointIdentity.UsingCustomIdentifier(identifier);

        return(endpointConfiguration);
    }
Esempio n. 10
0
        private static async Task Main()
        {
            Console.Title = "Billing";

            var endpointConfiguration = new EndpointConfiguration("Billing");

            endpointConfiguration.AuditProcessedMessagesTo("audit");

            var transport = endpointConfiguration.UseTransport <LearningTransport>();

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.EnableInstallers();

            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.AddDeserializer <XmlSerializer>();

            var conventions = endpointConfiguration.Conventions();

            conventions.DefiningEventsAs(
                type => type.Namespace != null && type.Namespace.EndsWith(".Events")
                );

            var endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false);

            Console.WriteLine("Press Enter to exit.");
            Console.ReadLine();

            await endpointInstance.Stop().ConfigureAwait(false);
        }
    private static EndpointConfiguration CreateConfiguration()
    {
        var endpointConfiguration = new EndpointConfiguration("Sales");

        endpointConfiguration.AuditProcessedMessagesTo("audit");

        var transport = endpointConfiguration.UseTransport <LearningTransport>();

        var recoverability = endpointConfiguration.Recoverability();

        recoverability.Delayed(delayed => delayed.NumberOfRetries(0));

        endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
        endpointConfiguration.AddDeserializer <XmlSerializer>();

        var conventions = endpointConfiguration.Conventions();

        conventions.DefiningEventsAs(
            type =>
            type == typeof(OrderPlaced)
            );

        endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

        var displayName = Dns.GetHostName();
        var identifier  = StringToGuid("Sales@" + displayName);

        var endpointIdentity = endpointConfiguration.UniquelyIdentifyRunningInstance();

        endpointIdentity.UsingCustomDisplayName(displayName);
        endpointIdentity.UsingCustomIdentifier(identifier);

        return(endpointConfiguration);
    }
Esempio n. 12
0
 AdditionalDeserializers(EndpointConfiguration endpointConfiguration)
 {
     #region AdditionalDeserializers
     // configures XML serialization as default
     endpointConfiguration.UseSerialization <XmlSerializer>();
     // configures additional deserialization
     endpointConfiguration.AddDeserializer <JsonSerializer>();
     #endregion
 }
 AdditionalDeserializers(EndpointConfiguration endpointConfiguration)
 {
     #region AdditionalDeserializers
     // configures XML serialization as default
     endpointConfiguration.UseSerialization<XmlSerializer>();
     // configures additional deserialization
     endpointConfiguration.AddDeserializer<JsonSerializer>();
     #endregion
 }
Esempio n. 14
0
        void Initialize(EndpointConfiguration config)
        {
            var transportCustomization = settings.LoadTransportCustomization();

            var buildQueueLengthProvider = QueueLengthProviderBuilder(settings.ConnectionString, transportCustomization);

            var containerBuilder = CreateContainer(settings, buildQueueLengthProvider);

            var transportSettings = new TransportSettings
            {
                RunCustomChecks  = false,
                ConnectionString = settings.ConnectionString,
                EndpointName     = settings.EndpointName,
                MaxConcurrency   = settings.MaximumConcurrencyLevel
            };

            transportCustomization.CustomizeForMonitoringIngestion(config, transportSettings);

            if (settings.EnableInstallers)
            {
                config.EnableInstallers(settings.Username);
            }

            config.DefineCriticalErrorAction(c =>
            {
                this.onCriticalError(c);
                return(TaskEx.Completed);
            });

            config.GetSettings().Set(settings);

            config.UseSerialization <NewtonsoftSerializer>();
            config.UsePersistence <InMemoryPersistence>();
            config.SendFailedMessagesTo(settings.ErrorQueue);
            config.DisableFeature <AutoSubscribe>();

            config.AddDeserializer <TaggedLongValueWriterOccurrenceSerializerDefinition>();
            config.Pipeline.Register(typeof(MessagePoolReleasingBehavior), "Releases pooled message.");
            config.EnableFeature <QueueLength.QueueLength>();

            config.EnableFeature <LicenseCheckFeature>();

            containerBuilder.RegisterSource(new AnyConcreteTypeNotAlreadyRegisteredSource(type => type.Assembly == typeof(Bootstrapper).Assembly && type.GetInterfaces().Any() == false));
            containerBuilder.RegisterInstance(settings);

            RegisterInternalWebApiControllers(containerBuilder);

            container = containerBuilder.Build();

#pragma warning disable CS0618 // Type or member is obsolete
            config.UseContainer <AutofacBuilder>(
#pragma warning restore CS0618 // Type or member is obsolete
                c => c.ExistingLifetimeScope(container)
                );

            Startup = new Startup(container);
        }
 AdditionalDeserializers(EndpointConfiguration endpointConfiguration)
 {
     #region AdditionalDeserializers
     // configures XML serialization as default
     endpointConfiguration.UseSerialization <XmlSerializer>();
     // configures additional deserialization
     var mySerializer = endpointConfiguration.AddDeserializer <MyCustomSerializerDefinition>();
     mySerializer.Settings("serializerSetting");
     #endregion
 }
 void RegisterSerializers()
 {
     #region AdditionalDeserializers
     EndpointConfiguration configuration = new EndpointConfiguration();
     // configures XML serialization as default
     configuration.UseSerialization<XmlSerializer>();
     // configures additional deserialization
     configuration.AddDeserializer<JsonSerializer>();
     #endregion
 }
 AdditionalDeserializers(EndpointConfiguration endpointConfiguration)
 {
     #region AdditionalDeserializers
     // Configures new default serialization
     var mySerializer = endpointConfiguration.UseSerialization <MyCustomSerializerDefinition>();
     mySerializer.Settings("serializerSetting");
     // Configures additional deserializer, like the previous (default) serializer to be compatible with in-flight messages.
     endpointConfiguration.AddDeserializer <XmlSerializer>();
     #endregion
 }
Esempio n. 18
0
    static async Task AsyncMain()
    {
        Console.Title = "Samples.Serialization.TransitionPhase3";
        var endpointConfiguration = new EndpointConfiguration("Samples.Serialization.TransitionPhase3");

        endpointConfiguration.SharedConfig();

        #region Phase3

        var settingsV2 = new JsonSerializerSettings
        {
            Formatting       = Formatting.Indented,
            ContractResolver = new ExtendedResolver()
        };
        var serializationV2 = endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
        serializationV2.Settings(settingsV2);
        serializationV2.ContentTypeKey("jsonv2");

        var settingsV1 = new JsonSerializerSettings
        {
            Formatting = Formatting.Indented
        };
        var serializationV1 = endpointConfiguration.AddDeserializer <NewtonsoftSerializer>();
        serializationV1.Settings(settingsV1);
        serializationV1.ContentTypeKey("jsonv1");

        #endregion

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        try
        {
            #region send-to-both
            var message = MessageCreator.NewOrder();
            await endpointInstance.SendLocal(message)
            .ConfigureAwait(false);

            await endpointInstance.Send("Samples.Serialization.TransitionPhase2", message)
            .ConfigureAwait(false);

            await endpointInstance.Send("Samples.Serialization.TransitionPhase4", message)
            .ConfigureAwait(false);

            #endregion
            Console.WriteLine("Order Sent");
            Console.WriteLine("Press any key to exit");
            Console.ReadKey();
        }
        finally
        {
            await endpointInstance.Stop()
            .ConfigureAwait(false);
        }
    }
Esempio n. 19
0
    static async Task Main()
    {
        //required to prevent possible occurrence of .NET Core issue https://github.com/dotnet/coreclr/issues/12668
        Thread.CurrentThread.CurrentUICulture = new CultureInfo("en-US");
        Thread.CurrentThread.CurrentCulture   = new CultureInfo("en-US");

        Console.Title = "Samples.Serialization.TransitionPhase3";
        var endpointConfiguration = new EndpointConfiguration("Samples.Serialization.TransitionPhase3");

        endpointConfiguration.SharedConfig();

        #region Phase3

        var settingsV2 = new JsonSerializerSettings
        {
            Formatting       = Formatting.Indented,
            ContractResolver = new ExtendedResolver()
        };
        var serializationV2 = endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
        serializationV2.Settings(settingsV2);
        serializationV2.ContentTypeKey("jsonv2");

        var settingsV1 = new JsonSerializerSettings
        {
            Formatting = Formatting.Indented
        };
        var serializationV1 = endpointConfiguration.AddDeserializer <NewtonsoftSerializer>();
        serializationV1.Settings(settingsV1);
        serializationV1.ContentTypeKey("jsonv1");

        #endregion

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        #region send-to-both
        var message = MessageCreator.NewOrder();
        await endpointInstance.SendLocal(message)
        .ConfigureAwait(false);

        await endpointInstance.Send("Samples.Serialization.TransitionPhase2", message)
        .ConfigureAwait(false);

        await endpointInstance.Send("Samples.Serialization.TransitionPhase4", message)
        .ConfigureAwait(false);

        #endregion
        Console.WriteLine("Order Sent");
        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Esempio n. 20
0
    private static IHostBuilder CreateHostBuilder(string[] args)
    {
        var builder = Host.CreateDefaultBuilder(args);

        builder.UseWindowsService();

        builder.ConfigureLogging((ctx, logging) =>
        {
            logging.AddConfiguration(ctx.Configuration.GetSection("Logging"));

            logging.AddEventLog();
            logging.AddConsole();
        }).UseNLog();

        builder.UseNServiceBus(ctx =>
        {
            var endpointConfiguration = new EndpointConfiguration("Sales");
            endpointConfiguration.EnableInstallers();
            endpointConfiguration.AuditProcessedMessagesTo("audit");

            var transport = endpointConfiguration.UseTransport <LearningTransport>();

            var recoverability = endpointConfiguration.Recoverability();
            recoverability.Delayed(delayed => delayed.NumberOfRetries(0));

            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.AddDeserializer <XmlSerializer>();

            var conventions = endpointConfiguration.Conventions();
            conventions.DefiningEventsAs(
                type =>
                type == typeof(OrderPlaced)
                );

            if (Environment.UserInteractive && Debugger.IsAttached)
            {
                endpointConfiguration.EnableInstallers();
            }

            endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

            var displayName = Dns.GetHostName();
            var identifier  = StringToGuid("Sales@" + displayName);

            var endpointIdentity = endpointConfiguration.UniquelyIdentifyRunningInstance();
            endpointIdentity.UsingCustomDisplayName(displayName);
            endpointIdentity.UsingCustomIdentifier(identifier);

            return(endpointConfiguration);
        });

        return(builder.ConfigureServices(services => { }));
    }
Esempio n. 21
0
    private static IHostBuilder CreateHostBuilder(string[] args)
    {
        var builder = Host.CreateDefaultBuilder(args);

        builder.UseWindowsService();

        builder.ConfigureLogging((ctx, logging) =>
        {
            logging.AddConfiguration(ctx.Configuration.GetSection("Logging"));

            logging.AddEventLog();
            logging.AddConsole();
        }).UseNLog();

        builder.UseNServiceBus(ctx =>
        {
            var endpointConfiguration = new EndpointConfiguration("Billing");

            var transport = endpointConfiguration.UseTransport <LearningTransport>();

            // TODO: optionally choose a different serializer
            // https://docs.particular.net/nservicebus/serialization/
            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.AddDeserializer <XmlSerializer>();

            var conventions = endpointConfiguration.Conventions();
            conventions.DefiningEventsAs(
                type => (type.Namespace != null && type.Namespace.EndsWith(".Events"))
                );

            endpointConfiguration.AuditProcessedMessagesTo("audit");

            endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

            if (Environment.UserInteractive && Debugger.IsAttached)
            {
                endpointConfiguration.EnableInstallers();
            }

            var displayName = System.Net.Dns.GetHostName();
            var identifier  = StringToGuid("Billing@" + displayName);

            var endpointIdentity = endpointConfiguration.UniquelyIdentifyRunningInstance();
            endpointIdentity.UsingCustomDisplayName(displayName);
            endpointIdentity.UsingCustomIdentifier(identifier);

            return(endpointConfiguration);
        });

        return(builder.ConfigureServices(services => { }));
    }
Esempio n. 22
0
    static async Task Main()
    {
        Console.Title = "Samples.MultipleDeserializers.ReceivingEndpoint";

        #region configAll

        var endpointConfiguration = new EndpointConfiguration("Samples.MultipleDeserializers.ReceivingEndpoint");

        // Xml
        endpointConfiguration.UseSerialization <XmlSerializer>();

        // External Newtonsoft Json
        var externalNewtonsoftJson = endpointConfiguration.AddDeserializer <NewtonsoftSerializer>();
        externalNewtonsoftJson.ContentTypeKey("NewtonsoftJson");

        // External Newtonsoft Bson
        var externalNewtonsoftBson = endpointConfiguration.AddDeserializer <NewtonsoftSerializer>();
        externalNewtonsoftBson.ReaderCreator(stream => new BsonDataReader(stream));
        externalNewtonsoftBson.WriterCreator(stream => new BsonDataWriter(stream));
        externalNewtonsoftBson.ContentTypeKey("NewtonsoftBson");

        // register the mutator so the the message on the wire is written
        endpointConfiguration.RegisterMessageMutator(new IncomingMessageBodyWriter());

        #endregion

        endpointConfiguration.UseTransport <LearningTransport>();

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        Console.WriteLine("Press any key to exit");
        Console.ReadKey();
        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
        public static void MakeMetricsReceiver(EndpointConfiguration config, Settings settings, string explicitConnectionStringValue = null)
        {
            var transportType = DetermineTransportType(settings);

            var buildQueueLengthProvider = QueueLengthProviderBuilder(explicitConnectionStringValue, transportType);

            config.UseContainer <AutofacBuilder>(
                c => c.ExistingLifetimeScope(CreateContainer(settings, buildQueueLengthProvider))
                );

            var transport = config.UseTransport(transportType)
                            .Transactions(TransportTransactionMode.ReceiveOnly);

            if (explicitConnectionStringValue != null)
            {
                transport.ConnectionString(explicitConnectionStringValue);
            }
            else
            {
#pragma warning disable 618
                transport.ConnectionStringName("NServiceBus/Transport");
#pragma warning restore 618
            }

            if (settings.EnableInstallers)
            {
                config.EnableInstallers(settings.Username);
            }

            config.DefineCriticalErrorAction(c =>
            {
                Environment.FailFast("NServiceBus Critical Error", c.Exception);
                return(TaskEx.Completed);
            });

            config.GetSettings().Set(settings);

            config.UseSerialization <NewtonsoftSerializer>();
            config.UsePersistence <InMemoryPersistence>();
            config.SendFailedMessagesTo(settings.ErrorQueue);
            config.DisableFeature <AutoSubscribe>();

            config.AddDeserializer <TaggedLongValueWriterOccurrenceSerializerDefinition>();
            config.Pipeline.Register(typeof(MessagePoolReleasingBehavior), "Releases pooled message.");
            config.EnableFeature <QueueLength.QueueLength>();

            config.EnableFeature <HttpEndpoint>();
        }
Esempio n. 24
0
        public EndpointConfiguration Build()
        {
            //string nsbLicense = $"{ AppDomain.CurrentDomain.BaseDirectory }/license/license.xml";
            string nsbLicense = $"C://NServiceBus//license.xml";
            string messagePublisherConnection = _configuration.GetConnectionString("NServiceBus_Transport");

            var endpointConfiguration = new EndpointConfiguration(EndpointName);

            endpointConfiguration.LicensePath(nsbLicense);
            endpointConfiguration.EnableInstallers();
            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.AuditProcessedMessagesTo("audit");

            endpointConfiguration.AddDeserializer <XmlSerializer>();
            var settings = new JsonSerializerSettings
            {
                Formatting = Formatting.Indented
            };
            var serialization = endpointConfiguration.UseSerialization <NewtonsoftSerializer>();

            serialization.Settings(settings);

            string nServiceBusConnection = _configuration.GetConnectionString("NServiceBus_Transport");
            var    transport             = endpointConfiguration.UseTransport <SqlServerTransport>();

            transport.Transactions(TransportTransactionMode.TransactionScope);
            transport.ConnectionString(nServiceBusConnection);
            transport.SubscriptionSettings().DisableSubscriptionCache();

            var subscriptions = transport.SubscriptionSettings();

            subscriptions.SubscriptionTableName(
                tableName: "SubscriptionRouting",
                schemaName: "dbo",
                catalogName: "Message.NServiceBus");

            var persistence = endpointConfiguration.UsePersistence <SqlPersistence>();

            persistence.ConnectionBuilder(() => new SqlConnection(messagePublisherConnection));

            var dialect = persistence.SqlDialect <SqlDialect.MsSqlServer>();

            transport.Routing().RouteToEndpoint(typeof(SmartMeterRegistered), "MessagePublisher");

            return(endpointConfiguration);
        }
Esempio n. 25
0
        private static IHostBuilder CreateHostBuilder(string[] args)
        {
            var builder = Host.CreateDefaultBuilder(args);

            builder.UseWindowsService();

            builder.ConfigureLogging((ctx, logging) =>
            {
                logging.AddConfiguration(ctx.Configuration.GetSection("Logging"));

                logging.AddEventLog();
                logging.AddConsole();
            }).UseNLog();

            builder.UseNServiceBus(ctx =>
            {
                var endpointConfiguration = new EndpointConfiguration("ClientUI");
                endpointConfiguration.AuditProcessedMessagesTo("audit");

                var transport = endpointConfiguration.UseTransport <LearningTransport>();
                endpointConfiguration.SendFailedMessagesTo("error");

                if (Environment.UserInteractive && Debugger.IsAttached)
                {
                    endpointConfiguration.EnableInstallers();
                }

                var routing = transport.Routing();
                routing.RouteToEndpoint(typeof(PlaceOrder), "Sales");

                endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
                endpointConfiguration.AddDeserializer <XmlSerializer>();

                endpointConfiguration.DefineCriticalErrorAction(OnCriticalError);

                return(endpointConfiguration);
            });

            return(builder.ConfigureServices(services => { services.AddHostedService <Worker>(); }));
        }
Esempio n. 26
0
        static EndpointConfiguration CreateConfiguration()
        {
            var endpointConfiguration = new EndpointConfiguration("Billing");

            endpointConfiguration.AuditProcessedMessagesTo("audit");

            var transport = endpointConfiguration.UseTransport <LearningTransport>();

            endpointConfiguration.SendFailedMessagesTo("error");
            endpointConfiguration.EnableInstallers();

            endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
            endpointConfiguration.AddDeserializer <XmlSerializer>();

            var conventions = endpointConfiguration.Conventions();

            conventions.DefiningEventsAs(
                type => (type.Namespace != null && type.Namespace.EndsWith(".Events"))
                );

            return(endpointConfiguration);
        }
Esempio n. 27
0
    static async Task Main()
    {
        Console.Title = "Samples.Azure.ServiceBus.AsbEndpoint";
        var endpointConfiguration = new EndpointConfiguration("Samples.Azure.ServiceBus.AsbEndpoint");

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.EnableInstallers();
        endpointConfiguration.UsePersistence <InMemoryPersistence>();
        endpointConfiguration.UseSerialization <JsonSerializer>();
        endpointConfiguration.AddDeserializer <XmlSerializer>();
        var transport        = endpointConfiguration.UseTransport <AzureServiceBusTransport>();
        var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString");

        if (string.IsNullOrWhiteSpace(connectionString))
        {
            throw new Exception("Could not read the 'AzureServiceBus.ConnectionString' environment variable. Check the sample prerequisites.");
        }
        transport.ConnectionString(connectionString);
        transport.UseForwardingTopology();
        var recoverability = endpointConfiguration.Recoverability();

        recoverability.DisableLegacyRetriesSatellite();

        #region connect-asb-side-of-bridge

        var routing = transport.Routing();
        var bridge  = routing.ConnectToBridge("Bridge-ASB");

        #endregion

        #region route-command-via-bridge

        bridge.RouteToEndpoint(typeof(MyCommand), "Samples.Azure.ServiceBus.MsmqEndpoint");

        #endregion

        #region subscribe-to-event-via-bridge

        bridge.RegisterPublisher(typeof(MyEvent), "Samples.Azure.ServiceBus.MsmqEndpoint");

        #endregion

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        Console.WriteLine("Press Enter to send a command");
        Console.WriteLine("Press any other key to exit");

        while (true)
        {
            var key = Console.ReadKey().Key;
            if (key != ConsoleKey.Enter)
            {
                break;
            }

            await endpointInstance.Send(new MyCommand { Property = "command from ASB endpoint" }).ConfigureAwait(false);

            Console.WriteLine("\nCommand sent");
        }

        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }
Esempio n. 28
0
    static async Task Main()
    {
        const string letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
        var          random  = new Random();

        Console.Title = "Samples.Azure.ServiceBus.AsbEndpoint";
        var endpointConfiguration = new EndpointConfiguration("Samples.Azure.ServiceBus.AsbEndpoint");

        endpointConfiguration.SendFailedMessagesTo("error");
        endpointConfiguration.EnableInstallers();
        endpointConfiguration.UsePersistence <InMemoryPersistence>();
        endpointConfiguration.UseSerialization <NewtonsoftSerializer>();
        endpointConfiguration.AddDeserializer <XmlSerializer>();

        var transport        = endpointConfiguration.UseTransport <AzureServiceBusTransport>();
        var connectionString = Environment.GetEnvironmentVariable("AzureServiceBus.ConnectionString");

        if (string.IsNullOrWhiteSpace(connectionString))
        {
            throw new Exception("Could not read the 'AzureServiceBus.ConnectionString' environment variable. Check the sample prerequisites.");
        }
        transport.ConnectionString(connectionString);

        #region connect-asb-side-of-bridge

        var routing = transport.Routing();
        var bridge  = routing.ConnectToBridge("Bridge");

        #endregion

        #region route-command-via-bridge

        bridge.RouteToEndpoint(typeof(MyCommand), "Samples.Azure.ServiceBus.MsmqEndpoint");

        #endregion

        #region subscribe-to-event-via-bridge

        bridge.RegisterPublisher(typeof(MyEvent), "Samples.Azure.ServiceBus.MsmqEndpoint");

        #endregion

        var endpointInstance = await Endpoint.Start(endpointConfiguration)
                               .ConfigureAwait(false);

        Console.WriteLine("Press Enter to send a command");
        Console.WriteLine("Press any other key to exit");

        while (true)
        {
            var key = Console.ReadKey().Key;
            if (key != ConsoleKey.Enter)
            {
                break;
            }

            var prop = new string(Enumerable.Range(0, 3).Select(i => letters[random.Next(letters.Length)]).ToArray());
            await endpointInstance.Send(new MyCommand { Property = prop }).ConfigureAwait(false);

            Console.WriteLine($"\nCommand with value '{prop}' sent");
        }

        await endpointInstance.Stop()
        .ConfigureAwait(false);
    }