-
|
tried this part of code, some of it works, but not sure why i cannot see the actors talking to each others... #r "nuget: Microsoft.Orleans.Server"
#r "nuget: Microsoft.Extensions.Logging.Console"
#r "nuget: IcedTasks"
open System
open Orleans.Runtime
open Microsoft.Extensions.Hosting
open Orleans.Hosting
open Microsoft.Extensions.Logging
open Microsoft.Extensions.DependencyInjection
open System.Threading.Tasks
open Orleans
open System.Threading.Tasks
open IcedTasks
module Grains =
type IHello =
abstract member SayHello : string -> string ValueTask
inherit IGrainWithIntegerKey
type HelloGrain(logger: ILogger<HelloGrain>) =
inherit Grain()
interface IHello with
member this.SayHello(greeting: string) =
valueTask {
$"""SayHello message received: greeting = "{greeting}" """
|> logger.LogInformation
return $"""Client said: "{greeting}", so HelloGrain says: Hello!"""
}
module App =
let builder =
Host.CreateDefaultBuilder([| |])
.UseOrleans(fun silo ->
silo.UseLocalhostClustering()
.ConfigureLogging(fun logging ->
logging.AddConsole() |> ignore)
|> ignore
)
.UseConsoleLifetime()
let host = builder.Build()
let run (host: IHost) =
valueTask {
do! host.StartAsync()
let grainFactory = host.Services.GetRequiredService<IGrainFactory>()
let friend = grainFactory.GetGrain<Grains.IHello>(0)
let! result = friend.SayHello("Good morning!")
Console.WriteLine($"\n\n{result}\n\n")
Console.WriteLine("Orleans is running.\nPress Enter to terminate...")
Console.ReadLine() |> ignore
Console.WriteLine("Orleans is stopping...")
return! host.StopAsync()
}
[<assembly: GenerateCodeForDeclaringAssembly(typeof<Grains.HelloGrain>)>]
App.host |> App.run |> Async.AwaitValueTask |> Async.RunSynchronously |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
i think i understand orleans relies on C# and source generators to generate grains code, can we make it work with some other mechanism for F# like myriad or type providers? |
Beta Was this translation helpful? Give feedback.
-
|
BTW i think F# has great opportunities for actor frameworks like orleans, so it would be great if they woudl work great together, after all, actors are from Erlang/BEAM so it makes sense to have it work great in F# other than just C# right? maybe a working F# API and documentation should be provided to make it easy to work with Orleans and F#? https://fsharpforfunandprofit.com/posts/concurrency-actor-model/ as for sure Erlang/Gleam / BEAM stack people would prefer samples in F# code rather than C# code Erlang/Gleam and F# share quite some synthax similarities and also the |
Beta Was this translation helpful? Give feedback.
I was looking into this package Microsoft.Orleans.Serialization.FSharp, trying to translate the quickstart tutorial (url shortener) to F#.
But, for some reason, the controller is not being able to retrieve the
IUrlShortenerGrain. I'll make this code public later today and update this comment to link it.Update: After some research, it's not currently possible. I found some valuable information at this issue.