Reading Operation Data: Persistent
Explore how to implement persistent storage for Spring Boot Actuator HTTP trace data using a custom wrapper and Spring Data MongoDB. Understand the need for immutable object handling with Spring Data converters, repository customization, and how to register these components. This lesson helps you grasp practical methods for monitoring and managing operation data in reactive Spring Boot applications.
We'll cover the following...
Adding wrapper class
Spring Boot Actuator’s HttpTraceRepository stores’ instances of the HttpTrace
class. Unfortunately, that record doesn’t have a proper key. This means we can’t save it directly into MongoDB. To handle this, and considering the fact that HttpTrace is final and not extendable, we must define a wrapper.
- In line 2, the wrapper contains a string-based
idwith Spring Data Commons’@Idannotation applied. This allows each instance to be uniquely identified. - In line 3, an actual
HttpTraceinstance is contained in the wrapper. - In line 4, we need a constructor call that accepts an existing
HttpTraceobject. Theidis null so that Spring Data MongoDB creates a new, unique key. - In line 7, a getter is needed to extract the
HttpTraceobject when retrieving.
We know that we must also define a corresponding Spring Data repository to store and retrieve HttpTraceWrapper objects from our MongoDB server.
Should this repository use the same Reactive Streams tactics we’ve used so far?
The answer to this is no, because HttpTraceRepository ...