2

I have a netstandard2.1 application and I am using nuget package "Microsoft.Azure.ServiceBus" Version="4.1.1".

I am creating a azure service bus SubscriptionClient and trying to use PeekBatch and ReceiveBatch, but I am getting below erros, What is missing here?

'SubscriptionClient' does not contain a definition for 'PeekBatch' and no accessible extension method 'PeekBatch' accepting a first argument of type 'SubscriptionClient' could be found

'SubscriptionClient' does not contain a definition for 'ReceiveBatch' and no accessible extension method 'PeekBatch' accepting a first argument of type 'SubscriptionClient' could be found

 _subscriptionClient = new SubscriptionClient(connectionString, topicName, subscriptionName, ReceiveMode.ReceiveAndDelete);
            
            _subscriptionClient.PrefetchCount = 16;

            while (_subscriptionClient.PeekBatch(16).Any())
            {
                var pendingMessages = _subscriptionClient.ReceiveBatch(16, TimeSpan.FromSeconds(1))?.ToList();
                if (pendingMessages != null)
                {
                    foreach (var message in pendingMessages)
                    {
                        // do processing of the message
                    }
                }
            }
user584018
  • 10,186
  • 15
  • 74
  • 160
  • U need to use `WindowsAzure.ServiceBus` package inorder to use `PeekBatch` and `ReceiveBatch` [SubscriptionClient.PeekBatch](https://learn.microsoft.com/en-us/dotnet/api/microsoft.servicebus.messaging.subscriptionclient.peekbatch?view=azure-dotnet) – Purushothaman Sep 12 '20 at 04:51
  • I am already using `Microsoft.Azure.ServiceBus`. Also when I am adding nuget `WindowsAzure.ServiceBus`, then I am getting error 'Package 'WindowsAzure.ServiceBus 6.0.2' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETStandard,Version=v2.1'. This package may not be fully compatible with your project.' – user584018 Sep 12 '20 at 05:07
  • This means `WindowsAzure.ServiceBus` is NOT compatible with `NETStandard,Version=v2.1`? – user584018 Sep 12 '20 at 05:08
  • 1
    `ReceiveBatch` is not supported by `Microsoft.Azure.ServiceBus`. Checked [this](https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-performance-improvements?tabs=net-standard-sdk#prefetching-and-receivebatch) Microsoft documentation. – user1672994 Sep 12 '20 at 06:37

1 Answers1

2

You can't use the batch methods and prefetching at the moment from .net standard or core.

Check the documentation here: https://learn.microsoft.com/en-us/azure/service-bus-messaging/service-bus-performance-improvements?tabs=net-standard-sdk#prefetching-and-receivebatch

Prefetching

This section only applies to the WindowsAzure.ServiceBus SDK, as the Microsoft.Azure.ServiceBus SDK does not expose batch functions.

Note that WindowsAzure here: https://www.nuget.org/packages/WindowsAzure.ServiceBus/

Please note that this package requires at least .Net Framework 4.6.2.

Is .net only and does not support net core or net standard

Athanasios Kataras
  • 25,191
  • 4
  • 32
  • 61