|
| 1 | +--- |
| 2 | +title: ServiceControl recoverability for MassTransit |
| 3 | +summary: Sample presenting a system that uses MassTransit together with the Particular Service Platform |
| 4 | +reviewed: 2024-09-04 |
| 5 | +component: ServiceControl |
| 6 | +--- |
| 7 | + |
| 8 | +This sample shows the usage of the Particular Service Platform with an existing MassTransit system. |
| 9 | + |
| 10 | +>[!NOTE] |
| 11 | +>This sample uses RabbitMQ as the messaging infrastructure. Refer to [the setup documentation](/servicecontrol/masstransit/#settings) for Amazon SQS and Azure Service Bus setup instructions. |
| 12 | +
|
| 13 | +## Download the sample |
| 14 | + |
| 15 | +The sample doesn't require a message queue or database to install - only a compatible IDE. To get started: |
| 16 | + |
| 17 | +downloadbutton |
| 18 | + |
| 19 | +## Run the sample |
| 20 | + |
| 21 | +Running the sample requires two steps: |
| 22 | + |
| 23 | +1. Execute `docker compose up -d` in the root directory of the sample to start the RabbitMQ broker |
| 24 | +2. Open the `MassTransitShowcaseDemo.sln` solution and start `ClientUI`, `Billing`, `Sales`, and `Shipping` projects. |
| 25 | + |
| 26 | +## Walkthrough |
| 27 | + |
| 28 | +The sample consists of 4 console applications hosting MassTransit message producers and consumers that implement a simplified order processing logic from an e-commerce system. |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | +`ClientUI` application generates `PlaceOder` messages at continuous rate that trigger follow-up message flow in the other parts of the system. |
| 33 | + |
| 34 | +### Experiencing failures |
| 35 | + |
| 36 | +All consumers provide ability to change message processing failure rate by pressing <kbd>I</kbd> to increase and <kbd>D</kbd> to decrease it. Each consumer application shows a list of available commands and a summary of currently used configuration values. |
| 37 | + |
| 38 | +The initial value for the failure rate for each each endpoint is `0`, except for the `Billing` for which the value is `50`%: |
| 39 | + |
| 40 | +```code |
| 41 | +Billing Endpoint |
| 42 | +Press I to increase the simulated failure rate |
| 43 | +Press D to decrease the simulated failure rate |
| 44 | +Press R to reset simulation |
| 45 | +Press CTRL+C to quit |
| 46 | +
|
| 47 | +Failure rate: 50% |
| 48 | +``` |
| 49 | + |
| 50 | +Whenever the `Billing` consumer fails to process a message, a log entry gets printed to the command line window, and the message is moved to the `BillOrder_error` queue. |
| 51 | + |
| 52 | +```code |
| 53 | +fail: MassTransit.ReceiveTransport[0] |
| 54 | + R-FAULT rabbitmq://localhost/BillOrder b4950300-b188-ac74-36f6-08dcf7ec3b26 Messages.OrderPlaced Billing.BillOrderConsumer(00:00:00.2819272) |
| 55 | + System.Exception: BOOM. A failure occurred |
| 56 | + at Billing.SimulationEffects.SimulatedMessageProcessing(CancellationToken cancellationToken) in C:\git\p\docs-mt-fork\strategy-527.docs.particular.net\samples\servicecontrol\masstransit-recoverability\ServiceControl_5\Billing\SimulationEffects.cs:line 17 |
| 57 | + at Billing.BillOrderConsumer.Consume(ConsumeContext`1 context) in C:\git\p\docs-mt-fork\strategy-527.docs.particular.net\samples\servicecontrol\masstransit-recoverability\ServiceControl_5\Billing\Consumers\BillOrderConsumer.cs:line 12 |
| 58 | + at MassTransit.DependencyInjection.ScopeConsumerFactory`1.Send[TMessage](ConsumeContext`1 context, IPipe`1 next) in /_/src/MassTransit/DependencyInjection/DependencyInjection/ScopeConsumerFactory.cs:line 22 |
| 59 | + at MassTransit.DependencyInjection.ScopeConsumerFactory`1.Send[TMessage](ConsumeContext`1 context, IPipe`1 next) in /_/src/MassTransit/DependencyInjection/DependencyInjection/ScopeConsumerFactory.cs:line 22 |
| 60 | + at MassTransit.Middleware.ConsumerMessageFilter`2.MassTransit.IFilter<MassTransit.ConsumeContext<TMessage>>.Send(ConsumeContext`1 context, IPipe`1 next) in /_/src/MassTransit/Middleware/ConsumerMessageFilter.cs:line 48 |
| 61 | +``` |
| 62 | + |
| 63 | +### Handling failures using native tools |
| 64 | + |
| 65 | +Failed messages can be accessed using RabbitMQ Management console. Navigate to [queue list](http://localhost:15672/#/queues) (use `guest` for username and password) and click on the corresponding row to see summary information for the the `BillOrder_error` queue. |
| 66 | + |
| 67 | + |
| 68 | + |
| 69 | +For any individal error queue, the built-in tooling enables: |
| 70 | +- peeking failed messages from the head of the queue, |
| 71 | +- moving all messages in the error queue to some other location |
| 72 | + |
| 73 | + |
| 74 | + |
| 75 | +### Handling failures with the Particular Platform |
| 76 | + |
| 77 | +#### Starting the platform |
| 78 | + |
| 79 | +In order, to see how the Particular Platfrom improves the failed messages management, start the containers responsible for running the platform: |
| 80 | + |
| 81 | +```bash |
| 82 | +docker compose --profile platform up -d |
| 83 | +``` |
| 84 | + |
| 85 | +This will make the platform monitor error messages for all the consumers in the sample system. Upon failure any moved by a MassTransit consumer to an error queue will be ingest and index by the platform. |
| 86 | + |
| 87 | +#### Inspecting failures |
| 88 | + |
| 89 | +Navigate to [http://localhost:9090](http://localhost:9090) to see the details on the failures ingested by the platform. |
| 90 | + |
| 91 | + |
| 92 | + |
| 93 | +#### Scheduling message reprocessing |
| 94 | + |
| 95 | +Click on the "Failed Messages" button at the top of the page to see all failed messages ingested by the platform grouped by the exception trype and stack trace. |
| 96 | + |
| 97 | + |
| 98 | + |
| 99 | +Drilling into an existing group to see the list of individual processing failures. Clicking on any |
| 100 | +of the rows in the list shows detailed information on a given failed message in the headers and message body tabs. |
| 101 | + |
| 102 | +A failed message can be scheduled for reprocessing by clicking the `Retry message` button. |
| 103 | + |
| 104 | + |
| 105 | + |
| 106 | +When messages get moved back to the input queue of the consumer and successfully reprocessed, this is indicated by a green rectangle (🟩) in the console output. |
| 107 | + |
| 108 | + |
| 109 | + |
| 110 | +#### Editing messages before reprocessing |
| 111 | + |
| 112 | +Go to the details page for one of the failed messages and click the `Edit & retry` button at the top. The pop-up window shows the headers collection and the message body in two separate tabs. |
| 113 | + |
| 114 | +Navigate to the `Message Body` tab, change the last digit of the `orderId` value, and click "Retry" to schedule the message for reprocessing. |
| 115 | + |
| 116 | + |
0 commit comments