public override void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings) { var transport = endpointConfig.UseTransport <LearningTransport>(); transport.StorageDirectory(transportSettings.ConnectionString); transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }
static void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings, TransportTransactionMode transportTransactionMode) { var transport = endpointConfig.UseTransport <LearningTransport>(); transport.StorageDirectory(Environment.ExpandEnvironmentVariables(transportSettings.ConnectionString)); transport.Transactions(transportTransactionMode); }
public override void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings) { var transport = endpointConfig.UseTransport <SqlServerTransport>(); ConfigureConnection(transport, transportSettings); transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }
static TransportExtensions <MsmqTransport> CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings, TransportTransactionMode transportTransactionMode) { var transport = endpointConfig.UseTransport <MsmqTransport>(); transport.Transactions(transportTransactionMode); return(transport); }
public RawEndpointConfiguration CreateFailedAuditsSender(string name) { var config = RawEndpointConfiguration.CreateSendOnly(name); transportCustomization.CustomizeRawSendOnlyEndpoint(config, transportSettings); return(config); }
static async Task <IRawEndpointInstance> StartMonitor() { var queueMonitorContext = new DefaultMetricsContext("QueueLengthMonitor"); new MetricsConfig(queueMonitorContext) .WithHttpEndpoint("http://localhost:7777/QueueLengthMonitor/") .WithReporting(r => { r.WithReport( new PerformanceCounterReporter(x => new CounterInstanceName("Queue Length", x.MetricName)), TimeSpan.FromSeconds(5), Filter.New.WhereContext(c => c == "QueueLengthMonitor" || c == "QueueState")); }); var monitor = new Monitor(queueMonitorContext, new QueueLength()); var config = RawEndpointConfiguration.Create("QueueLengthMonitor", monitor.OnMessage); config.LimitMessageProcessingConcurrencyTo(1); config.UseTransport <MsmqTransport>(); //config.UseTransport<RabbitMQTransport>().ConnectionString("host=localhost"); config.SendFailedMessagesTo("error"); var endpoint = await RawEndpoint.Start(config); return(endpoint); }
internal static async Task <(IReceivingRawEndpoint, StateStore)> SetupEndpoint(Action <Guid, Message, Message[]> messageProcessed) { var storageTable = await PrepareStorageTable(); var stateStore = new StateStore(storageTable); var handlerInvoker = new HandlerInvoker(stateStore); var endpointConfiguration = RawEndpointConfiguration.Create( endpointName: EndpointName, onMessage: async(c, d) => { var message = Serializer.Deserialize(c.Body, c.Headers); var outputMessages = await handlerInvoker.Process(message); var runId = Guid.Parse(c.Headers["Message.RunId"]); messageProcessed(runId, message, outputMessages); await d.Send(outputMessages, runId); }, poisonMessageQueue: "error"); endpointConfiguration.UseTransport <LearningTransport>() .Transactions(TransportTransactionMode.ReceiveOnly); var defaultFactory = LogManager.Use <DefaultFactory>(); defaultFactory.Level(LogLevel.Debug); var endpoint = await RawEndpoint.Start(endpointConfiguration); return(endpoint, stateStore); }
static void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings) { var transport = endpointConfig.UseTransport <AzureStorageQueueTransport>(); transport.ApplyHacksForNsbRaw(); ConfigureTransport(transport, transportSettings); }
public Bridge(string leftName, string rightName, bool autoCreateQueues, string autoCreateQueuesIdentity, EndpointInstances endpointInstances, ISubscriptionStorage subscriptionStorage, IDistributionPolicy distributionPolicy, string poisonQueue, Action <TransportExtensions <TLeft> > leftCustomization, Action <TransportExtensions <TRight> > rightCustomization, int?maximumConcurrency) { this.endpointInstances = endpointInstances; this.subscriptionStorage = subscriptionStorage; publishRouter = new PublishRouter(subscriptionStorage, distributionPolicy); sendRouter = new SendRouter(endpointInstances, distributionPolicy); replyRouter = new ReplyRouter(); leftConfig = RawEndpointConfiguration.Create(leftName, (context, _) => Forward(context, rightStartable, rightSubscribeRouter), poisonQueue); var leftTransport = leftConfig.UseTransport <TLeft>(); leftTransport.GetSettings().Set("errorQueue", poisonQueue); leftCustomization?.Invoke(leftTransport); if (autoCreateQueues) { leftConfig.AutoCreateQueue(autoCreateQueuesIdentity); } rightConfig = RawEndpointConfiguration.Create(rightName, (context, _) => Forward(context, leftStartable, leftSubscribeRouter), poisonQueue); var rightTransport = rightConfig.UseTransport <TRight>(); rightTransport.GetSettings().Set("errorQueue", poisonQueue); rightCustomization?.Invoke(rightTransport); if (autoCreateQueues) { rightConfig.AutoCreateQueue(autoCreateQueuesIdentity); } if (maximumConcurrency.HasValue) { leftConfig.LimitMessageProcessingConcurrencyTo(1); rightConfig.LimitMessageProcessingConcurrencyTo(1); } }
static async Task Main() { Console.Title = "Case00041163.OccasionalSubscriber"; var endpointConfiguration = RawEndpointConfiguration.Create(Console.Title, (context, messages) => Task.CompletedTask, "error"); endpointConfiguration.UseTransport <MsmqTransport>(); var endpointInstance = await RawEndpoint.Start(endpointConfiguration) .ConfigureAwait(false); var subscriptionMessage = ControlMessageFactory.Create(MessageIntentEnum.Subscribe); subscriptionMessage.Headers[Headers.SubscriptionMessageType] = typeof(MyEvent).AssemblyQualifiedName; subscriptionMessage.Headers[Headers.ReplyToAddress] = "Case00041163.OccasionalSubscriber@FAKEPC"; subscriptionMessage.Headers[Headers.SubscriberTransportAddress] = "Case00041163.OccasionalSubscriber@FAKEPC"; subscriptionMessage.Headers[Headers.SubscriberEndpoint] = "Case00041163.OccasionalSubscriber"; subscriptionMessage.Headers[Headers.TimeSent] = DateTimeExtensions.ToWireFormattedString(DateTime.UtcNow); subscriptionMessage.Headers[Headers.NServiceBusVersion] = "5.6.4"; var operation = new TransportOperation(subscriptionMessage, new UnicastAddressTag("Case00041163.Publisher")); await endpointInstance.Dispatch(new TransportOperations(operation), new TransportTransaction(), new ContextBag()).ConfigureAwait(false); await endpointInstance.Stop().ConfigureAwait(false); }
public Runner(RawEndpointConfiguration config, string name, bool sendOnly, Func <IRawEndpoint, Task> onStarting, Func <IRawEndpoint, Task> onStarted) { this.config = config; this.sendOnly = sendOnly; this.onStarting = onStarting; Name = name; this.onStarted = onStarted; }
public override void CustomizeForReturnToSenderIngestion(RawEndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = endpointConfiguration.UseTransport <AzureServiceBusTransport>(); CustomizeEndpoint(transport, transportSettings); transport.ConfigureTransport(transportSettings, TransportTransactionMode.SendsAtomicWithReceive); }
public override void CustomizeForAuditIngestion(RawEndpointConfiguration endpointConfiguration, TransportSettings transportSettings) { var transport = endpointConfiguration.UseTransport <AzureServiceBusTransport>(); CustomizeEndpoint(transport, transportSettings); transport.ConfigureTransport(transportSettings, TransportTransactionMode.ReceiveOnly); }
RawEndpointConfiguration PrepareConfig(string inputQueue, string poisonMessageQueueName, Action <TransportExtensions <T> > transportCustomization, Func <MessageContext, IDispatchMessages, Task> onMessage, PoisonMessageHandling poisonMessageHandling, int?maximumConcurrency, int immediateRetries, int delayedRetries, int circuitBreakerThreshold, bool autoCreateQueue, string autoCreateQueueIdentity) { var circuitBreaker = new RepeatedFailuresCircuitBreaker(inputQueue, circuitBreakerThreshold, e => { logger.Error($"Persistent error while processing messages in {inputQueue}. Entering throttled mode.", e); Task.Run(async() => { await transitionSemaphore.WaitAsync().ConfigureAwait(false); try { var oldEndpoint = endpoint; var throttledConfig = PrepareThrottledConfig(inputQueue, poisonMessageQueueName, transportCustomization, onMessage, poisonMessageHandling, maximumConcurrency, immediateRetries, circuitBreakerThreshold, delayedRetries); var newEndpoint = await RawEndpoint.Start(throttledConfig).ConfigureAwait(false); endpoint = newEndpoint; await oldEndpoint.Stop().ConfigureAwait(false); } catch (Exception ex) { logger.Error("Error when entering throttled mode", ex); } finally { transitionSemaphore.Release(); } }); }); var regularConfig = RawEndpointConfiguration.Create(inputQueue, async(context, dispatcher) => { await onMessage(context, dispatcher).ConfigureAwait(false); circuitBreaker.Success(); }, poisonMessageQueueName); regularConfig.CustomErrorHandlingPolicy(new RegularModePolicy(inputQueue, circuitBreaker, poisonMessageHandling, immediateRetries, delayedRetries)); Task onCriticalError(ICriticalErrorContext context) { logger.Fatal($"The receiver for queue {inputQueue} has encountered a severe error that is likely related to the connectivity with the broker or the broker itself."); return(Task.CompletedTask); } regularConfig.Settings.Set("onCriticalErrorAction", (Func <ICriticalErrorContext, Task>)onCriticalError); var transport = regularConfig.UseTransport <T>(); transportCustomization(transport); if (autoCreateQueue) { regularConfig.AutoCreateQueue(autoCreateQueueIdentity); } if (maximumConcurrency.HasValue) { regularConfig.LimitMessageProcessingConcurrencyTo(maximumConcurrency.Value); } return(regularConfig); }
public RawEndpointConfiguration CreateRawEndpointConfiguration(string name, Func <MessageContext, IDispatchMessages, Task> onMessage, TransportDefinition transportDefinition) { var config = RawEndpointConfiguration.Create(name, onMessage, $"{transportSettings.EndpointName}.Errors"); config.LimitMessageProcessingConcurrencyTo(settings.MaximumConcurrencyLevel); transportCustomization.CustomizeRawEndpoint(config, transportSettings); return(config); }
public override void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings) { var transport = endpointConfig.UseTransport <AzureServiceBusTransport>(); transport.UseEndpointOrientedTopology(); transport.ApplyHacksForNsbRaw(); transport.ConfigureTransport(transportSettings); }
public static void UseLicense(this RawEndpointConfiguration config, string licenseText) { if (string.IsNullOrWhiteSpace(licenseText)) { throw new ArgumentException("NServiceBus license text must not be null or white space", nameof(licenseText)); } config.Settings.Set("LicenseText", licenseText); }
public override void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings) { var transport = endpointConfig.UseTransport <AzureServiceBusTransport>(); transport.ApplyHacksForNsbRaw(); transport.UseForwardingTopology(); transport.Sanitization().UseStrategy <ValidateAndHashIfNeeded>(); transport.ConfigureTransport(transportSettings); }
static void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings, TransportTransactionMode transactionMode) { #pragma warning disable 618 var transport = endpointConfig.UseTransport <AzureServiceBusTransport>(); #pragma warning restore 618 transport.UseEndpointOrientedTopology(); transport.ApplyHacksForNsbRaw(); transport.ConfigureTransport(transportSettings, transactionMode); }
/// <summary> /// Starts the endpoint. /// </summary> public async Task Start() { var outConfig = RawEndpointConfiguration.Create(storageQueueName, OnOutgoingMessage, poisonMessageQueue); outConfig.LimitMessageProcessingConcurrencyTo(1); transportCustomization(outConfig.UseTransport <T>()); outConfig.CustomErrorHandlingPolicy(new RetryForeverPolicy()); outConfig.AutoCreateQueue(); outEndpoint = await RawEndpoint.Start(outConfig).ConfigureAwait(false); }
void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings, TransportTransactionMode transactionMode) { #pragma warning disable 618 var transport = endpointConfig.UseTransport <AzureServiceBusTransport>(); #pragma warning restore 618 transport.ApplyHacksForNsbRaw(); transport.UseForwardingTopology(); transport.Sanitization().UseStrategy <ValidateAndHashIfNeeded>(); transport.ConfigureTransport(transportSettings, transactionMode); }
static async Task Main(string[] args) { var senderConfig = RawEndpointConfiguration.Create("DummyHandler", OnMessage, "error"); var transport = senderConfig.UseTransport <AzureServiceBusTransport>(); transport.ConnectionString(Environment.GetEnvironmentVariable("AzureServiceBus_ConnectionString")); senderConfig.LimitMessageProcessingConcurrencyTo(10); var sender = await RawEndpoint.Start(senderConfig).ConfigureAwait(false); Console.ReadLine(); }
public override async Task Start(CancellationToken token) { var config = RawEndpointConfiguration.Create("poison", OnMessage, "poison"); config.AutoCreateQueue(); config.CustomErrorHandlingPolicy(new IgnoreErrorsPolicy()); var transport = config.UseTransport <TestTransport>(); transportConfiguration(transport); endpoint = await RawEndpoint.Start(config); }
RawEndpointConfiguration PrepareThrottledConfig(string inputQueue, string poisonMessageQueueName, Action <TransportExtensions <T> > transportCustomization, Func <MessageContext, IDispatchMessages, Task> onMessage, PoisonMessageHandling poisonMessageHandling, int?maximumConcurrency, int immediateRetries, int delayedRetries, int circuitBreakerThreshold) { var switchedBack = false; var throttledConfig = RawEndpointConfiguration.Create(inputQueue, async(context, dispatcher) => { await onMessage(context, dispatcher); if (switchedBack) { return; } await transitionSemaphore.WaitAsync().ConfigureAwait(false); Task.Run(async() => { logger.Info("Exiting throttled mode."); try { var oldEndpoint = endpoint; var regularConfig = PrepareConfig(inputQueue, poisonMessageQueueName, transportCustomization, onMessage, poisonMessageHandling, maximumConcurrency, immediateRetries, delayedRetries, circuitBreakerThreshold, false, null); var newEndpoint = await RawEndpoint.Start(regularConfig).ConfigureAwait(false); endpoint = newEndpoint; await oldEndpoint.Stop().ConfigureAwait(false); } catch (Exception e) { logger.Error("Error when exiting throttled mode", e); } finally { transitionSemaphore.Release(); } }).Ignore(); switchedBack = true; }, poisonMessageQueueName); throttledConfig.CustomErrorHandlingPolicy(new ThrottledModePolicy(inputQueue, immediateRetries)); Task onCriticalError(ICriticalErrorContext context) { logger.Fatal($"The receiver for queue {inputQueue} has encountered a severe error that is likely related to the connectivity with the broker or the broker itself."); return(Task.CompletedTask); } throttledConfig.Settings.Set("onCriticalErrorAction", (Func <ICriticalErrorContext, Task>)onCriticalError); var transport = throttledConfig.UseTransport <T>(); transportCustomization(transport); throttledConfig.LimitMessageProcessingConcurrencyTo(1); return(throttledConfig); }
RawEndpointConfiguration CreateEndpointConfig(KeyValuePair <string, QueueInfo> queueInfo, Task <bool> barrier, string errorQueue) { var config = RawEndpointConfiguration.Create(queueInfo.Value.QueueTable, (context, dispatcher) => OnMessage(context, dispatcher, barrier, queueInfo.Value.Catalogs), errorQueue); var transport = config.UseTransport <SqlServerTransport>() .ConnectionString(queueInfo.Value.ConnectionString) .DefaultSchema(queueInfo.Value.Schema); transport.GetSettings().Set <EndpointInstances>(new EndpointInstances()); config.AutoCreateQueue(); config.DefaultErrorHandlingPolicy(errorQueue, 5); return(config); }
public static async Task InitServerEndpoint(string endpointName) { if (serverEndpoint == null) { var senderConfig = RawEndpointConfiguration.Create( endpointName: endpointName, onMessage: OnMessage, poisonMessageQueue: "error"); senderConfig.UseTransport <MsmqTransport>(); serverEndpoint = await RawEndpoint.Start(senderConfig) .ConfigureAwait(false); } }
public async static Task InitSubTwoEndpoint(string endpointName, Func <MessageContext, IDispatchMessages, Task> func) { if (subscriber2Endpoint == null) { var senderConfig = RawEndpointConfiguration.Create( endpointName: endpointName, onMessage: func, poisonMessageQueue: "error"); senderConfig.UseTransport <MsmqTransport>(); senderConfig.AutoCreateQueue(); subscriber2Endpoint = await RawEndpoint.Start(senderConfig) .ConfigureAwait(false); } }
public Task <ComponentRunner> CreateRunner(RunDescriptor run) { var typedScenarioContext = (TContext)run.ScenarioContext; var sendOnly = onMessage == null; var config = sendOnly ? RawEndpointConfiguration.CreateSendOnly(name) : RawEndpointConfiguration.Create(name, (c, d) => onMessage(c, typedScenarioContext, d), "poison"); config.AutoCreateQueue(); configure(config); return(Task.FromResult <ComponentRunner>(new Runner(config, name, sendOnly, endpoint => onStarting != null ? onStarting(endpoint, typedScenarioContext) : Task.FromResult(0), endpoint => onStarted != null ? onStarted(endpoint, typedScenarioContext) : Task.FromResult(0)))); }
public override void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings) { var transport = endpointConfig.UseTransport <SqlServerTransport>(); ConfigureConnection(transport, transportSettings); endpointConfig.Settings.Set("SqlServer.DisableDelayedDelivery", true); var sendOnlyEndpoint = transport.GetSettings().GetOrDefault <bool>("Endpoint.SendOnly"); if (!sendOnlyEndpoint) { transport.NativeDelayedDelivery().DisableTimeoutManagerCompatibility(); } transport.Transactions(TransportTransactionMode.SendsAtomicWithReceive); }
static void CustomizeRawEndpoint(RawEndpointConfiguration endpointConfig, TransportSettings transportSettings, TransportTransactionMode transportTransactionMode) { var transport = endpointConfig.UseTransport <SqlServerTransport>(); ConfigureConnection(transport, transportSettings); endpointConfig.Settings.Set("SqlServer.DisableDelayedDelivery", true); var sendOnlyEndpoint = transport.GetSettings().GetOrDefault <bool>("Endpoint.SendOnly"); if (!sendOnlyEndpoint) { transport.NativeDelayedDelivery(); } transport.Transactions(transportTransactionMode); }