//create messaging endpoint private static async Task Main() { Console.Title = "ClientUI"; //EndpointConfiguration class defintes all settings which determines how endpoint operates //string ClientUI is endpoint name var endpointConfiguration = new EndpointConfiguration("ClientUI"); // //transport is a setting which NServiceBus uses to send and receives messages // var transport = endpointConfiguration.UseTransport<LearningTransport>(); //MSMQ does not support natively Publish/Subscribe var transport = endpointConfiguration.UseTransport <MsmqTransport>(); //message subscription info stored in memory instead endpointConfiguration.UsePersistence <InMemoryPersistence>(); //error queue specified endpointConfiguration.SendFailedMessagesTo("error"); //creates message queues required by endpoints endpointConfiguration.EnableInstallers(); //establises commands of type PlaceOrder should be sent to the Sales endpoint var routing = transport.Routing(); routing.RouteToEndpoint(typeof(PlaceOrder), "Sales"); endpointConfiguration.UseSerialization <JsonSerializer>(); //starts endpoint var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); await RunLoop(endpointInstance) .ConfigureAwait(false); //endpoint runs until user presses enter and then stops await endpointInstance.Stop() .ConfigureAwait(false); }
public static void ApplyCommonConfiguration(this EndpointConfiguration endpointConfiguration, bool asSendOnly = false, Action <RoutingSettings <LearningTransport> > configureRouting = null) { endpointConfiguration.UseSerialization <NewtonsoftSerializer>(); var transportConfig = endpointConfiguration.UseTransport <LearningTransport>(); configureRouting?.Invoke(transportConfig.Routing()); if (!asSendOnly) { endpointConfiguration.UsePersistence <LearningPersistence>(); } endpointConfiguration.AuditProcessedMessagesTo("audit"); endpointConfiguration.SendFailedMessagesTo("error"); endpointConfiguration.SendHeartbeatTo( serviceControlQueue: "Particular.ServiceControl", frequency: TimeSpan.FromSeconds(10), timeToLive: TimeSpan.FromSeconds(5)); var messageConventions = endpointConfiguration.Conventions(); messageConventions.DefiningMessagesAs(t => t.Namespace != null && t.Namespace.EndsWith(".Messages")); messageConventions.DefiningEventsAs(t => t.Namespace != null && t.Namespace.EndsWith(".Messages.Events")); messageConventions.DefiningCommandsAs(t => t.Namespace != null && t.Namespace.EndsWith(".Messages.Commands")); if (asSendOnly) { endpointConfiguration.SendOnly(); } else { var metrics = endpointConfiguration.EnableMetrics(); metrics.SendMetricDataToServiceControl( serviceControlMetricsAddress: "Particular.Monitoring", interval: TimeSpan.FromSeconds(5)); } }
public static async Task <IEndpointInstance> Configure(string endpointName) { var endpointConfiguration = new NServiceBus.EndpointConfiguration(endpointName); endpointConfiguration.SendFailedMessagesTo("error"); endpointConfiguration.EnableInstallers(); 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); var endpointInstance = await Endpoint.Start(endpointConfiguration) .ConfigureAwait(false); return(endpointInstance); }