How To Propagate Context Information Throw Spring Batch

How To Propagate Context Information Throw Spring Batch

How To Propagate Context Information Throw Spring Batch. A very helpful article. Do not ignore this article. Because it is sure you will need it later.

Introduction to a framework that performs the propagation of Spring Security, Sleuth, MDC, and Locale (Internationalization) contexts inside Spring Batch items.

Introduction

While developing applications using Spring batch, especially in a micro-service project, we sometimes face one or most of the following cases:

  • The necessity of getting the security context inside the batch items to call methods that require authorizations inside the same micro-service or perform remote processing by calling other micro-services using Feign Client (HTTP) or Spring Cloud Stream (broker like Kafka, RabbitMq ...)
  • Propagating Sleuth trace Id and span Id in order to enhance logs traceability inside all the application components including other micro-services so the trace will not be lost if we use Job.
  • Getting the connected user Locale (i18n) in order to generate internationalized output otherwise, all the Job outputs will be generated in the default server language.
  • Retrieving objects stored inside Mapped Diagnostic Context (MDC) for tracing purposes.

The following schema illustrates remote calls that can be performed in a micro-service-based application and the context information that String Batch items can propagate.

The cases described above can be resolved by passing the context information as job parameters and restoring them before the job or step runs using JobExecutionListener or StepExecutionListener, respectively, according to the execution configuration made (One thread per job or thread pool that).

The problem with this approach is that the code responsible for the job parameters injection will appear with the business one which can cause confusion during code maintenance, also this processing should be transparent for the developers so they can concentrate more on the business logic. This is why I want to introduce a new framework that can be used in order to propagate the contexts described above with the possibility of adding any other information easily.

java spring security spring-boot internatinalization propagation mdc spring-batch spring tutorial sleuth

What is Geek Coin

What is GeekCash, Geek Token

Best Visual Studio Code Themes of 2021

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

High-Performance Batch Processing Using Apache Spark and Spring Batch

Batch processing is dealing with a large amount of data; it actually is a method of running high-volume, repetitive data jobs and each job does a specific task. Let's explore it with us now.

How to Configure log4j2 In a Spring Boot Application? | Spring Boot Logging [Video]

How to Configure log4j2 In a Spring Boot Application? Do you know yet? Very simple, in just a few steps. If there's one show you shouldn't miss it's here.

Introduction to Spring Boot and JDBCTemplate: Refactoring to SpringData JPA

Introduction to Spring Boot and JDBCTemplate: Refactoring to SpringData JPA. Refactoring is...

Spring Security Tutorial with Login Example (Spring Boot + Spring Security + MySQL)

In this video, we'll go through the Spring Security Implementation with MySQL

Spring Boot: Profile Config, YAML Property File

In this tutorial, we'll learn Spring Boot: Profile Config, YAML Property File. Let's explore it with us now.