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
As a prerequisite, you will need Azure Functions Core Tools installed on your devbox.
-
Create an Azure Service Bus Namespace with Standard or Premium pricing tier.
-
Install the asb-transport CLI tool.
-
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
- Create another queue named
Wholesale
manually, with message sessions enabled on it:
-
Put your Azure Service Bus connection string into each project's
local.settings.json
file. -
Start each Function project by running
func start
in its folder. -
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.
-
How to enable and use cross-entity transactions.
Sample code is here. To work correctly, it requires
EnableCrossEntityTransactions
set totrue
inhost.json
andSendsAtomicWithReceive
set totrue
onNServiceBusTriggerFunction
attribute. -
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 ;).
-
How to enable and use message deduplication.
Sample code is here. To work correctly it requires the destination queue (called
dedup
) to be created withEnable duplicate detection
flag set: