The syntax of Fog is pretty straight forward. The following examples use the course grained approach. To see how to use the fined-grained functions, which match almost one to one with the Azure SDK for .NET methods, see the Fog integration tests.
Blob Storage
With Fog all you have to do to interact with Azure blob storage is to add the connection string information in the config with a name of "BlobStorageConnectionString". Once that is done, you can use syntax like the following:
UploadBlob "testcontainer" "testblob" "This is a test" |> ignore DeleteBlob "testcontainer" "testblob"or
UploadBlob "testcontainer" "testblob" testBytes |> ignore DownloadBlob<byte[]> "testcontainer" "testblob"Table Storage
The simplest way to interact with Azure table storage is to add the connection string information in the config with a name of "TableStorageConnectionString". Once that is done, you can use syntax like the following:
[<DataServiceKey("PartitionKey", "RowKey")>] type TestClass() = let mutable partitionKey = "" let mutable rowKey = "" let mutable name = "" member x.PartitionKey with get() = partitionKey and set v = partitionKey <- v member x.RowKey with get() = rowKey and set v = rowKey <- v member x.Name with get() = name and set v = name <- v let originalClass = TestClass(PartitionKey = "tprt", RowKey = Guid.NewGuid().ToString(), Name = "test") CreateEntity "testtable" originalClass |> ignore let newClass = originalClass newClass.Name <- "test2" UpdateEntity "testtable" newClass |> ignore DeleteEntity "testtable" newClassQueue Storage
For queue storage, add the connection string configuration value with setting name "QueueStorageConnectionString".
AddMessage "testqueue" "This is a test message" |> ignore let result = GetMessages "testqueue" 20 5 for m in result do DeleteMessage "testqueue" mService Bus
There are a few service bus related config entries. Here's the list of expected names: ServiceBusIssuer, ServiceBusKey, ServiceBusScheme, ServiceBusNamespace, ServiceBusServicePath
To send a message do this:
type TestRecord = { Name : string } let testRecord = { Name = "test" } SendMessage "testQueue" testRecordTo receive a message, pass the queue name, a function to handle successful message retrieval, and another function to handle errors.
HandleMessages "testQueue" <| fun m -> printfn "%s" m.GetBody<TestRecord>().Name <| fun ex m -> raise exTo use topics in a pub/sub type of scenario, use something like the following to subscribe:
Subscribe "topictest2" "AllTopics4" <| fun m -> printfn "%s" m.GetBody<TestRecord>().Name <| fun ex m -> raise exMessage publishing can be accomplished like this:
Publish "topictest2" testRecordA few other handy functions include Unsubscribe and DeleteTopic:
Unsubscribe "topictest2" "AllTopics4" DeleteTopic "topictest2"How to get it
The easiest way to get Fog is to install the Fog NuGet package. You can also find the full source as well as integration tests on the Fog GitHub site.
No comments:
Post a Comment