1
votes

I've got a very simple implementation using Akka.NET remoting.

Specifically I have two actors:

public class ClientQueryActor : ReceiveActor
{
    public ClientQueryActor(ActorSelection stockBarcodeActor)
    {
        this._stockBarcodeActor = stockBarcodeActor ?? throw new ArgumentNullException("stockBarcodeActor must be provided.");

        this.Receive<GetStockBarcodeByBarcodeRequest>(this.HandleStockBarcodeByBarcodeRequestReceived);
        this.Receive<GetStockBarcodeByBarcodeResponse>(this.HandleStockBarcodeByBarcodeResponseReceived);
    }

    private void HandleStockBarcodeByBarcodeRequestReceived(GetStockBarcodeByBarcodeRequest obj)
    {
        this._stockBarcodeActor.Tell(obj);
    }

    private void HandleStockBarcodeByBarcodeResponseReceived(GetStockBarcodeByBarcodeResponse obj)
    {

    }
}


public class StockBarcodeQueryActor : ReceiveActor
{

    public StockBarcodeQueryActor()
    {    
        this.Receive<GetStockBarcodeByBarcodeRequest>(this.HandleStockBarcodeByBarcodeRequestReceived);
    }

    private void HandleStockBarcodeByBarcodeRequestReceived(GetStockBarcodeByBarcodeRequest obj)
    {
        this.Sender.Tell(new GetStockBarcodeByBarcodeResponse(true, null, null));
    }
}

For the most part these actors seem to be working properly the issue is in the messages I am sending.

My message class looks roughly like this:

public class GetStockBarcodeByBarcodeResponse 
{
    public GetStockBarcodeByBarcodeResponse(bool success) { }

    public GetStockBarcodeByBarcodeResponse(bool success, IEnumerable<string> errors) { } 
}

However when I attempt to send a message using this class I get the error

'Association with remote system akka.tcp://client@localhost:2552 has failed; address is now gated for 5000 ms. Reason is: [Akka.Remote.EndpointDisassociatedException: Disassociated'

When I remove the multiple constructors the message sends successfully.

I have been unable to find anything in the documentation referencing this problem, can someone please explain this limitation to me?

Could anyone provide any suggested workarounds?

1
Wild guess: Serializers? If there's any serialization/deserialization going on, it wouldn't know how to access your constructor. - Josh
@Josh Thanks Josh, you're right, no doubt this is a problem with serialization but I guess I was hoping for some sugggestions on how you might be able to get around this problem. I've updated my question to be more clear. - Maxim Gershkovich
Which constructor the serializer should use, then creating an instance ? Most often you need a parameterless constructor. By removing your 2 constructors, actually you add an auto-generated parameterless constructor. Instead of removing your two constructors, you can also add a third (parameterless) constructor. - Holger
Try adding a default constructor to GetStockBarcodeByBarcodeResponse with other constructors. Serializers expects a default constructor. - vendettamit
Akka.NET by default uses JSON.NET so all of it's limitations apply here. See: stackoverflow.com/questions/24678734/… - Bartosz Sypytkowski

1 Answers

1
votes

Bartosz's comment is the correct answer - we use JSON.NET serialization by default for user-defined messages and in order for deserialization to work you need to mark one of the constructors using the JsonConstructor attribute: Unable to deserialize classes with multiple constructors with Json.NET