Share
Embed
Transcript
61 slides
-
What’s new in Spring Batch 5? Mahmoud Ben Hassine Spring
Batch Lead, VMware @fmbenhassine -
AGENDA • New baseline • New features • Pruning •
Support policy • What’s next? -
AGENDA • New baseline • New features • Pruning •
Support policy • What’s next? -
DEPENDENCIES UPDATES • Spring Framework 6 • Spring Integration 6
• Spring Data 3 • Spring AMQP 3 • Spring for Apache Kafka 3 • Spring LDAP 3 • Spring Retry 2 • Micrometer 1.10 -
DEPENDENCIES UPDATES • Spring Framework 6 • Spring Integration 6
• Spring Data 3 • Spring AMQP 3 • Spring for Apache Kafka 3 • Spring LDAP 3 • Spring Retry 2 • Micrometer 1.10 https://github.com/spring-projects/spring-framework/wiki -
JAVA VERSION UPDATES • Java 17+ • Jakarta EE 9+
https://www.youtube.com/watch?v=P7SI9mLwiqw -
JAVA VERSION UPDATES • Java 17+ • Jakarta EE 9+
https://www.youtube.com/watch?v=P7SI9mLwiqw "You should expect to see these benefits without having to change anything in your code, just by updating to a newer Java version." Aurelio García-Ribeyro - Senior Director of Product Management - Java Platform Group -
AGENDA • New baseline • New features • Pruning •
Support policy • What’s next? -
JAVA RECORDS SUPPORT UPDATES • Several improvements since 4.3 o
Bug fixes o Addition of RecordFieldExtractor for Java Records (similar to BeanWrapperFieldExtractor for Java Beans) • Usage of java.lang.Record APIs to improve configuration o Automatic configuration of mappers in item readers based on item type o Automatic configuration of extractors in item writers based on item type -
JAVA RECORDS SUPPORT UPDATES // given class Person {int id;
String name;} // when FlatFileItemReader<Person> reader = new FlatFileItemReaderBuilder<Person>() .resource(new FileSystemResource("/data/persons.csv")) .targetType(Person.class) // set other properties .build(); // then // assertThat(reader.getFieldSetMapper()).isInstanceOf(BeanWrapperFieldSetMapper.class); -
JAVA RECORDS SUPPORT UPDATES // given record Person (int id,
String name) {} // when FlatFileItemReader<Person> reader = new FlatFileItemReaderBuilder<Person>() .resource(new FileSystemResource("/data/persons.csv")) .targetType(Person.class) // set other properties .build(); // then // assertThat(reader.getFieldSetMapper()).isInstanceOf(RecordFieldSetMapper.class); -
JAVA RECORDS SUPPORT UPDATES public class FlatFileItemReaderBuilder<T> { private Class<T>
targetType; public FlatFileItemReader<T> build() { FlatFileItemReader<T> reader = new FlatFileItemReader(); if (this.targetType.isRecord()) { reader.setFieldSetMapper(new RecordFieldSetMapper(this.targetType); } else { reader.setFieldSetMapper(new BeanWrapperFieldSetMapper(this.targetType); } } } -
@EnableBatchProcessing IMPROVEMENTS @Configuration @EnableBatchProcessing public class MyJobConfiguration { @Bean public
Job job(JobRepository jobRepository) { return new JobBuilder(“myJob”, jobRepository) // define job flow as needed .build(); } } -
@EnableBatchProcessing IMPROVEMENTS @Configuration @EnableBatchProcessing public class MyJobConfiguration { @Bean public
Job job(JobRepository jobRepository) { … } @Bean public BatchConfigurer batchConfigurer(DataSource dataSource) { return new DefaultBatchConfigurer() { @Override public JobRepository getJobRepository() { return new MyCustomJobRepository(dataSource); } }; } } -
@EnableBatchProcessing IMPROVEMENTS @Configuration @EnableBatchProcessing(dataSourceRef = "batchDataSource") public class MyJobConfiguration {
@Bean public Job job(JobRepository jobRepository) { … } @Bean public DataSource batchDataSource() { return new MyDataSource(); } } -
@EnableBatchProcessing IMPROVEMENTS @Configuration @EnableBatchProcessing public class MyJobConfiguration { @Bean public
BatchConfigurer batchConfigurer() { return new DefaultBatchConfigurer() { private Jackson2ExecutionContextStringSerializer customSerializer() { Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer(); // customize serializer return serializer; } @Override public JobRepository getJobRepository() { JobRepositoryFactoryBean factoryBean = new JobRepositoryFactoryBean(); factoryBean.setSerializer(customSerializer()); try { return factoryBean.getObject(); } catch (Exception e) { throw new RuntimeException(e); } } … @Override public JobExplorer getJobExplorer() { JobExplorerFactoryBean factoryBean = new JobExplorerFactoryBean(); factoryBean.setSerializer(customSerializer()); // set other properties try { return factoryBean.getObject(); } catch (Exception e) { throw new RuntimeException(e); } } }; } -
@EnableBatchProcessing IMPROVEMENTS @Configuration @EnableBatchProcessing(executionContextSerializerRef = "myCustomSerializer") public class MyJobConfiguration {
@Bean public Jackson2ExecutionContextStringSerializer myCustomSerializer() { Jackson2ExecutionContextStringSerializer serializer = new Jackson2ExecutionContextStringSerializer(); // customize serializer return serializer; } } -
ADDITION OF DefaultBatchConfiguration @Configuration public class MyJobConfiguration extends DefaultBatchConfiguration {
@Bean public Job job(JobRepository jobRepository) { return new JobBuilder(“myJob”, jobRepository) // define job flow as needed .build(); } } -
ADDITION OF DefaultBatchConfiguration @Configuration public class MyJobConfiguration extends DefaultBatchConfiguration {
@Bean public Job job(JobRepository jobRepository) { return new JobBuilder(“myJob”, jobRepository) // define job flow as needed .build(); } @Override public DataSource getDataSource() { return new MyDataSource(); } } -
PARAMETER CONVERSION IMPROVEMENTS Notation in v4: [+|-]parameterName(parameterType)=parameterValue $>java -jar my-job.jar
-schedule.date(date)=2023-01-26 -
PARAMETER CONVERSION IMPROVEMENTS Notation in v4: [+|-]parameterName(parameterType)=parameterValue $>java -jar my-job.jar
-schedule.date(date)=2023-01-26 Incompatible with Spring Boot -
PARAMETER CONVERSION IMPROVEMENTS Notation in v4: [+|-]parameterName(parameterType)=parameterValue $>java -jar my-job.jar
-schedule.date(date)=2023-01-26 Incompatible with Spring Boot Incompatible with Environment variables -
PARAMETER CONVERSION IMPROVEMENTS Notation in v4: [+|-]parameterName(parameterType)=parameterValue $>java -jar my-job.jar
-schedule.date(date)=2023-01-26 Incompatible with Spring Boot Incompatible with Environment variables Ambiguous parameter type -
PARAMETER CONVERSION IMPROVEMENTS Notation in v5 (default): parameterName=parameterValue,parameterType,identificationFlag $>java -jar
my-job.jar schedule.date=2023-01-26,java.time.LocalDate -
PARAMETER CONVERSION IMPROVEMENTS Notation in v5 (extended): parameterName='{ "value": "parameterValue",
"type": "parameterType", "identifying": "booleanValue" }' $>java -jar my-job.jar schedule.date='{value:"2023-01-26", type:"java.time.LocalDate"}' -
PARAMETER CONVERSION IMPROVEMENTS Notation in v5 (extended): parameterName=‘{ "value": "parameterValue",
"type":"parameterType", "identifying": "booleanValue” }' $>java -jar my-job.jar schedule.date='{value:"2023-01-26", type:"java.time.LocalDate"}' -
PARAMETER TYPES IMPROVEMENTS • Supported types in v4: String, Long,
Double, Date • Supported types in v5: Any type! $>java -jar export-orders-job.jar customer=foo,my.domain.Customer -
HOW TO SUPPORT CUSTOM PARAMETER TYPES? @Configuration @EnableBatchProcessing public class
MyJobConfiguration { @Bean public Job job(JobRepository jobRepository) { return new MyJob(jobRepository); } } -
HOW TO SUPPORT CUSTOM PARAMETER TYPES? @Configuration @EnableBatchProcessing(conversionServiceRef = "myCustomConversionService")
public class MyJobConfiguration { @Bean public Job job(JobRepository jobRepository) { return new MyJob(jobRepository); } @Bean public ConfigurableConversionService myCustomConversionService() { DefaultConversionService conversionService = new DefaultConversionService(); // add converters from String to my.domain.Customer and vice-versa in conversionService return conversionService; } } -
EXECUTION CONTEXT IMPROVEMENTS • Serialization format updates ◦ Base64 instead
of JSON ◦ Jackson is now optional • Meta-data improvements ◦ New “batch.version” attribute in the context { batch.stepType: “..”, batch.restart: “..”, .. batch.version: “5.0.0” } -
SCHEMA UPDATES • Usage of sequences instead of tables for
SQLServer • Addition of column CREATE_TIME in BATCH_STEP_EXECUTION • Addition of PARAMETER_NAME, PARAMETER_TYPE and PARAMETER_VALUE in BATCH_JOB_EXECUTION_PARAMS • Removal of BATCH_CONFIGURATION_LOCATION in BATCH_JOB_EXECUTION https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide -
BATCH METRICS IMPROVEMENTS • Several improvements since 4.3 ◦ Bug
fixes ◦ Consistent tag names • Upgraded the usage of Observability APIs to Micrometer 1.10 • New metrics ◦ Currently active step ◦ Job launch count -
HOW TO ENABLE BATCH METRICS? @Configuration @EnableBatchProcessing public class MyJobConfiguration
{ @Bean public Job job() { return new MyJob(); } } -
HOW TO ENABLE BATCH METRICS? @Configuration @EnableBatchProcessing public class MyJobConfiguration
{ @Bean public Job job() { return new MyJob(); } @Bean public ObservationRegistry observationRegistry() { ObservationRegistry registry = ObservationRegistry.create(); // configure the registry as needed return registry; } } -
HOW TO ENABLE BATCH TRACING? @Configuration @EnableBatchProcessing public class MyJobConfiguration
{ @Bean public Job job() { return new MyJob(); } @Bean public ObservationRegistry observationRegistry() { ObservationRegistry registry = ObservationRegistry.create(); // configure the registry as needed return registry; } } -
HOW TO ENABLE BATCH TRACING? @Configuration @EnableBatchProcessing public class MyJobConfiguration
{ @Bean public Job job() { return new MyJob(); } @Bean public ObservationRegistry observationRegistry(Tracer tracer) { ObservationRegistry registry = ObservationRegistry.create(); registry.observationConfig().observationHandler( new DefaultTracingObservationHandler(tracer)); return registry; } } -
GRAALVM NATIVE SUPPORT IMPROVEMENTS • Several improvements since v4.3 ◦
Bug fixes ◦ Performance improvements ◦ Tooling improvements • Addition of native hints for AOT processing by Spring ◦ Reflection hints ◦ Resource hints ◦ Proxy hints ◦ Serialization hints -
HELLO-WORLD NATIVE PERFORMANCE 1248 44 0 200 400 600 800
1000 1200 1400 Startup time (ms) JVM Native 26 1 0 5 10 15 20 25 30 Total execution time (ms) JVM Native https://github.com/fmbenhassine/spring-batch-lab/tree/main/talks/spring-batch-native/hello-world -
FILE-TO-DB (1M ITEMS) NATIVE PERFORMANCE 905 41 0 100 200
300 400 500 600 700 800 900 1000 Startup time (ms) JVM Native 37 15 0 5 10 15 20 25 30 35 40 Total execution time (s) JVM Native https://github.com/fmbenhassine/spring-batch-lab/tree/main/talks/spring-batch-native/file-to-db -
GRAALVM NATIVE IMAGE COMPILATION $> curl https://start.spring.io/starter.zip \ -d dependencies=h2,batch,native
\ -d type=maven-project \ -o my-batch-job.zip $> unzip my-batch-job.zip $> # EDIT your Spring Batch app as needed &> mvn -Pnative native:compile &> ./target/my-batch-job -
OTHER FEATURES • New Maven Bill Of Materials • UTF-8
by default in all areas of the framework • Transaction support in JobExplorer and JobOperator • Automatic registration of JobOperator with @EnableBatchProcessing • SystemCommandTasklet improvements (new CommandRunner interface) • Test utilities improvements + migration to Junit 5 • New documentation backend -
AGENDA • New baseline • New features • Pruning •
Support policy • What’s next? -
REMOVED FEATURES • SQLFire support removal • GemFire support removal
• JSR-352 implementation removal • Deprecated APIs removal https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide#pruning https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide#removed-apis -
AGENDA • New baseline • New features • Pruning •
Support policy • What’s next? -
SUPPORT POLICY • Same support policy as VMware Tanzu •
Same support period as Spring Boot ◦ Spring Batch 5.0 (Spring Boot 3.0) ◦ Spring Batch 4.3 (Spring Boot 2.7) https://spring.io/projects/spring-batch#support -
AGENDA • New baseline • New features • Pruning •
Support policy • What’s next? -
WHAT’S NEXT? • Support for 5.0.x and 4.3.x • Spring
Batch 5.1 (Spring Framework 6.1) ◦ Better getting started experience ◦ Virtual Threads (Project Loom) support ◦ Revisit the chunk-oriented processing model implementation Those are goals, not commitments! -
60 Our vision Empower Spring developers to continuously learn, innovate
and solve complex problems. Core features • Project-based courses with hands-on labs • In-browser code editing and debugging • Certification prep courses • Spring Certified Professional certification Sign up today Get started for free at https://spring.academy. For conference attendees Use SPRINGIO-2023 at checkout by June 4th for a 20% discount on a Spring Academy Pro subscription. -
THANK YOU! Q&A Mahmoud Ben Hassine Spring Batch Lead, VMware
@fmbenhassine https://docs.spring.io/spring-batch/docs/5.0.0/reference/html/whatsnew.html https://github.com/spring-projects/spring-batch/wiki/Spring-Batch-5.0-Migration-Guide