scale-tone / nservicebus-azure-functions-demo

Demonstrates how to build and host NServiceBus-based services with Azure Functions and Azure Service Bus

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NServiceBus + Azure Functions + Azure Service Bus Demo

Demonstrates how to build and host NServiceBus-based services with Azure Functions and Azure Service Bus.

Official NServiceBus quick start solution migrated to Azure Functions with Azure Service Bus used as messaging transport.

graph LR

Browser[[Browser]] -.-> ClientUI

subgraph Azure Functions

ClientUI -- "#9889; PlaceOrder" --> Sales
Sales -- "#9889; OrderPlaced" --> Billing
Sales -- "#9889; OrderPlaced" --> Shipping

end

How to run

As a prerequisite, you will need Azure Functions Core Tools installed on your devbox.

  1. Create an Azure Service Bus Namespace with Standard or Premium pricing tier.

  2. Install the asb-transport CLI tool.

  3. Use that tool to pre-create required queues/topics:

set AzureServiceBus_ConnectionString=<my-service-bus-connection-string>
asb-transport endpoint create ClientUI
asb-transport endpoint create Sales
asb-transport endpoint create Billing
asb-transport endpoint create Shipping
  1. Create another queue named Wholesale manually, with message sessions enabled on it:

  1. Put your Azure Service Bus connection string into each project's local.settings.json file.

  2. Start each Function project by running func start in its folder.

  3. Navigate to http://localhost:7071 with your browser.

    The ClientUI project is an Azure Function, but it also serves static HTML files for the client-side React-based UI app, so there is no need to host them anywhere else.

Concepts demonstrated

  1. How to host NServiceBus endpoints as Azure Functions.

  2. How to enable and use cross-entity transactions.

    Sample code is here. To work correctly, it requires EnableCrossEntityTransactions set to true in host.json and SendsAtomicWithReceive set to true on NServiceBusTriggerFunction attribute.

  3. How to enable and use message sessions (aka ordered delivery).

    Sample code is here. To work correctly it requires message sessions be enabled on the destination queue.

    Also check out Jeff Hollan's very useful post about message sessions.

    Also check out why you don't actually need it ;).

  4. How to enable and use message deduplication.

    Sample code is here. To work correctly it requires the destination queue (called dedup) to be created with Enable duplicate detection flag set:

About

Demonstrates how to build and host NServiceBus-based services with Azure Functions and Azure Service Bus

License:MIT License


Languages

Language:C# 72.0%Language:TypeScript 11.3%Language:HTML 8.9%Language:JavaScript 6.9%Language:Dockerfile 0.9%