0

Background
Notification service has a Notify method which is invoked when an event occurs, so here Im creating the FloorActor and sending the message consisting data and post url to the Actor.

public class NotificationService
    {
        //HttpClient client = new HttpClient();
        ActorSystem notificationSystem = ActorSystem.Create("NotificationSystem");

        public void Notify(int clientID, FloorEventData data)
        {
            try
            {
                string postUrl = "http://localhost:6001";
                FloorData floorData = new FloorData() { Data = data,PostURL=postUrl };

//This commented line of code post data and listener gets the POST request
//client.PostAsJsonAsync<FloorEventData>(postUrl, data); 
                //Create Floor Actor
                var floorActor = notificationSystem.ActorOf<FloorActor>("floorActor");
                floorActor.Tell(data);
            }
            catch (Exception exception)
            {
                //Log exception
            }
        }
}

ReceiveAsync method of the Floor Actor data just posts the event data to the specified URL.Framework used to implement Actor Model :Akka.Net

     public class FloorActor : ReceiveActor 
    {
        HttpClient client = new HttpClient();

        public FloorActor()
        {
            ReceiveAsync<FloorData>(floorActor => client.PostAsJsonAsync<FloorEventData>(floorActor.PostURL, floorActor.Data));
        }
    }

Issue- When I debugged the issue the code flow works as expected:- 1) When event occurs Notify method is invoked 2) Notify method creates the Floor Actor and sends the data 3) Floor Actor's ReceiveAsync method is called and the line of code is executed without any errors or exceptions.But the POST listener, doesn't get the POST data request, so not sure what is happening ?

Tried POST data directly from the Notify method its works, the listener gets the POST request.You can see this code snippet commented above in the Notify method.

So when I try to POST data from my Actor's Receive method, the Http listener does not get the request and there is no errors or exception. Please let me know if I have to change anything?

Bopanna
  • 37
  • 1
  • 7

1 Answers1

0

ActorSystem should be treated as a singleton for your entire system. So put that instance in a static somewhere and reference it from there.

Also try to await on client.PostAsJsonAsync

Danthar
  • 1,068
  • 7
  • 13