void TrySpecifyDefaultLicense() { var licenseText = Environment.GetEnvironmentVariable("NSERVICEBUS_LICENSE"); if (!string.IsNullOrWhiteSpace(licenseText)) { EndpointConfiguration.License(licenseText); } }
/// <summary> /// Allows user to specify the path for the license file. /// </summary> /// <param name="config">The <see cref="EndpointConfiguration" /> instance to apply the settings to.</param> /// <param name="licenseFile">A relative or absolute path to the license file.</param> public static void LicensePath(this EndpointConfiguration config, string licenseFile) { Guard.AgainstNull(nameof(config), config); Guard.AgainstNullAndEmpty(nameof(licenseFile), licenseFile); if (!File.Exists(licenseFile)) { throw new FileNotFoundException("License file not found", licenseFile); } var licenseText = NonLockingFileReader.ReadAllTextWithoutLocking(licenseFile); config.License(licenseText); }
/// <summary> /// Creates a serverless NServiceBus endpoint. /// </summary> internal ServiceBusTriggeredEndpointConfiguration(string endpointName, IConfiguration configuration, string connectionString = default) { var endpointConfiguration = new EndpointConfiguration(endpointName); var recoverability = endpointConfiguration.Recoverability(); recoverability.Immediate(settings => settings.NumberOfRetries(5)); recoverability.Delayed(settings => settings.NumberOfRetries(3)); recoverabilityPolicy.SendFailedMessagesToErrorQueue = true; recoverability.CustomPolicy(recoverabilityPolicy.Invoke); endpointConfiguration.CustomDiagnosticsWriter(customDiagnosticsWriter); // 'WEBSITE_SITE_NAME' represents an Azure Function App and the environment variable is set when hosting the function in Azure. var functionAppName = GetConfiguredValueOrFallback(configuration, "WEBSITE_SITE_NAME", true) ?? Environment.MachineName; endpointConfiguration.UniquelyIdentifyRunningInstance() .UsingCustomDisplayName(functionAppName) .UsingCustomIdentifier(DeterministicGuid.Create(functionAppName)); var licenseText = GetConfiguredValueOrFallback(configuration, "NSERVICEBUS_LICENSE", optional: true); if (!string.IsNullOrWhiteSpace(licenseText)) { endpointConfiguration.License(licenseText); } if (connectionString == null) { connectionString = GetConfiguredValueOrFallback(configuration, DefaultServiceBusConnectionName, optional: true); if (string.IsNullOrWhiteSpace(connectionString)) { throw new Exception($@"Azure Service Bus connection string has not been configured. Specify a connection string through IConfiguration, an environment variable named {DefaultServiceBusConnectionName} or passing it to `UseNServiceBus(ENDPOINTNAME,CONNECTIONSTRING)`"); } } Transport = new AzureServiceBusTransport(connectionString); serverlessTransport = new ServerlessTransport(Transport); var serverlessRouting = endpointConfiguration.UseTransport(serverlessTransport); Routing = new RoutingSettings <AzureServiceBusTransport>(serverlessRouting.GetSettings()); endpointConfiguration.UseSerialization <NewtonsoftSerializer>(); AdvancedConfiguration = endpointConfiguration; }
/// <summary> /// Creates a serverless NServiceBus endpoint running within an AzureStorageQueue trigger. /// </summary> public StorageQueueTriggeredEndpointConfiguration(string endpointName, string connectionStringName = null) { EndpointConfiguration = new EndpointConfiguration(endpointName); EndpointConfiguration.Recoverability().Delayed(c => c.NumberOfRetries(0)); recoverabilityPolicy.SendFailedMessagesToErrorQueue = true; EndpointConfiguration.Recoverability().CustomPolicy(recoverabilityPolicy.Invoke); // Disable diagnostics by default as it will fail to create the diagnostics file in the default path. // Can be overriden by ServerlessEndpointConfiguration.LogDiagnostics(). EndpointConfiguration.CustomDiagnosticsWriter(_ => Task.CompletedTask); // 'WEBSITE_SITE_NAME' represents an Azure Function App and the environment variable is set when hosting the function in Azure. var functionAppName = Environment.GetEnvironmentVariable("WEBSITE_SITE_NAME") ?? Environment.MachineName; EndpointConfiguration.UniquelyIdentifyRunningInstance() .UsingCustomDisplayName(functionAppName) .UsingCustomIdentifier(DeterministicGuid.Create(functionAppName)); // Look for license as an environment variable var licenseText = Environment.GetEnvironmentVariable("NSERVICEBUS_LICENSE"); if (!string.IsNullOrWhiteSpace(licenseText)) { EndpointConfiguration.License(licenseText); } Transport = UseTransport <AzureStorageQueueTransport>(); var connectionString = Environment.GetEnvironmentVariable(connectionStringName ?? DefaultStorageConnectionString); Transport.ConnectionString(connectionString); var recoverability = AdvancedConfiguration.Recoverability(); recoverability.Immediate(settings => settings.NumberOfRetries(4)); recoverability.Delayed(settings => settings.NumberOfRetries(0)); Transport.DelayedDelivery().DisableTimeoutManager(); EndpointConfiguration.UseSerialization <NewtonsoftSerializer>(); }