Reputation: 4434
I'm using Microsoft Orleans for .net Core and I'm trying to receive ServiceBus messages and process them as fast as I can.
With parameter MaxConcurrentCalls set to 2 everything works fine. But with set 10 or 30 it throws an exception:
OrleansPrepareFailedException, Transaction 50038 aborted because Prepare phase did not succeed
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw() at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task) at MichalBialecki.com.OrleansCore.AccountTransfer.Client.Program.<>c__DisplayClass4_0.<b__0>d.MoveNext()
code looks like this:
subscriptionClient.RegisterMessageHandler(
async (message, token) =>
{
var messageJson = Encoding.UTF8.GetString(message.Body);
var updateMessage = JsonConvert.DeserializeObject<AccountTransferMessage>(messageJson);
await client.GetGrain<IAccountGrain>(updateMessage.From).Withdraw(updateMessage.Amount);
await client.GetGrain<IAccountGrain>(updateMessage.To).Deposit(updateMessage.Amount);
await subscriptionClient.CompleteAsync(message.SystemProperties.LockToken);
},
new MessageHandlerOptions(async args => Console.WriteLine(args.Exception + ", stack trace: " + args.Exception.StackTrace))
{ MaxConcurrentCalls = 30, AutoComplete = false });
My scenario is very simple. It handles account transfer messages and after updating account (Grain) balance, it sends message to a different ServiceBus topic. Currently on my local machine it can handel around 1500 messages per minute, but it feels kinda slow.
Upvotes: 2
Views: 923
Reputation: 4434
The problem was mishandling the state in a grain class. I used transactional state and persistent state at the same time, where I should have used only one. I managed to get my code running correctly for Orleans version 2.0 and .Net Core application.
Here is my code: https://github.com/mikuam/orleans-core-example And here is my blog post about adding persistent storage to Microsoft Orleans in .Net Core: http://www.michalbialecki.com/2018/04/03/add-cosmosdb-persistent-storage-to-microsoft-orleans-in-net-core/
Upvotes: 2