New Azure WebJob Project - JobHostConfiguration/Ru

2020-06-14 03:29发布

问题:

Easy Replication

  1. Create a new project 'ASP.NET Web Application (.NET Framework).
  2. Build compile, update NuGet, all works.
  3. Add: Add New Azure WebJob Project.
  4. Build, compile. Happy
  5. Update NuGet for the WebJob project.
  6. Project no longer compiles.

Breaking changes were introduced https://github.com/Azure/app-service-announcements/issues/129

So I install

Microsoft.Azure.WebJobs.Extensions.Storage

This resolves QueueTriggerAttribute

But in program.cs

    static void Main()
    {
        var config = new JobHostConfiguration();

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

        var host = new JobHost(config);
        host.RunAndBlock();
    }

I am encountering the following problems:

  1. JobHostConfiguration is now missing.
  2. JobHost constructor now has two parameters, including a new IJobHostContextFactory?
  3. RunAndBlock is missing. It is now 'StartAsync'
  4. The code now needs to become asynchronous since there are no synchronous calls to the job.

Questions:

  1. What additioanl assemblies need to be installed?
  2. What is this new JobHostContextFactory?
  3. How do I configure the job now?
  4. How should I update the code for asynchronous?
  5. How do I block for a continuous job now that all we have is Start?

Thanks in advance!

  • C#
  • .Net Framework 4.6.2
  • Visual Studio 2017 - v15.8.7

回答1:

The 3.0.0 NuGet package update (non-beta) brought breaking changes. It's based on the generic host which is similar to the asp.net host. Here's an example of the new setup

Here you can find a GitHub discussion related to that topic.