public SenderToQueueElasticUpdate(EndpointConfiguration endPoint, string messageQueueName) { _endPoint = endPoint; _transport = _endPoint.UseTransport <LearningTransport>(); _routing = _transport.Routing(); _messageQueueName = messageQueueName; }
private static async Task MainAsync() { const string EndpointName = "Finance.Endpoint"; Console.Title = EndpointName; var endpointConfiguration = new EndpointConfiguration(EndpointName); endpointConfiguration.UsePersistence <LearningPersistence>(); TransportExtensions <LearningTransport> transport = endpointConfiguration.UseTransport <LearningTransport>(); RoutingSettings <LearningTransport> routing = transport.Routing(); routing.RouteToEndpoint(typeof(ChargeCreditCardRequest), "ItOps.CreditCardProcessor.Gateway"); endpointConfiguration.EnableFeature <RoutingSlips>(); endpointConfiguration.RegisterComponents( configureComponents => { configureComponents.ConfigureComponent <InMemoryOrders>(DependencyLifecycle.SingleInstance); }); var endpoint = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false); Console.WriteLine("Press any key to exit"); Console.ReadKey(); await endpoint.Stop().ConfigureAwait(false); }
public static EndpointConfiguration CreateCommonConfiguration(string name) { string connectionString = @"Server=192.168.0.114;Database=ServiceControlSql;User Id=sa;Password=GQI1qNeq0oEHlL;"; EndpointConfiguration cfg = new EndpointConfiguration(name); PersistenceExtensions <SqlPersistence> persistence = cfg.UsePersistence <SqlPersistence>(); TransportExtensions <SqlServerTransport> transport = cfg.UseTransport <SqlServerTransport>(); SerializationExtensions <NewtonsoftSerializer> ser = cfg.UseSerialization <NewtonsoftSerializer>(); cfg.AuditSagaStateChanges(serviceControlQueue: "Particular.ServiceControl.Sql"); cfg.AuditProcessedMessagesTo("audit"); cfg.SendFailedMessagesTo("error"); cfg.EnableInstallers(); cfg.DefineCriticalErrorAction(OnCriticalError); persistence.SqlDialect <SqlDialect.MsSqlServer>(); persistence.ConnectionBuilder(() => new SqlConnection(connectionString)); persistence.SubscriptionSettings().DisableCache(); transport.ConnectionString(connectionString); transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive); transport.Routing().ApplyRouting(); RecoverabilitySettings recoverabilityConfig = cfg.Recoverability(); recoverabilityConfig.Immediate(delegate(ImmediateRetriesSettings config) { config.NumberOfRetries(3); }); recoverabilityConfig.Delayed(delegate(DelayedRetriesSettings config) { config.NumberOfRetries(3); }); return(cfg); }
private void EndpointConfigurationEvents_ConfiguringTransport(object sender, TransportExtensions <AzureServiceBusTransport> e) { var configHelper = new ServiceFabricConfigurationHelper(); var routing = e.Routing(); routing.RouteToEndpoint(typeof(ProcessLearnerCommand), configHelper.GetSetting("ProcessLearnerEndpoint")); }
public static void ApplyDefaultRouting(this TransportExtensions transport) { var routing = transport.Routing(); routing.RouteToEndpoint(typeof(CreateOrderCommand), "Backend"); routing.RouteToEndpoint(typeof(SendCustomerReceipt), "Backend"); }
static void ConfigureReceiverSideDistributionShipOrder(TransportExtensions transportConfig, PartitionsInformation partitionInfo) { // TODO 11 var partitionKeysAsInts = partitionInfo.Partitions.Select(i => new { Key = i, AsInt = Convert.ToInt32(i) }).OrderBy(i => i.AsInt); var routing = transportConfig.Routing(); var receiverSideDistribution = routing.EnableReceiverSideDistribution(partitionInfo.Partitions); receiverSideDistribution.AddPartitionMappingForMessageType <ShipOrder>( mapMessageToPartitionKey: shipOrder => { var zipCodeAsNumber = Convert.ToInt32(shipOrder.ZipCode); int current = -1; foreach (var keys in partitionKeysAsInts) { var next = keys.AsInt; if (zipCodeAsNumber > current && zipCodeAsNumber <= next) { return(keys.Key); } current = next; } throw new Exception($"Invalid zip code '{zipCodeAsNumber}' for message of type '{shipOrder.GetType()}'."); }); }
public EndpointConfigurationBuilder RouteToEndpoint(Type messageType, string endpointName) { var routing = _transportExtensions.Routing(); routing.RouteToEndpoint(messageType, endpointName); return(this); }
protected override void CustomizeTransport(TransportExtensions <SqlServerTransport> transport) { #region Setup subscription to another database / service: transport.UseCatalogForEndpoint("Sales", SqlHelper.BuildCatalogName("Sales")); //Associate "Sales" service with the database it owns transport.Routing().RegisterPublisher(typeof(OrderReceived), "Sales"); //Do not use app.config to define where the publisher is #endregion }
static void Routing(TransportExtensions <LearningTransport> transport) { #region ShipWithAlpine-Routing var routing = transport.Routing(); routing.RouteToEndpoint(typeof(ShipOrder), "Shipping"); routing.RouteToEndpoint(typeof(ShipWithMaple), "Shipping"); routing.RouteToEndpoint(typeof(ShipWithAlpine), "Shipping"); #endregion }
public static void RegisterRoutes(this TransportExtensions <LearningTransport> transport) { var routing = transport.Routing(); routing.RouteToEndpoint(typeof(StartBatch).Assembly, typeof(StartBatch).Namespace, "BatchProcessingEndpoint"); routing.RouteToEndpoint(typeof(ProcessBatchItemData), "BatchDataItemProcessingEndpoint"); routing.RouteToEndpoint(typeof(DoOperation6), "LongRunningProcessEndpoint"); routing.RouteToEndpoint(typeof(DoOperation4).Assembly, typeof(DoOperation4).Namespace, "OperationsEndpoint"); routing.RouteToEndpoint(typeof(ValidateBatchItemData), "ValidationEndpoint"); }
void StaticRoutesEndpointBroker(TransportExtensions transportExtensions) { #region Routing-StaticRoutes-Endpoint-Broker var routing = transportExtensions.Routing(); routing.RouteToEndpoint( messageType: typeof(AcceptOrder), destination: "Sales"); #endregion }
public static void RegisterPublishers(TransportExtensions <MsmqTransport> transport) { var routing = transport.Routing(); foreach (var endpointName in EndpointNames.All) { var assemblyName = endpointName.Replace("WireCompat", ""); var eventType = Type.GetType($"{assemblyName}.Messages.MyEvent, {assemblyName}.Messages"); routing.RegisterPublisher(eventType, endpointName); } }
static void ConfigureRouting <T>(TransportExtensions <T> transport) where T : TransportDefinition { var routing = transport.Routing(); routing.RouteToEndpoint(typeof(PlaceOrder), "Sales.Api"); routing.RouteToEndpoint(typeof(CancelOrder), "Sales.Api"); routing.RouteToEndpoint(typeof(StoreOrder), "Sales.Api"); routing.RouteToEndpoint(typeof(AcceptOrder), "Sales.Api"); routing.RouteToEndpoint(typeof(RecordConsumerBehavior), "Marketing.Api"); // For transports that do not support publish/subcribe natively, e.g. MSMQ, SqlTransport, call RegisterPublisher }
static void ConfigureReceiverSideDistributionOrderShipped(TransportExtensions transportConfig, PartitionsInformation partitionInfo) { // TODO 10 var routing = transportConfig.Routing(); var receiverSideDistribution = routing.EnableReceiverSideDistribution(partitionInfo.Partitions); receiverSideDistribution.AddPartitionMappingForMessageType <OrderShipped>( mapMessageToPartitionKey: orderShipped => { var chocolateType = orderShipped.OrderId.Split(new[] { ";" }, StringSplitOptions.RemoveEmptyEntries)[0]; return(chocolateType); }); }
public static EndpointConfiguration UseAzureServiceBusTransport(this EndpointConfiguration config, Func <string> connectionStringBuilder, Action <RoutingSettings> routing, Action <TransportExtensions <LearningTransport> > transportSettings) { TransportExtensions <LearningTransport> config1 = config.UseTransport <LearningTransport>(); transportSettings?.Invoke(config1); config1.Transactions(TransportTransactionMode.ReceiveOnly); routing((RoutingSettings)config1.Routing <LearningTransport>()); return(config); }
static void ConfigureReceiverSideDistributionCandidateVoteCount(TransportExtensions <AzureServiceBusTransport> transportConfig, PartitionsInformation partitionInfo) { #region ConfigureReceiverSideDistribution-CandidateVoteCount var routing = transportConfig.Routing(); var receiverSideDistribution = routing.EnableReceiverSideDistribution(partitionInfo.Partitions); receiverSideDistribution.AddPartitionMappingForMessageType <VotePlaced>( mapMessageToPartitionKey: votePlaced => { return(votePlaced.Candidate); }); #endregion }
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); } }
private static async Task Main(string[] args) { Console.Title = "ClientUI"; var endpointConfiguration = new EndpointConfiguration("ClientUI"); TransportExtensions <LearningTransport> transport = endpointConfiguration.UseTransport <LearningTransport>(); RoutingSettings <LearningTransport> routing = transport.Routing(); routing.RouteToEndpoint(typeof(PlaceOrder), "Sales"); IEndpointInstance endpointInstance = await Endpoint.Start(endpointConfiguration).ConfigureAwait(false); await RunLoop(endpointInstance).ConfigureAwait(false); await endpointInstance.Stop().ConfigureAwait(false); }
public IServiceProvider ConfigureServices(IServiceCollection services) { services .AddMvcCore() .AddCors() .AddJsonFormatters() .AddApiExplorer() .SetCompatibilityVersion(CompatibilityVersion.Version_2_2); services .AddSignalR(); services.AddSpaStaticFiles(configuration => { configuration.RootPath = "ClientApp/dist"; }); services.AddSingleton <IEquipmentRepository, EquipmentRepository>(); services.AddScoped <EquipmentFilter>(); services.AddSingleton(serviceProvider => _endpoint); var endpointConfiguration = new EndpointConfiguration("Bondora.ConstructionEquipmentRental.Service"); // It's used for development, for real case we should use any real transport (RabbitMQ and so on). TransportExtensions <LearningTransport> transport = endpointConfiguration.UseTransport <LearningTransport>(); UpdateableServiceProvider container = null; endpointConfiguration.UseContainer <ServicesBuilder>(customizations => { customizations.ExistingServices(services); customizations.ServiceProviderFactory(serviceCollection => { container = new UpdateableServiceProvider(serviceCollection); return(container); }); }); RoutingSettings <LearningTransport> routing = transport.Routing(); routing.RouteToEndpoint( assembly: typeof(GetInvoiceCommand).Assembly, destination: "Bondora.ConstructionEquipmentRental.Billing"); _endpoint = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult(); return(container); }
private static void ConfigureMessageRouting(TransportExtensions <SqsTransport> transport) { var routing = transport.Routing(); routing.RouteToEndpoint( messageType: typeof(ProcessPayment) , destination: "Example.PaymentSaga" ); routing.RouteToEndpoint( messageType: typeof(MakePayment) , destination: "Example.PaymentProcessorWorker" ); routing.RegisterPublisher( eventType: typeof(ICompletedMakePayment), publisherEndpoint: "Example.PaymentProcessorWorker"); }
void SubscribeRouting(TransportExtensions <MsmqTransport> transportExtensions) { #region Routing-RegisterPublisher var routing = transportExtensions.Routing(); routing.RegisterPublisher( assembly: typeof(OrderAccepted).Assembly, publisherEndpoint: "Sales"); routing.RegisterPublisher( assembly: typeof(OrderAccepted).Assembly, @namespace: "PriorityMessages", publisherEndpoint: "Preferred"); routing.RegisterPublisher( eventType: typeof(OrderSent), publisherEndpoint: "Sending"); #endregion }
void LogicalRouting(TransportExtensions transportExtensions) { #region Routing-Logical var routing = transportExtensions.Routing(); routing.RouteToEndpoint( assembly: typeof(AcceptOrder).Assembly, destination: "Sales"); routing.RouteToEndpoint( assembly: typeof(AcceptOrder).Assembly, @namespace: "PriorityMessages", destination: "Preferred"); routing.RouteToEndpoint( messageType: typeof(SendOrder), destination: "Sending"); #endregion }
static void ConfigureSenderSideRoutingCandidateVoteCount(TransportExtensions <AzureServiceBusTransport> transportConfig) { #region ConfigureSenderSideRouting-CandidateVoteCount var remotePartitions = new[] { "33000", "66000", "99000" }; Func <TrackZipCode, string> convertStringZipCodeToHighKey = message => { var zipCodeAsNumber = Convert.ToInt32(message.ZipCode); // 00000..33000 => 33000 33001..66000 => 66000 66001..99000 => 99000 if (zipCodeAsNumber >= 0 && zipCodeAsNumber <= 33000) { return("33000"); } if (zipCodeAsNumber > 33000 && zipCodeAsNumber <= 66000) { return("66000"); } if (zipCodeAsNumber > 66000 && zipCodeAsNumber <= 99000) { return("99000"); } throw new Exception($"Invalid zip code '{zipCodeAsNumber}' for message of type '{message.GetType()}'."); }; var routing = transportConfig.Routing(); var senderSideDistribution = routing.RegisterPartitionedDestinationEndpoint( destinationEndpoint: "ZipCodeVoteCount", partitions: remotePartitions); senderSideDistribution.AddPartitionMappingForMessageType <TrackZipCode>( mapMessageToPartitionKey: trackZipCode => { return(convertStringZipCodeToHighKey(trackZipCode)); }); #endregion }
public Endpoint <T> WithRouting() { this.routingConfiguration = transportConfiguration.Routing(); return(this); }
public IEndpointBuilder ConfigureRouting(Action <RoutingSettings <SqlServerTransport> > routing) { routing(transport.Routing()); return(this); }