These are chat archives for petabridge/akka-bootcamp

9th
Feb 2016
nerubseran
@nerubseran
Feb 09 2016 15:58

Hi,
I have been experimenting with akka.persistence (v1.0.5.15) and i ran into an unexpected situation.
In the constructor of my persistent actor, i call a private method (named Working()) to set Command and Recover handlers. When an exception is thrown during writing new events to Journal, i am able to handle PersistenceFailure message. If I change the code in my constructor so that Become method, with "Working" method as parameter, is called instead of the "Working" method i am not able to handle PersistenceFailure message. There isn't any behavior change anywhere in code.

This one handles PersistenceFailure:

    class SampleActor : ReceivePersistentActor
    {
        public SampleActor()
        {
            Working();
        }

        private void Working()
        {   
               Command<string>(msg =>
                {
                    Persist<string>(msg, x =>
                    {
                        //do what you have to do
                    });
                });

               Command<PersistenceFailure>(failure =>
               {
                   //Code written here is run when an exception is thrown during writing new events to Journal
               });
        }
    }

This one does not handle PersistenceFailure:

    class SampleActor2 : ReceivePersistentActor
    {
        public SampleActor2()
        {
            Become(Working);
        }

        private void Working()
        {
            Command<string>(msg =>
            {
                Persist<string>(msg, x =>
                {
                    //do what you have to do
                });
            });

            Command<PersistenceFailure>(failure =>
            {
                //Code written here is NOT run when an exception is thrown during writing new events to Journal
            });
        }
    }

I know persistent actors doesn't preserve their behavior but the as far as i know actor is not restarted due to WriteMessagesFailed exception.
Is this behavior by design?
Thank you in advance for your time.

Bartosz Sypytkowski
@Horusiath
Feb 09 2016 17:54
@nerubseran 1) I'm not sure if Become is meant to be invoked from constructor. 2) This may be indeed sign of a bug.