This sample implements a fictional store that can be deployed to Azure. It is different from most samples in that it shows many features of NServiceBus working together.
- Start the Azure Storage Emulator. Ensure latest version is installed.
- Run the solution. 4 console windows start and one web-site opens.
- Order products from the website. Once orders are submitted, there is a window of time allocated for handling cancellations due to buyer's remorse. Once the order has been accepted, they are provisioned and made available for download. If the order is cancelled before the buyer's remorse timeout, nothing is provisioned for download.
Users can order products from the website. Once orders are submitted, there is a window of time allocated for handling cancellations due to buyer's remorse. Once the order has been accepted, they are provisioned and made available for download.
The web application hosts the ECommerce endpoint. When a user presses the Place Order button on the website, the ECommerce endpoint sends a
SubmitOrder command to the Sales endpoint. Upon receiving a
SubmitOrder command the Sales endpoint will immediately publish an
OrderPlaced event and request to be called back in 20 seconds (
BuyersRemorseIsOver). If the user does not cancel their order before the end of the buyers remorse period then the Sales endpoint will publish an
The ECommerce endpoint is subscribed to the
OrderAccepted events in order to update the web page. It does this by forwarding events to the client using SignalR.
If the user presses the Cancel button before the buyers remorse period ends then the ECommerce endpoint sends a
CancelOrder command to the Sales endpoint which publishes an
OrderCancelled event instead of an
OrderAccepted event. The ECommerce endpoint subscribes to
OrderCancelled and updates the UI via SignalR to mark the order as cancelled.
Once an order is accepted, it can be provisioned. The ContentManagement endpoint subscribes to the
OrderAccepted event and sends a
ProvisionDownloadRequest message to the Operations endpoint. When Operations handles
ProvisionDownloadRequest it sends back a
ProvisionDownloadResponse message. When the response is received by ContentManagement it publishes a
DownloadIsReady event. The ECommerce endpoint subscribes to
DownloadIsReady to update the UI via SignalR.
The CustomerRelations endpoint is subscribed to
OrderAccepted events. When a customer order is accepted, the CustomerRelations endpoint publishes a
ClientBecamePreferred event. This event only has one subscriber, CustomerRelations itself, which will use send the customer a welcome pack and a limited time offer when a customer becomes preferred.
In implementing the above workflow various aspects are highlighted:
All endpoints in the solution communicate using the Azure Storage Queues transport. The sample has been configured to use the Azure Storage Emulator.
The endpoints in the solution persist data using the Azure Storage persistence. This persistence is used to store subscription, timeout, and saga data.
ProcessOrderSagaavoids this issue by combining a collection of
ProductIdsinto a single string for persistence.
Ecommerce project is configured to deploy as an Azure Web Site. The
Sales endpoints are all configured to run as Azure Web Jobs. The sample has been configured to run on the Azure Storage Emulator.
Illustrates the use of the Saga pattern to handle the buyer's remorse scenario.
The request/response pattern is illustrated for the product provisioning between the ContentManagement endpoint and the Operations Endpoint.
The ECommerce endpoint is implemented as an ASP.NET application which uses SignalR to show feedback to the user.
The use of message headers and message mutator is also illustrated when the user clicks on the Check box on the ECommerce web page, which conveniently stops at the predefined breakpoints in the message handler code on the endpoints.
The use of encryption is illustrated by passing in the Credit Card number and the Expiration date from the ECommerce web site. The UnobtrusiveConventions defined in the ECommerce endpoint show how to treat certain properties as encrypted. Both the ECommerce and the Sales endpoint is setup for RijndaelEncryption and the encryption key is provided in the config file. If the messages are inspected in the queue, both the Credit Card number and the Expiration Date will show the encrypted values.
This sample has been designed to run in a development environment under the Azure Storage Emulator. In order to deploy the sample to the cloud the following should be considered:
- Application setting with the key
AzureWebJobsEnvmust be set to a value other than
- An Azure Storage account must be created.
- By default, each endpoint is using the development storage. Application setting with the key
NServiceBus.ConnectionStringmust be defined and its value set to the Storage Account connection string configured in step 1.
- In order to support the elastic scale capabilities of the Azure platform, a SignalR backplane must be added to the