Created
September 30, 2024 10:19
-
-
Save jkone27/6ea625869fb0e1ebec6c0485b031311d to your computer and use it in GitHub Desktop.
Orleans F# fsx test (not working atm)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment