コード例 #1
0
        public static TransportExtensions <AzureServiceBusTransport> UseTransport <TTransport>(this EndpointConfiguration endpointConfiguration)
            where TTransport : AzureServiceBusTransport
        {
            var transport = new AzureServiceBusTransport();

            var routing = endpointConfiguration.UseTransport(transport);

            return(new TransportExtensions <AzureServiceBusTransport>(transport, routing));
        }
コード例 #2
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;
        }