Create() public static method

public static Create ( ) : System.Guid
return System.Guid
Example #1
0
        /// <summary>
        /// In this mode, a host id will be generated from <paramref name="instanceName" /> and <paramref name="hostName" />.
        /// </summary>
        /// <remarks>
        /// This mode is recommended when deploying in Azure roles or <see cref="UsingInstalledFilePath" /> is not appropriate.
        /// </remarks>
        public HostInfoSettings UsingNames(string instanceName, string hostName)
        {
            Guard.AgainstNullAndEmpty(nameof(instanceName), instanceName);
            Guard.AgainstNullAndEmpty(nameof(hostName), hostName);

            config.Settings.Get <HostingComponent.Settings>().HostId = DeterministicGuid.Create(instanceName, hostName);
            return(this);
        }
Example #2
0
        /// <summary>
        /// In this mode, a host id will be generated from <paramref name="instanceName" /> and <paramref name="hostName" />.
        /// </summary>
        /// <remarks>
        /// This mode is recommended when deploying in Azure roles or <see cref="UsingInstalledFilePath" /> is not appropriate.
        /// </remarks>
        public HostInfoSettings UsingNames(string instanceName, string hostName)
        {
            Guard.AgainstNullAndEmpty(nameof(instanceName), instanceName);
            Guard.AgainstNullAndEmpty(nameof(hostName), hostName);

            config.Settings.Set(HostInformationFeature.HostIdSettingsKey, DeterministicGuid.Create(instanceName, hostName));
            return(this);
        }
Example #3
0
            internal void ApplyHostIdDefaultIfNeededForV7BackwardsCompatibility()
            {
                if (settings.HasExplicitValue(HostIdSettingsKey))
                {
                    return;
                }

                settings.SetDefault(HostIdSettingsKey, DeterministicGuid.Create(fullPathToStartingExe, RuntimeEnvironment.MachineName));
            }
Example #4
0
        /// <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;
        }
Example #5
0
        /// <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>();
        }
Example #6
0
 /// <summary>
 /// In this mode, a host id will be generated from <paramref name="instanceName"/> and <paramref name="hostName"/>.
 /// </summary>
 /// <remarks>
 /// This mode is recommended when deploying in Azure roles or <see cref="UsingInstalledFilePath"/> is not appropriate.
 /// </remarks>
 public HostInfoSettings UsingNames(string instanceName, string hostName)
 {
     config.Settings.Set("NServiceBus.HostInformation.HostId", DeterministicGuid.Create(instanceName, hostName));
     return(this);
 }
 public static Guid Generate(Type sagaEntityType, string correlationPropertyName, object correlationPropertyValue)
 {
     // assumes single correlated sagas since v6 doesn't allow more than one corr prop
     // will still have to use a GUID since moving to a string id will have to wait since its a breaking change
     return(DeterministicGuid.Create($"{sagaEntityType}_{correlationPropertyName}_{correlationPropertyValue}"));
 }