Ayush Mishra
Ayush Mishra

Reputation: 21

Issue during Upgrade of Azure functions to .NET 8 and isolated workers

Hi I upgrading my workers to dotnet 8 and isolated worker. I have removed the Microsoft.Azure.Webjobs.Extensions.ServiceBus dependency as suggested in document https://learn.microsoft.com/en-us/azure/azure-functions/migrate-dotnet-to-isolated-model?tabs=net8#programcs-file.

But now I am getting error in Program.cs file for line:

services.Configure<ServiceBusOptions>(options =>
{
    options.AutoCompleteMessages = false;
});

with ServiceBusOptions that it cannot be found. What can I do here?

here is my hostbuilder function,

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services => {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
        services.Configure<ServiceBusOptions>(options =>
        {
            options.AutoCompleteMessages = false;
        });
    })
    .Build();

host.Run();

I am not sure what to do, since I am new to .NET and Azure, any help would be appreciated.

Upvotes: 0

Views: 1535

Answers (2)

Thomas
Thomas

Reputation: 732

The new package for .Net 8 is Microsoft.Azure.Functions.Worker.Extensions.ServiceBus, found here.

Upvotes: 0

Pravallika KV
Pravallika KV

Reputation: 8734

Thanks for the article @Andrew B.

I got the same error when I tried to implement the same in my environment.

The type or namespace name 'ServiceBusOptions' could not be found (are you missing a using directive or an assembly reference?).

Refer the MSDOC for the example code.

To set AutoCompleteMessages= false, add the attribute in the function code as shown below:

[Function(nameof(Function1))]
public async Task Run(
    [ServiceBusTrigger("myqueue", Connection = "demo", AutoCompleteMessages = false)]
    ServiceBusReceivedMessage message,
    ServiceBusMessageActions messageActions)
{
    _logger.LogInformation("Message ID: {id}", message.MessageId);
    _logger.LogInformation("Message Body: {body}", message.Body);
    _logger.LogInformation("Message Content-Type: {contentType}", message.ContentType);

    // Complete the message
    await messageActions.CompleteMessageAsync(message);
}

Program.cs:

var host = new HostBuilder()
    .ConfigureFunctionsWebApplication()
    .ConfigureServices(services =>
    {
        services.AddApplicationInsightsTelemetryWorkerService();
        services.ConfigureFunctionsApplicationInsights();
    })
    .Build();

host.Run();

Sending message:

enter image description here

Console Response:

enter image description here

Upvotes: 0

Related Questions