A simple ASP.NET web application that demonstrates how to send messages to an NServiceBus endpoint using the ClearHostedEndpoint library.
This web app provides a user interface and API endpoints to place orders, which are sent as NServiceBus commands to the OrderProcessing endpoint. It demonstrates:
- Configuring NServiceBus in an ASP.NET application
- Using Learning Transport for local development
- Sending commands to a separate worker endpoint
- Routing configuration
- .NET 10.0 SDK
- The
NServiceBusEndpointworker running (to process the messages)
In one terminal, start the order processing endpoint:
cd examples/NServiceBusEndpoint
dotnet runYou should see output indicating the endpoint is running:
Starting NServiceBus endpoint: OrderProcessing
NServiceBus endpoint started successfully: OrderProcessing
In another terminal, start the web application:
cd examples/NServiceBusWebApp
dotnet runThe web app will start on http://localhost:5000 (or similar).
- Open your browser to
http://localhost:5000 - Fill in the order form
- Click "Place Order"
- Check the NServiceBusEndpoint console for message processing output
# Place an order via GET request
curl http://localhost:5000/api/orders??????????????????????? ???????????????????????????
? NServiceBusWebApp ? ? OrderProcessingEndpoint ?
? (ASP.NET) ? ? (Worker Service) ?
??????????????????????? ???????????????????????????
? ? ? ?
? POST /orders ???????> ? PlaceOrderHandler ?
? GET /api/orders ? (msg) ? ?
? ? ? Publishes OrderPlaced ?
??????????????????????? ???????????????????????????
? ?
???????????????????????????????????
?
Learning Transport
(File-based queue)
%TEMP%\NServiceBusEndpointExample
Both the web app and the worker endpoint use the same Learning Transport storage directory, enabling message exchange:
var learningTransportDirectory = Path.Combine(
Path.GetTempPath(),
"NServiceBusEndpointExample",
".learningtransport");| Method | Path | Description |
|---|---|---|
| GET | / |
HTML form to place orders |
| POST | /orders |
Submit order from form |
| GET | /api/orders |
Place a test order via API |
?? Important: The Learning Transport is for development and testing only. For production, use a real transport like:
- Azure Service Bus
- RabbitMQ
- Amazon SQS
- SQL Transport
- Ensure both applications are running
- Verify they're using the same transport directory
- Check the temp directory for
.learningtransportfolder
Change the port in Program.cs or use:
dotnet run --urls "http://localhost:5001"- NServiceBusEndpoint - The worker endpoint that processes messages