= Single Step Batch Job
This is a Spring Cloud Task application that autoconfigures a single step Spring Batch job based on the profiles that are active.
The profiles that are available are:
* `ffreader` - Activates a FlatFileItemReader that reads from the `test.txt` file provided.
* `ffwriter` - Activates a FlatFileItemWriter that writes to the `result.txt` file.
* `jdbcreader` - Activates a JdbcCursorItemReader that reads from the `item_sample` table.
* `jdbcwriter` - Activates a JdbcItemReader that writes to the `item` table.
* `amqpreader` - Activates a AmqpItemReader that reads from the `samplequeue` queue.
* `amqpwriter` - Activates a AmqpItemWriter that writes to the `sampleexchange` exchange.
* `kafkareader` - Activates a KafkaItemReader that reads from the `sampletopic` topic.
* `kafkawriter` - Activates a KafkaItemWriter that writes to the `sampletopic` topic.
== Requirements:
* Java 17 or Above
== Classes:
* SingleStepBatchJobApplication - the Spring Boot Main Application
== Build:
[source,shell]
----
mvn clean package
----
== Run:
[source,shell]
----
java -jar target/single-step-batch-job-3.0.0-SNAPSHOT.jar --spring.config.name=<property file containing batch, reader, and writer properties>
----
== Examples
=== FlatFileItemReader with a FlatFileItemWriter batch job
In this example the batch job will read from the test.txt file from the resources directory and write a `result.txt` file to the root directory of the project.
```
java -Dspring.profiles.active=ffreader,ffwriter -jar target/single-step-batch-job-2.3.0-SNAPSHOT.jar
```
=== FlatFileItemReader with a JdbcItemWriter batch job
In this example the batch job will read from the test.txt file from the resources directory and write the result to the `item` table in your data store.
```
java -Dspring.profiles.active=ffreader,jdbcwriter -jar target/single-step-batch-job-2.3.0-SNAPSHOT.jar
```
Before running create the following table:
```
CREATE TABLE IF NOT EXISTS item
(
item_name varchar(55)
);
```
=== JdbcCursorItemReader with a JdbcItemWriter batch job
In this example the batch job will read from the `item_sample` table in your data store (as specified in the default `DataSource` properties) and write the result to the `item` table in your data store (as specified in the default `DataSource` properties).
```
java -Dspring.profiles.active=jdbcreader,jdbcwriter -jar target/single-step-batch-job-2.3.0-SNAPSHOT.jar
```
Before running create the following tables:
```
CREATE TABLE IF NOT EXISTS item
(
item_name varchar(55)
);
CREATE TABLE IF NOT EXISTS item_sample
(
ITEM_NAME varchar(55)
);
INSERT INTO item_sample (item_name) VALUES ('foo');
INSERT INTO item_sample (item_name) VALUES ('bar');
INSERT INTO item_sample (item_name) VALUES ('baz');
INSERT INTO item_sample (item_name) VALUES ('boo');
INSERT INTO item_sample (item_name) VALUES ('qux');
INSERT INTO item_sample (item_name) VALUES ('Job');
```
You may also wish to read from and write to data sources different from the default `DataSource`. This can be done specifying datasources for the reader and writer as follows:
```
# Jdbc Cursor Item Reader Data Source
export jdbccursoritemreader_datasource_url=<your reader database>
export jdbccursoritemreader_datasource_username=<your user>
export jdbccursoritemreader_datasource_password=<your password>
export jdbccursoritemreader_datasource_driverClassName=<your driver classname>
export spring_batch_job_jdbccursoritemreader_datasource_enable=true
# Jdbc Batch Item Writer Data Source
export jdbcbatchitemwriter_datasource_url=<your writer database>
export jdbcbatchitemwriter_datasource_username=<your user>
export jdbcbatchitemwriter_datasource_password=<your password>
export jdbcbatchitemwriter_datasource_driverClassName=<your driver classname>
export spring_batch_job_jdbcbatchitemwriter_datasource_enable=true
```
=== JdbcCursorItemReader with FlatfileItemWriter batch job
In this example the batch job will read from the `item_sample` table in your data store and write the result to the `result.txt` file to the root directory of the project.
```
java -Dspring.profiles.active=jdbcreader,ffwriter -jar target/single-step-batch-job-2.3.0-SNAPSHOT.jar
```
Before running create the following table:
```
CREATE TABLE IF NOT EXISTS item_sample
(
ITEM_NAME varchar(55)
);
INSERT INTO item_sample (item_name) VALUES ('foo');
INSERT INTO item_sample (item_name) VALUES ('bar');
INSERT INTO item_sample (item_name) VALUES ('baz');
INSERT INTO item_sample (item_name) VALUES ('boo');
INSERT INTO item_sample (item_name) VALUES ('qux');
INSERT INTO item_sample (item_name) VALUES ('Job');
```
=== FlatfileItemReader with AmqpItemWriter batch job
In this example the batch job will read from the `test.txt` file and write the result to the `sampleexchange` exchange.
```
java -Dspring.profiles.active=ffreader,amqpwriter -jar target/single-step-batch-job-2.3.0-SNAPSHOT.jar
```
NOTE: Before running create an exchange named `sampleexchange`.
=== AmqpItemReader with FlatfileItemWriter batch job
In this example the batch job will read from the `samplequeue` queue and write the result to the `result.txt` in the current directory.
```
java -Dspring.profiles.active=amqpreader,ffwriter -jar target/single-step-batch-job-2.3.0-SNAPSHOT.jar
```
NOTE: Before running create and populate a queue named `samplequeue`.
=== FlatfileItemReader with KafkaItemWriter batch job
In this example the batch job will read from the `test.txt` file and write the result to the `sampletopic` topic.
```
java -Dspring.profiles.active=ffreader,kafkawriter -jar target/single-step-batch-job-2.3.0-SNAPSHOT.jar
```
Before running create a topic named `sampletopic`. For example:
```
kafka-topics.sh --create --topic sampletopic --bootstrap-server localhost:9092
```
=== KafkaItemReader with FlatfileItemWriter batch job
In this example the batch job will read from the `sampletopic` topic and write the result to the `result.txt` in the current directory.
```
java -Dspring.profiles.active=kafkareader,ffwriter -jar target/single-step-batch-job-2.3.0-SNAPSHOT.jar
```
Before running populate the topic named `sampletopic`. For example populate it using the FlatfileItemReader and KafkaItemWriter from above:
```
java -Dspring.profiles.active=ffreader,kafkawriter -jar target/single-step-batch-job-2.3.0-SNAPSHOT.jar
```