We have in our Azure Service Fabric cluster an actor called SmsActorService that haves a method that allow us to get the next SMS.
Send SMS to actor
Get SMS from actor
Even if we know that we already created the actor with the given ID and we have our state saved, when we access it, surprise, the state is not set. It's like we just created our actor for the first time.
After a few minutes of debugging, we identify the problem. When we send the SMS to our actor, we specify the Actor ID as a string (PhoneNumber). When we want to access the actor in the second call, we specify the Actor ID as int.
This is enough for Azure Service Fabric to create two different instances of actors. One that has ID 1000 (long) and another one that has ID '1000' (as string).
The problem can be solved easily by converting both ID to the same time. I recommend to use only string because is more safe for long time and you will never ask yourself if others used long, string or GUID.
The actor works great, when we want to send an SMS to our actor works great, but when we want to get a SMS, surprise, we have null reference exception when we want to access the actor state.
Send SMS to actor
IAct0r mobileDevice = ActorProxy.Create<IAct0r>(
new ActorId(smsToSent.Value.PhoneNumber),
new Uri("fabric:/ITCamp.SF/Act0rActorService"));
await mobileDevice.ReceiveSmsAsync(smsToSent.Value);
Get SMS from actor
int id = 1000;
IAct0r mobileDevice = ActorProxy.Create<IAct0r>(
new ActorId(id),
new Uri("fabric:/ITCamp.SF/Act0rActorService"));
Sms sms = mobileDevice.GetNextSms().Result;
Even if we know that we already created the actor with the given ID and we have our state saved, when we access it, surprise, the state is not set. It's like we just created our actor for the first time.
After a few minutes of debugging, we identify the problem. When we send the SMS to our actor, we specify the Actor ID as a string (PhoneNumber). When we want to access the actor in the second call, we specify the Actor ID as int.
This is enough for Azure Service Fabric to create two different instances of actors. One that has ID 1000 (long) and another one that has ID '1000' (as string).
The problem can be solved easily by converting both ID to the same time. I recommend to use only string because is more safe for long time and you will never ask yourself if others used long, string or GUID.
int id = 1000;
IAct0r mobileDevice = ActorProxy.Create<IAct0r>(
new ActorId(id.ToString()),
new Uri("fabric:/ITCamp.SF/Act0rActorService"));
Sms sms = mobileDevice.GetNextSms().Result;
Ahhh ! Been struggling with this for an hour, thanks !!!
ReplyDelete