I'm using a custom implementation of IMessageSessionAsyncHandler
in order to read from a partitioned service bus queue. The number of partitions is rather large and so is the volume of messages written in the queue. The MaxConcurrentSessions
is set to default.
I'm trying to maximize the number of processed messages assuming a uniform distribution of messages over the partitions. The MessageWaitTimeout
is set to 1 second in order to avoid losing time when there is no new message on the partition.
Now what I'd like to do is to force the closing of the session when a certain number of messages were processed so that another session reader gets the chance to process its messages (in the OnMessageAsync
method). Before closing the session, I need to simulate the completion of all messages in the session that were read but not completed yet (Autocomplete
set to true). In other words, simulate the action of the Autocomplete
trigger. Do you know if there's any way to do it?
If I set Autocomplete
to false and complete each message by hand, the performance falls to an unacceptable level (the batched messages completed at once really improve the volume of reading).
public async Task OnMessageAsync(MessageSession session, BrokeredMessage message)
{
try
{
_callback(message);
if (++_processedMessages >= n)
{
//simulate the action of Autocomplete for the batched msg
await OnCloseSessionAsync(session);
}
}
catch (Exception ex)
{
Logger.Error(ex, "Error handling brokered message");
}
}