Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Integration with web apps #167

Open
DejanMilicic opened this issue Jun 1, 2023 · 1 comment
Open

Integration with web apps #167

DejanMilicic opened this issue Jun 1, 2023 · 1 comment

Comments

@DejanMilicic
Copy link

I am in the early learning phase, and I am attempting to produce minimal working example of small counter app, which is integrating Akka.net, Akkling and Falco

open Falco
open Falco.Routing
open Falco.HostBuilder
open Akkling
open Akka.Actor
open Akka

let system: ActorSystem = System.create "basic-sys" <| Configuration.defaultConfig()

type Message = 
    | IncreaseCounter
    | GetCounter

let greeter (m:Actor<Message>) =
    let rec loop state = actor {
        let! msg = m.Receive ()
        match msg with
        | IncreaseCounter -> return! loop (state + 1)
        | GetCounter -> m.Sender() <! state.ToString()

        return! loop state
    }
    loop 0

let greeterRef = spawnAnonymous system (props greeter)

webHost [||] {
    endpoints [
        get "/counter" (
            let counter = greeterRef <? GetCounter |> Async.RunSynchronously
            Response.ofPlainText counter
        )

        put "/counter" (
            greeterRef <! IncreaseCounter
            Response.ofEmpty
        )
    ]
}

I am experiencing the "get counter" always returning 0.
It is almost like the actor gets re-created repeatedly instead of sleeping and awaiting a message.

When I take this very same code outside of Falco and go with something like this

let greeterRef = spawnAnonymous system (props greeter)
greeterRef <! IncreaseCounter
let counter = greeterRef <? GetCounter |> Async.RunSynchronously

it works as expected.
So it is clear that the integration part is wrong.

Apologies for creating this as an issue - if we had Discussions here I would post it there.
Thanx!

@kerams
Copy link

kerams commented Jun 23, 2023

Without knowing Falco, it would seem to me you're partially applying the GET handler, so the counter value 0 is embedded in it. Similarly, the counter is increased once during startup, not on every PUT.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants