Decorating the methods with enhancements can be cumbersome. Recording transactions was the next stuff I wanted to do. It took me a day to do that stuff however.
Its 3 am at night or morning whatever, I am feeling sleepy but I wanted to jot this down no matter what. I am trying to recall what I did for it.
As I recall, I started by creating the db models for storing the trasaction details. Chose to create three table – one for recording transaction be it in processing or failure or complete status, second one is api error logs and last one is unusual activity error log.
Used rabbitmq to consume the data from the order and payment microservices, and used the same for producing the data as well.
Rest it was all about placing the producer call in right place in the code and logging it to database while returning valid response. This may sound easy but was kind of difficult in this case.
It can be laborious at this night to explain what is the actual logic, but here is a brief explanation that placed failed producer logger in the except blocks and processing, initiated, completed producer logs in the try block, rest is taken care by rabbitmq.
The hack here is when the attempts is 3 I am recording it as unusal activity, when the error is an instance of requestException then API error, but I was mostly able to test 500 internal server error by supplying the payment strategy as None, just in case user tries to order without paying, sounds impractical more so,
Tommorrow, will test the api log error. Then I intent to track the user activity to understand which product the user is ordering and how much range the user usually shops. I can think of so many such things to accomplish in this app. Hmm!! Sound interesting! I will try. But there is one thing I forgot is recording the payment strategy the user chooses I will inculcate it soon.
However, I am out of ideas of what to implement next. I will think something more so!