Nservice Bus with AzureStorageQueueTransport which hosted on azure webjob causing more containers creation and charging more price

Nservice Bus with AzureStorageQueueTransport which hosted on azure webjob causing more containers creation and charging more price. please check below details and help me to find out what could be causing.

Please check my web job code and i am attaching storage account screenshots

.

program.cs file

TelemetryConfiguration.Active.InstrumentationKey = ConfigurationManager.AppSettings[“APPINSIGHTS_INSTRUMENTATIONKEY”];
ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls12;
var config = new JobHostConfiguration();

if (config.IsDevelopment)
{
config.UseDevelopmentSettings();
}

config.DashboardConnectionString = null;

var host = new JobHost(config);
// The following code ensures that the WebJob will be running continuously
host.Call(typeof(Functions).GetMethod(“Host”));
host.RunAndBlock();

Functions.cs

public class Functions
{
private static readonly ILog Logger = LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

[NoAutomaticTrigger]
public static void Host(TextWriter log, CancellationToken cancellationToken)
{
	try
	{
			

		NServiceBus.Logging.LogManager.Use<Log4NetFactory>();


		var endpointConfiguration = new EndpointConfiguration("myendpoint");

		endpointConfiguration.UniquelyIdentifyRunningInstance().UsingNames("myendpoint", Environment.MachineName);
		endpointConfiguration.DisableFeature<AutoSubscribe>();
		endpointConfiguration.EnableInstallers();

		endpointConfiguration.DisableFeature<NServiceBus.Features.TimeoutManager>();
		endpointConfiguration.UseSerialization<XmlSerializer>();
		endpointConfiguration.PurgeOnStartup(false);
		endpointConfiguration.SendFailedMessagesTo("myendpointerror");
		endpointConfiguration.AuditProcessedMessagesTo("myendpointaudit");

		
		var transport = endpointConfiguration.UseTransport<AzureStorageQueueTransport>();
		
		var delayedDelivery = transport.DelayedDelivery();
		delayedDelivery.DisableTimeoutManager();
		delayedDelivery.DisableDelayedDelivery();

		var connection = ConfigurationManager.AppSettings["NServiceBus/AzureStorageQueue"];
		transport.ConnectionString(connection);
		transport.MessageInvisibleTime(TimeSpan.FromSeconds(90));

		
		var recoverability = endpointConfiguration.Recoverability();
		var nServiceBusMaxRetrys = Convert.ToInt32(ConfigurationManager.AppSettings["NServiceBusMaxRetrys"]);

		recoverability.Immediate(
			immediate =>
			{
				immediate.NumberOfRetries(0);
			}).Delayed(delayed=> delayed.NumberOfRetries(0));

		
		string route = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location);
		var routing = transport.Routing();

		
		endpointConfiguration.UsePersistence<NHibernatePersistence>();
		

		endpointConfiguration.DisableFeature<TimeoutManager>();

		Logger.Info("*****.Backend.***** Host Starting!");
		
		var endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

		Logger.Info("*****.Backend.***** Host Started!");
	}
	catch (Exception ex)
	{
		Logger.Info(ex.StackTrace);
		throw ex;
	}
}

}

Hi

Which version of the Azure Storage Queue transport are you using?

Also judging based on the code snippet you posted it looks like the method will immediately exit after

var endpointInstance = Endpoint.Start(endpointConfiguration).GetAwaiter().GetResult();

Endpoint.Start is not a blocking call and therefore your Host method will immediately exit after NServiceBus was started. Because you are using native delayed deliveries when the endpoint starts it will check the native delayed delivery infrastructure again which uses blobs/containers.

For long-running web jobs it is also required to set AlwaysOn=true. If that is not set even when you use RunAndBlock the web job will be canceled after some period of time and then restarted again which then causes NServiceBus to start again, do the blob/container checks and so on.

Have you seen our sample that shows how to host NServiceBus in WebJobs?

Regards
Daniel

Hi Danielmarbach,

Thanks for providing details,

Yes, Always on is enabled for the webjob / app service and we are using 8.2.2 version of Azure Storage queue.

Can you please provide sample in .Net But given sample in .Net core.
Thanks & Regards,
Jagadeesh Boddu.

Hi Jagadeesh

Is your webjob scaled out or a singleton?

I have checked the version you are on and based on my investigation we are only creating one container that is used for leases for delayed deliveries. Some background information how that works

https://docs.particular.net/transports/azure-storage-queues/delayed-delivery

If the table name is not specified it takes the SHA1 of the endpoint. Your endpoint name is myendpoint which should lead to something like

delays19857cb140b90b44cb91c85c9de1e6f14d1453bf

as a Table in Azure Storage and a corresponding lease container. The container creation is guarded and we should only attempt to create it a few times when the endpoint starts. Can you verify if the container creation attempts are coming from this endpoint or if another endpoint is doing that (maybe using the Azure Databus)?

If you don’t use delayed delivery but just sending commands and receiving commands you could also disable native delayed delivery entirely.

var transport = endpointConfiguration.UseTransport<AzureStorageQueueTransport>();
var delayedDelivery = transport.DelayedDelivery();
delayedDelivery.DisableDelayedDelivery();

https://docs.particular.net/transports/azure-storage-queues/delayed-delivery#how-it-works-disabling-delayed-delivery

Regarding the request for a sample. I digged the sample respository history and we only have a sample for .NET Core 2.2 and .NET Core 3.1 available.

Regards
Daniel