Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Created June 7, 2015 11:58
Show Gist options
  • Save isaacabraham/48c29056bfe1c03ee303 to your computer and use it in GitHub Desktop.
Save isaacabraham/48c29056bfe1c03ee303 to your computer and use it in GitHub Desktop.
CloudAgent sample client / server
module Client
open System
open FSharp.CloudAgent
open FSharp.CloudAgent.Messaging
open FSharp.CloudAgent.Connections
open Server
let CreateActor actor =
MailboxProcessor.Start(fun mailbox ->
let print msg = printfn "[%O] %A: %s" DateTime.UtcNow actor msg
let rec loop() =
async {
let! message, reply = mailbox.Receive()
match message.Name with
| "Foo" ->
print "HELLO!"
reply Completed
| "Bar" | "Fravel" ->
print "GOODBYE!!"
reply Failed
| _ ->
print (sprintf "Who are you: %A " message)
reply Abandoned
return! loop()
}
loop())
[<EntryPoint>]
let main argv =
let listener = ConnectionFactory.StartListening(SampleConnection, CreateActor >> ResilientCloudAgent)
printfn "Connected to actor cloud. Press any key to quit."
Console.ReadKey() |> ignore
listener.Dispose()
1
module Server
open System
open FSharp.CloudAgent
open FSharp.CloudAgent.Connections
open FSharp.CloudAgent.Messaging
/// A simple DTO
type Person = { Name : string; Age : int }
/// Connection string to service bus
let SampleConnection = CloudConnection.WorkerCloudConnection(ServiceBusConnection "serviceBusConnection", Queue "workerqueue")
[<EntryPoint>]
let main argv =
/// Just partially apply the SendToWorkerPool message with the sample connection
let sendMessage = ConnectionFactory.SendToWorkerPool SampleConnection
while true do
printf "Please enter Name: "
let name = Console.ReadLine()
printf "Please enter Age: "
let age = Console.ReadLine() |> int
sendMessage { Name = name; Age = age } |> Async.RunSynchronously
Console.Clear()
0 // return an integer exit code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment