Skip to content

Instantly share code, notes, and snippets.

@isaacabraham
Last active August 29, 2015 14:10
Show Gist options
  • Save isaacabraham/5ad0f5ff34fd09dc1138 to your computer and use it in GitHub Desktop.
Save isaacabraham/5ad0f5ff34fd09dc1138 to your computer and use it in GitHub Desktop.
How to bind a Mailbox Processor to CloudAgent
// A connection to a Azure Service Bus-backed CloudAgent actor pool
let cloudConnection = CloudConnection.ActorCloudConnection(ServiceBusConnection "Endpoint=sb://myservicebus.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=fsdoifsm0983m29048098dfs", Connections.Queue "myqueue")
(* Posting messages - run this code on every producer *)
let sendTo = ConnectionFactory.SendToActorPool CloudConnection
let sendToIsaac = sendTo (ActorKey "isaac")
sendToIsaac Clear |> Async.RunSynchronously // send a message to Clear the file to the Isaac actor
sendToIsaac(Record { Text = "Hello"; Priority = Priority.Low }) |> Async.RunSynchronously // Send a new message to Isaac
(* Consuming messages - run this code on every consumer *)
open FSharp.CloudAgent
open FSharp.CloudAgent.Messaging
// Start listening! CloudAgent will start listening to Service Bus for messages and create Mailbox Processors as required.
let disposable = ConnectionFactory.StartListening(cloudConnection, CreateActor >> BasicCloudAgent)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment