DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports Events Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones AWS Cloud
by AWS Developer Relations
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Partner Zones
AWS Cloud
by AWS Developer Relations
The Latest "Software Integration: The Intersection of APIs, Microservices, and Cloud-Based Systems" Trend Report
Get the report
  1. DZone
  2. Data Engineering
  3. Databases
  4. Introducing Fog: A Library for Interacting with Azure from F#

Introducing Fog: A Library for Interacting with Azure from F#

Daniel Mohl user avatar by
Daniel Mohl
·
May. 13, 12 · Interview
Like (0)
Save
Tweet
Share
4.01K Views

Join the DZone community and get the full member experience.

Join For Free
Fog is a library that makes it easier to use F# to interact with Windows Azure through the Windows Azure SDK for .NET. It provides functions for many of the common activities related to table storage, blob storage, and queue storage as well as service bus queues and topics. Provided functions include both course and fined-grained approaches that remove boiler plate code and make it easier to use various functional patterns and techniques. The course grained functions currently use config settings with specific names to allow most operations to only require a single function call.

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" newClass 
Queue 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" m 
Service 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" testRecord 
To 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 ex 
To 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 ex 
Message publishing can be accomplished like this:
Publish "topictest2" testRecord 
A 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.
azure Database Library

Opinions expressed by DZone contributors are their own.

Popular on DZone

  • OpenVPN With Radius and Multi-Factor Authentication
  • Demystifying the Infrastructure as Code Landscape
  • Building a REST API With AWS Gateway and Python
  • Integrate AWS Secrets Manager in Spring Boot Application

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 600 Park Offices Drive
  • Suite 300
  • Durham, NC 27709
  • support@dzone.com
  • +1 (919) 678-0300

Let's be friends: