public void TearDown() { testCancellationTokenSource?.Dispose(); MessagePump?.Stop().GetAwaiter().GetResult(); TransportInfrastructure?.Stop().GetAwaiter().GetResult(); Configurer?.Cleanup().GetAwaiter().GetResult(); }
protected async Task StartPump(Func <MessageContext, Task> onMessage, Func <ErrorContext, Task <ErrorHandleResult> > onError, TransportTransactionMode transactionMode, Action <string, Exception> onCriticalError = null) { InputQueueName = GetTestName() + transactionMode; ErrorQueueName = $"{InputQueueName}.error"; transportSettings.Set("NServiceBus.Routing.EndpointName", InputQueueName); var queueBindings = new QueueBindings(); queueBindings.BindReceiving(InputQueueName); queueBindings.BindSending(ErrorQueueName); transportSettings.Set(ErrorQueueSettings.SettingsKey, ErrorQueueName); transportSettings.Set <QueueBindings>(queueBindings); transportSettings.Set <EndpointInstances>(new EndpointInstances()); Configurer = CreateConfigurer(); var configuration = Configurer.Configure(transportSettings, transactionMode); TransportInfrastructure = configuration.TransportInfrastructure; IgnoreUnsupportedTransactionModes(transactionMode); IgnoreUnsupportedDeliveryConstraints(); ReceiveInfrastructure = TransportInfrastructure.ConfigureReceiveInfrastructure(); SendInfrastructure = TransportInfrastructure.ConfigureSendInfrastructure(); lazyDispatcher = new Lazy <IDispatchMessages>(() => SendInfrastructure.DispatcherFactory()); MessagePump = ReceiveInfrastructure.MessagePumpFactory(); var queueCreator = ReceiveInfrastructure.QueueCreatorFactory(); await queueCreator.CreateQueueIfNecessary(queueBindings, WindowsIdentity.GetCurrent().Name); var pushSettings = new PushSettings(InputQueueName, ErrorQueueName, configuration.PurgeInputQueueOnStartup, transactionMode); await MessagePump.Init( context => { if (context.Headers.ContainsKey(TestIdHeaderName) && context.Headers[TestIdHeaderName] == testId) { return(onMessage(context)); } return(Task.FromResult(0)); }, context => { if (context.Message.Headers.ContainsKey(TestIdHeaderName) && context.Message.Headers[TestIdHeaderName] == testId) { return(onError(context)); } return(Task.FromResult(ErrorHandleResult.Handled)); }, new FakeCriticalError(onCriticalError), pushSettings); MessagePump.Start(configuration.PushRuntimeSettings); }
static IManageSubscriptions CreateSubscriptionManager(TransportInfrastructure transportInfra) { var subscriptionInfra = transportInfra.ConfigureSubscriptionInfrastructure(); var factoryProperty = typeof(TransportSubscriptionInfrastructure).GetProperty("SubscriptionManagerFactory", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var factoryInstance = (Func <IManageSubscriptions>)factoryProperty.GetValue(subscriptionInfra, new object[0]); return(factoryInstance()); }
public ServerlessTransportInfrastructure(TransportInfrastructure baseTransportInfrastructure) { this.baseTransportInfrastructure = baseTransportInfrastructure; Dispatcher = baseTransportInfrastructure.Dispatcher; Receivers = baseTransportInfrastructure.Receivers.ToDictionary( r => r.Key, r => (IMessageReceiver) new PipelineInvoker(r.Value) ); }
public StartableRawEndpoint(SettingsHolder settings, TransportInfrastructure transportInfrastructure, RawCriticalError criticalError, IPushMessages messagePump, IDispatchMessages dispatcher, IManageSubscriptions subscriptionManager, Func <MessageContext, IDispatchMessages, Task> onMessage, string localAddress) { this.criticalError = criticalError; this.messagePump = messagePump; this.dispatcher = dispatcher; this.onMessage = onMessage; this.localAddress = localAddress; this.settings = settings; this.transportInfrastructure = transportInfrastructure; SubscriptionManager = subscriptionManager; }
IRouter CreateSubscribeRouter(TransportInfrastructure transportInfrastructure) { if (transportInfrastructure.OutboundRoutingPolicy.Publishes == OutboundRoutingType.Unicast) { return(new MessageDrivenSubscribeRouter(subscriptionStorage, endpointInstances)); } var subscriptionInfra = transportInfrastructure.ConfigureSubscriptionInfrastructure(); var factoryProperty = typeof(TransportSubscriptionInfrastructure).GetProperty("SubscriptionManagerFactory", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic); var factoryInstance = (Func <IManageSubscriptions>)factoryProperty.GetValue(subscriptionInfra, new object[0]); var subscriptionManager = factoryInstance(); return(new NativeSubscribeRouter(subscriptionStorage, subscriptionManager)); }
public StartableEndpoint(SettingsHolder settings, IBuilder builder, FeatureActivator featureActivator, PipelineConfiguration pipelineConfiguration, IEventAggregator eventAggregator, TransportInfrastructure transportInfrastructure, CriticalError criticalError) { this.criticalError = criticalError; this.settings = settings; this.builder = builder; this.featureActivator = featureActivator; this.pipelineConfiguration = pipelineConfiguration; this.eventAggregator = eventAggregator; this.transportInfrastructure = transportInfrastructure; pipelineCache = new PipelineCache(builder, settings); messageSession = new MessageSession(new RootContext(builder, pipelineCache, eventAggregator)); }
protected async Task StartPump(Func <MessageContext, Task> onMessage, Func <ErrorContext, Task <ErrorHandleResult> > onError, TransportTransactionMode transactionMode, Action <string, Exception> onCriticalError = null) { InputQueueName = GetTestName() + transactionMode; ErrorQueueName = $"{InputQueueName}.error"; var endpointConfiguration = new EndpointConfiguration(InputQueueName); endpointConfiguration.SendFailedMessagesTo(ErrorQueueName); transportSettings = endpointConfiguration.GetSettings(); var queueBindings = transportSettings.Get <QueueBindings>(); queueBindings.BindReceiving(InputQueueName); queueBindings.BindSending(ErrorQueueName); Configurer = CreateConfigurer(); var configuration = Configurer.Configure(transportSettings, transactionMode); TransportInfrastructure = configuration.TransportInfrastructure; IgnoreUnsupportedTransactionModes(transactionMode); IgnoreUnsupportedDeliveryConstraints(); ReceiveInfrastructure = TransportInfrastructure.ConfigureReceiveInfrastructure(); var queueCreator = ReceiveInfrastructure.QueueCreatorFactory(); var userName = GetUserName(); await queueCreator.CreateQueueIfNecessary(queueBindings, userName); var result = await ReceiveInfrastructure.PreStartupCheck(); if (result.Succeeded == false) { throw new Exception($"Pre start-up check failed: {result.ErrorMessage}"); } await TransportInfrastructure.Start(); SendInfrastructure = TransportInfrastructure.ConfigureSendInfrastructure(); lazyDispatcher = new Lazy <IDispatchMessages>(() => SendInfrastructure.DispatcherFactory()); MessagePump = ReceiveInfrastructure.MessagePumpFactory(); await MessagePump.Init( context => { if (context.Headers.ContainsKey(TestIdHeaderName) && context.Headers[TestIdHeaderName] == testId) { return(onMessage(context)); } return(Task.FromResult(0)); }, context => { if (context.Message.Headers.ContainsKey(TestIdHeaderName) && context.Message.Headers[TestIdHeaderName] == testId) { return(onError(context)); } return(Task.FromResult(ErrorHandleResult.Handled)); }, new FakeCriticalError(onCriticalError), new PushSettings(InputQueueName, ErrorQueueName, configuration.PurgeInputQueueOnStartup, transactionMode)); result = await SendInfrastructure.PreStartupCheck(); if (result.Succeeded == false) { throw new Exception($"Pre start-up check failed: {result.ErrorMessage}"); } MessagePump.Start(configuration.PushRuntimeSettings); }
public ServerlessTransportInfrastructure(TransportInfrastructure baseTransportInfrastructure, SettingsHolder settings) { this.baseTransportInfrastructure = baseTransportInfrastructure; this.settings = settings; }
public RunningRawEndpointInstance(SettingsHolder settings, RawTransportReceiver receiver, TransportInfrastructure transportInfrastructure, IDispatchMessages dispatcher, IManageSubscriptions subscriptionManager, string localAddress) { this.settings = settings; this.receiver = receiver; this.transportInfrastructure = transportInfrastructure; this.dispatcher = dispatcher; this.TransportAddress = localAddress; SubscriptionManager = subscriptionManager; }
public StoppableRawEndpoint(TransportInfrastructure transportInfrastructure, SettingsHolder settings) { this.transportInfrastructure = transportInfrastructure; this.settings = settings; }