我正在尝试向 Eventhub 发送通知,以前我使用的是https://www.nuget.org/packages/Microsoft.Azure.EventHubs/包,现在我正在使用https://www.nuget.org /packages/Azure.Messaging.EventHubs。这是我正在使用的代码。它工作正常,但我不知道如何在发送消息时传递分区键eventData.PartitionKey = partitionKey; 属性是只读属性。
var producerClient = new EventHubProducerClient(connectionString, eventHubName);
using EventDataBatch eventBatch = await producerClient.CreateBatchAsync();
var eventData = new EventData(Encoding.UTF8.GetBytes(message));
eventData.PartitionKey = partitionKey;
if (!eventBatch.TryAdd(eventData))
throw new Exception($"batch size is large and cannot be sent");
await producerClient.SendAsync(eventBatch);
await producerClient.DisposeAsync();