SimpleMessageStream not re-activating grains between single silo restarts
I'm trying to setup a dev environment that uses offline providers to help with local testing of 2.0-beta1. Im using SMS stream provider and the sample json file provider for grain state. The streams are working as expected for implicit as well as explicit subscriptions that are created in an active activation. However, when I kill the silo and start it up again I'm unable to get a grain with an explicit subscription to activate when a message is sent on the stream. Is it possible to use the SMS provider to activate a grain when the only silo is completely restarted? I tried to use the json file provider as the PubSubStore but when i try and send a message after the silo is restarted I get this a NullReferenceException exception:
at Orleans.Providers.Streams.SimpleMessageStream.SimpleMessageStreamProducerExtension.StreamConsumerExtensionCollection.<DeliverToRemote>d__7.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Orleans.Providers.Streams.SimpleMessageStream.SimpleMessageStreamProducer`1.<OnNextAsync>d__21.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Zapic.Service.Grains.EventGrain.<SendEventMessage>d__5.MoveNext()
Update 1:
After doing some more research it appears the problem is due to the fact that I was saving the subscriptions in my grain state and it was unable to deserialize the subscription handle since StreamSubscriptionHandleImpl does not have a default constructor.
Exc level 0: Newtonsoft.Json.JsonSerializationException: Unable to find a constructor to use for type Orleans.Streams.StreamSubscriptionHandleImpl`1[Zapic.Service.Interfaces.Models.EventMessage]. A class should either have a default constructor, one constructor with arguments or a constructor marked with the JsonConstructor attribute. Path 'Subscriptions.dfc431f6-717d-49ad-b4f5-49d21adc8835.ProviderName', line 1, position 1396.
Update 2:
Looks like there is a discussion related to my issues #1777. Is it still best practice to use GetAllSubscriptionHandles instead of directly storing the subscription?
Yes it is still best practice to use GetAllSubscriptionHandles instead of directly storing subscription.
After playing around with it more, it looks like you need to use the Json.NET serializer settings provided in OrleansJsonSerializer. This will ensure all the internal orleans classes are serialized and deserialized properly. We use the sample file storage provider for local dev so I updated the sample to use the proper serializer settings. After using the new serializer and switching to GetAllSubscriptionHandles it seems to be working.