From 1eab6f63ed5f262379d4ffdce703f0aed883a398 Mon Sep 17 00:00:00 2001 From: Mahmoud Ben Hassine Date: Mon, 25 Sep 2023 08:53:56 +0200 Subject: [PATCH] Move AMQP sample to rabbitmq package Issue #3663 --- spring-batch-samples/README.md | 15 +----------- .../AmqpJobConfiguration.java | 4 +++- .../batch/sample/rabbitmq/README.md | 24 +++++++++++++++++++ .../batch/sample/AMQPJobFunctionalTests.java | 2 +- 4 files changed, 29 insertions(+), 16 deletions(-) rename spring-batch-samples/src/main/java/org/springframework/batch/sample/{amqp => rabbitmq}/AmqpJobConfiguration.java (95%) create mode 100644 spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/README.md diff --git a/spring-batch-samples/README.md b/spring-batch-samples/README.md index 77eac1ef5e..58abb260de 100644 --- a/spring-batch-samples/README.md +++ b/spring-batch-samples/README.md @@ -124,20 +124,7 @@ The `AmqpItemReader` and Writer were contributed by Chris Schaefer. It is modeled after the `JmsItemReader` / Writer implementations, which are popular models for remote chunking. It leverages the `AmqpTemplate`. -This example requires the env to have a copy of rabbitmq installed -and running. The standard dashboard can be used to see the traffic -from the `MessageProducer` to the `AmqpItemWriter`. Make sure you -launch the `MessageProducer` before launching the test. - -You can run the sample from the command line as following: - -``` -cd spring-batch-samples -# Launch the test using the XML configuration -../mvnw -Dtest=AMQPJobFunctionalTests#testLaunchJobWithXmlConfig test -# Launch the test using the Java configuration -../mvnw -Dtest=AMQPJobFunctionalTests#testLaunchJobWithJavaConfig test -``` +[Amqp Job Sample](./src/main/java/org/springframework/batch/sample/rabbitmq/README.md) ### BeanWrapperMapper Sample diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/amqp/AmqpJobConfiguration.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/AmqpJobConfiguration.java similarity index 95% rename from spring-batch-samples/src/main/java/org/springframework/batch/sample/amqp/AmqpJobConfiguration.java rename to spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/AmqpJobConfiguration.java index 173b8fcbda..a8088d189e 100644 --- a/spring-batch-samples/src/main/java/org/springframework/batch/sample/amqp/AmqpJobConfiguration.java +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/AmqpJobConfiguration.java @@ -14,7 +14,7 @@ * limitations under the License. */ -package org.springframework.batch.sample.amqp; +package org.springframework.batch.sample.rabbitmq; import javax.sql.DataSource; @@ -29,6 +29,7 @@ import org.springframework.batch.item.ItemWriter; import org.springframework.batch.item.amqp.builder.AmqpItemReaderBuilder; import org.springframework.batch.item.amqp.builder.AmqpItemWriterBuilder; +import org.springframework.batch.sample.rabbitmq.processor.MessageProcessor; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder; @@ -55,6 +56,7 @@ public Step step(JobRepository jobRepository, JdbcTransactionManager transaction RabbitTemplate rabbitInputTemplate, RabbitTemplate rabbitOutputTemplate) { return new StepBuilder("step", jobRepository).chunk(1, transactionManager) .reader(amqpItemReader(rabbitInputTemplate)) + .processor(new MessageProcessor()) .writer(amqpItemWriter(rabbitOutputTemplate)) .build(); } diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/README.md b/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/README.md new file mode 100644 index 0000000000..bc3b37d95c --- /dev/null +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/README.md @@ -0,0 +1,24 @@ +# AMQP sample Job + +## About + +This sample shows the use of Spring Batch to write to an `AmqpItemWriter`. +The `AmqpItemReader` and Writer were contributed by Chris Schaefer. +It is modeled after the `JmsItemReader` / Writer implementations, which +are popular models for remote chunking. It leverages the `AmqpTemplate`. + +## Run the sample + +This example requires the env to have a copy of rabbitmq installed +and running. The standard dashboard can be used to see the traffic +from the `MessageProducer` to the `AmqpItemWriter`. Make sure you +launch the `MessageProducer` before launching the test. + +You can run the sample from the command line as following: + +``` +cd spring-batch-samples +# Launch the test using the XML configuration +../mvnw -Dtest=AMQPJobFunctionalTests#testLaunchJobWithXmlConfig test +# Launch the test using the Java configuration +../mvnw -Dtest=AMQPJobFunctionalTests#testLaunchJobWithJavaConfig test \ No newline at end of file diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java index 3224bf89ca..bd7b528cc4 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java @@ -36,7 +36,7 @@ import org.springframework.batch.core.launch.JobLauncher; import org.springframework.batch.item.ItemReader; import org.springframework.batch.item.ItemWriter; -import org.springframework.batch.sample.amqp.AmqpJobConfiguration; +import org.springframework.batch.sample.rabbitmq.AmqpJobConfiguration; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean;