Create Azure Service Bus Topic Programmatically

Here’s a test:CreateTopic

Here’s a module:

namespace OrderRequest.DataGateway

open Microsoft.Azure.ServiceBus.Management

module AzureTopic =

    let existsAsync(topicName:string) (connectionstring:string) =

        async {

            let     client = ManagementClient(connectionstring)
            return! client.TopicExistsAsync(topicName) |> Async.AwaitTask
        }

    let createAsync(topicName:string) (connectionstring:string) =

        async {

            let  client = ManagementClient(connectionstring)
            let! found  = client.TopicExistsAsync(topicName) |> Async.AwaitTask

            if not found then

                let description = TopicDescription(topicName, EnablePartitioning= true)
                do! client.CreateTopicAsync(description) |> Async.AwaitTask |> Async.Ignore
        }

    let deleteAsync(topicName:string) (connectionstring:string) =

        async {

            let  client = ManagementClient(connectionstring)
            let! found  = client.TopicExistsAsync(topicName) |> Async.AwaitTask

            if found then

                do! client.DeleteTopicAsync(topicName) |> Async.AwaitTask
        }

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s