{"id":14973032,"url":"https://github.com/zahidmed/spring-batch-context","last_synced_at":"2025-04-23T14:31:37.771Z","repository":{"id":52921174,"uuid":"354387389","full_name":"zahidMed/spring-batch-context","owner":"zahidMed","description":"This project allows the propagation of context information throw Spring-batch jobs. The current supported information concerns spring-security, sleuth and MDC. It can be easily extended to support other information.","archived":false,"fork":false,"pushed_at":"2023-02-18T09:11:28.000Z","size":123,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-30T13:35:13.640Z","etag":null,"topics":["mdc","propagation","spring-batch","spring-batch-jobs","spring-boot","spring-security","spring-sleuth"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/zahidMed.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null}},"created_at":"2021-04-03T20:25:30.000Z","updated_at":"2024-04-08T06:18:40.000Z","dependencies_parsed_at":"2022-08-30T11:32:03.268Z","dependency_job_id":null,"html_url":"https://github.com/zahidMed/spring-batch-context","commit_stats":{"total_commits":11,"total_committers":1,"mean_commits":11.0,"dds":0.0,"last_synced_commit":"dc247c5cf1d9d421a61c96063d254c692e0c93f5"},"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zahidMed%2Fspring-batch-context","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zahidMed%2Fspring-batch-context/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zahidMed%2Fspring-batch-context/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/zahidMed%2Fspring-batch-context/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/zahidMed","download_url":"https://codeload.github.com/zahidMed/spring-batch-context/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":250451786,"owners_count":21432897,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["mdc","propagation","spring-batch","spring-batch-jobs","spring-boot","spring-security","spring-sleuth"],"created_at":"2024-09-24T13:47:59.083Z","updated_at":"2025-04-23T14:31:37.466Z","avatar_url":"https://github.com/zahidMed.png","language":"Java","readme":"# Welcom to spring-batch-context\r\n\r\nThe aim of this library is to allow developers who use spring-batch to propagate information from the main thread that runs the batch (where JobLauncher is called) to the executions context of the batch items (ItemReader, ItemProcessor and ItemWriter) including the execution listeners (JobsExecutionListener and stepExecutionListener).\r\nFor example we some times need to extract the current user from Security Context, so instead of writing the code that passes the current user information as a job parameter we let this library to handle it.\r\nThis library can be extended to support any information developer want to add.\r\n\r\nThe integration of this library require a simple configuration during the job definition (see Configuration paragraph)\r\n\r\n# What is new in the version 1.1.0-RELEASE\r\nThis version supports multi-threaded step, multi-process, parallel steps and flow by using customized task executors that inherit from `SimpleAsyncTaskExecutor` and `ThreadPoolTaskExecutor`\r\n\r\n# Modules\r\nThis Project includes the modules described bellow.\r\n\r\n**Remark**: Unlike the version 1.0.0, this one doesn't include spring-batch and spring boot dependencies so developer should add his own ones.\r\n## Spring Security context propagation\r\n### Usage\r\nTo propagate Spring Security context (Authentication) inside the Job items and listeners , you need to add `spring-batch-security` as a dependency to your Spring based application, as shown in the following example for Maven:\r\n```xml\r\n\u003cdependency\u003e\r\n\t\u003cgroupId\u003eorg.digibooster.spring.batch\u003c/groupId\u003e\r\n\t\u003cartifactId\u003espring-batch-security\u003c/artifactId\u003e\r\n\t\u003cversion\u003e1.1.0-RELEASE\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n## MDC Context Map propagation\r\n### Usage\r\nTo propagate Slf4j's MDC context inside the Job items and listeners , you need to add `spring-batch-mdc` as a dependency to your Spring based application, as shown in the following example for Maven:\r\n```xml\r\n\u003cdependency\u003e\r\n\t\u003cgroupId\u003eorg.digibooster.spring.batch\u003c/groupId\u003e\r\n\t\u003cartifactId\u003espring-batch-mdc\u003c/artifactId\u003e\r\n\t\u003cversion\u003e1.1.0-RELEASE\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n## Sleuth Span Information propagation\r\n### Usage\r\nTo propagate Sleuth Span information context (TraceId, SpanId, Parents, Tags ...) inside the Job items and listeners , you need to add `spring-batch-sleuth` as a dependency to your Spring based application, as shown in the following example for Maven:\r\n```xml\r\n\u003cdependency\u003e\r\n\t\u003cgroupId\u003eorg.digibooster.spring.batch\u003c/groupId\u003e\r\n\t\u003cartifactId\u003espring-batch-sleuth\u003c/artifactId\u003e\r\n\t\u003cversion\u003e1.1.0-RELEASE\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n## Locale propatation (Internationalization)\r\n### Usage\r\nTo propagate internationalization context (Locale) inside the Job items and listeners , you need to add `spring-batch-locale` as a dependency to your Spring based application, as shown in the following example for Maven:\r\n```xml\r\n\u003cdependency\u003e\r\n\t\u003cgroupId\u003eorg.digibooster.spring.batch\u003c/groupId\u003e\r\n\t\u003cartifactId\u003espring-batch-locale\u003c/artifactId\u003e\r\n\t\u003cversion\u003e1.1.0-RELEASE\u003c/version\u003e\r\n\u003c/dependency\u003e\r\n```\r\n\r\n# Configuration\r\nIn order to run jobs asynchronously with parallel processing with context propagation, you need use one of the following task executors:\r\n- ContextBasedSimpleAsyncTaskExecutor: inherits `SimpleAsyncTaskExecutor` with context propagation support.\r\n- ContextBasedThreadPoolTaskExecutor: inherits `ThreadPoolTaskExecutor` with context propagation support.\r\n\r\n## Configuration example\r\n### Task executors configuration\r\n```java\r\n/**\r\n * Bean example for creating a simple task executor\r\n * The task listener beans are created automatically by the starter\r\n */\r\n@Bean\r\npublic TaskExecutor simpleTaskExecutor(@Autowired List\u003cTaskExecutorListener\u003e taskExecutorListeners){\r\n        return new ContextBasedSimpleAsyncTaskExecutor(taskExecutorListeners);\r\n}\r\n\r\n/**\r\n * Bean example for creating a thread pool task executor\r\n * The task listener beans are created automatically by the starter\r\n */\r\n@Bean\r\npublic TaskExecutor threadpoolTaskExecutor(@Autowired List\u003cTaskExecutorListener\u003e taskExecutorListeners) {\r\n        return new ContextBasedThreadPoolTaskExecutor(taskExecutorListeners);\r\n}\r\n\r\n```\r\n\r\n### Job launcher configuration\r\n\r\n````java\r\n/**\r\n * Bean example of Job launcher that uses the custom simple task executor for running jobs\r\n */\r\n@Bean\r\npublic JobLauncher jobLauncher(@Autowired JobRepository jobRepository, TaskExecutor simpleTaskExecutor) throws Exception {\r\n    SimpleJobLauncher jobLauncher = new SimpleJobLauncher();\r\n    jobLauncher.setJobRepository(jobRepository);\r\n    jobLauncher.setTaskExecutor(simpleTaskExecutor);// configuration of simple task executor for running the job asynchronously\r\n    jobLauncher.afterPropertiesSet();\r\n    return jobLauncher;\r\n}\r\n````\r\n\r\n### Step configuration\r\n\r\n````java\r\n/**\r\n * Bean example of Step that uses the custom thread pool task executor for parallel processing\r\n */\r\n@Bean\r\npublic Step step(@Autowired TaskExecutor threadpoolTaskExecutor) {\r\n    return stepBuilderFactory.get(\"step\")\r\n    .reader(reader())\r\n    .processor(processor())\r\n    .writer(writer())\r\n    .listener(stepExecutionListener())\r\n    .taskExecutor(threadpoolTaskExecutor) // configuration of step task executor for parallel processing\r\n    .build();\r\n}\r\n````\r\n\r\n### Example of flow configuration\r\n\r\n````java\r\n/**\r\n * Bean example of Flow that uses the custom thread pool task executor for\r\n * running flow1 and flow2 in parallel\r\n */\r\n@Bean\r\npublic Flow splitFlow(@Autowired TaskExecutor threadpoolTaskExecutor) {\r\n    return new FlowBuilder\u003cSimpleFlow\u003e(\"splitFlow\")\r\n    .split(threadpoolTaskExecutor)\r\n    .add(flow1(), flow2())\r\n    .build();\r\n}\r\n````\r\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzahidmed%2Fspring-batch-context","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fzahidmed%2Fspring-batch-context","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fzahidmed%2Fspring-batch-context/lists"}