我正在使用Azure Service Bus SDK(.NET标准版)从队列接收消息并将它们导入到SQL数据库。 我使用ForEachAsync方法来提高吞吐量。
var receiver = new MessageReceiver(serviceBusConnectionString, queueName);
while (true)
{
var messages = await receiver.ReceiveAsync(100);
if (messages != null)
{
await ForEachAsync(messages, 10, async message =>
{
var success = await ProcessMessageAsync(message);
if (success)
await receiver.CompleteAsync(message.SystemProperties.LockToken);
else
await receiver.DeadLetterAsync(message.SystemProperties.LockToken);
});
}
};
在Azure指标中,我看到的传出消息多于传入消息,这意味着此代码多次收到同一条消息。
怎么了?