0
votes

I am using Azure App service plan to host web App which process Service Bus Topic message. I am using Azure Function App also which has http trigger to execute Event grid data. Both Web App(App Service Plan) and Function App(Elastic Premium plan) have staging slots in production.

At the time of swapping slot I observed stgaing slot for web app is processing message. Is this expected behaviour? For function app staging slot, I am not observing this behaviour. Why so ?

2
is your app service running a webjob to consume messages?Juanma Feliu
@Juanma Feliu - No, App Service is running as web app (REST API) not web job.Amit Agrawal
@Juanma Feliu - Sorrey, I am using IHostedService so it will run as web job in web appsAmit Agrawal
Updated my answer with code for webjobs. Wish it can help you adapting it to your own code.Juanma Feliu
Code is for webjobs not for IHostedService but it can give you an idea how to handle it.Juanma Feliu

2 Answers

1
votes

Please make sure you stop the slot, otherwise it will be in the running state (can receive message). If you don’t want it to receive information, you should stop it.

1
votes

Add an App Setting in each slot called "IsStaging" with true and false values then when app service warms up (Startup or method consuming messages) stop requests so messages are not consumed from the Staging slot.

                if (CurrentConfiguration.IsStaging)
                {
                   logger.LogWarn("Staging slot cannot consume messages");
                   return;
                }

UPDATE for WebJob:

        static void Main(string[] args)
        {
            JobHost host = CreateJobHost();
            if (CurrentConfiguration.IsStaging)
            {
                host.Call(typeof(Program).GetMethod("DoStagingInfiniteLoop"));
            }
            else
            {
                host.Call(typeof(Program).GetMethod("ProcessQueue"));
            }
        }


        private static JobHost CreateJobHost()
        {
            JobHostConfiguration jobHostConfig = new JobHostConfiguration();
            jobHostConfig.DashboardConnectionString = "DashboardCS";
            jobHostConfig.StorageConnectionString = "StorageCS";

            var JobHost = new JobHost(jobHostConfig);
            return JobHost;
        }


        [NoAutomaticTrigger]
        public static void DoStagingInfiniteLoop(TextWriter logger, CancellationToken token)
        {
            const int LOOP_TRACE_INTERVAL = 10000;
            ProcessLogger.WriteTrace("This is a staging environment, waiting...");
            while (true)
            {
                Task.Delay(LOOP_TRACE_INTERVAL).Wait(token);
            }
        }

        [NoAutomaticTrigger]
        public static void ProcessQueue(TextWriter logger, CancellationToken token)
        {
            //Your processing code here
        }