dimanche 22 novembre 2020

Passing an extra parameter along method chain

I have several microservices on Spring Boot and one of them is designed for logging processes from other services. In the services that work with it, it is necessary to pass the session identifier variable along the chain of called methods. Methods can be called asynchronously via @Assync. The session can be started by the user through the controller or by schedule.

Example:

public void method1(..., Long sessionId) {
    ...
    if (condition) {
        obj.method2(..., Long sessionId);
    } else {
        method3(..., Long sessionId);
    }
}

My problem is that I would like to get away from explicitly passing a given variable to each method from the chain. Maybe there is some pattern or another solution.

Aucun commentaire:

Enregistrer un commentaire