From 0d7bf2cd71328082578e7b2185cb50e05e3e01f6 Mon Sep 17 00:00:00 2001 From: wxlund Date: Mon, 17 Dec 2012 16:34:38 -0800 Subject: [PATCH 1/5] Modified core to support drop and schema-sqlf.sql but leverages derby syntax outside of connection string. Modified *.properties file to add additional property "batch.isolationlevel=ISOLATION_SERIALIZABLE because batch-sqlf.properties needs batch.isolationlevel=ISOLATION_READ_COMMITTED. Added corresponding sqlf properties and sqlf files. Modified simple-job-launcher-context.xml to support the p:isolationLevelForCreate="${batch.isolationlevel}" --- .../batch/core/schema-drop-sqlf.sql | 12 +++ .../batch/core/schema-sqlf.sql | 79 ++++++++++++++ spring-batch-samples/pom.xml | 5 + .../src/main/resources/batch-derby.properties | 3 +- .../src/main/resources/batch-h2.properties | 1 + .../src/main/resources/batch-hsql.properties | 2 + .../src/main/resources/batch-mysql.properties | 2 + .../main/resources/batch-oracle.properties | 2 + .../src/main/resources/batch-sqlf.properties | 20 ++++ .../main/resources/batch-sqlserver.properties | 2 + .../main/resources/batch-sybase.properties | 2 + .../main/resources/business-schema-sqlf.sql | 100 ++++++++++++++++++ .../resources/simple-job-launcher-context.xml | 3 +- 13 files changed, 231 insertions(+), 2 deletions(-) create mode 100644 spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-sqlf.sql create mode 100644 spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlf.sql create mode 100644 spring-batch-samples/src/main/resources/batch-sqlf.properties create mode 100644 spring-batch-samples/src/main/resources/business-schema-sqlf.sql diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-sqlf.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-sqlf.sql new file mode 100644 index 000000000..68ffb0214 --- /dev/null +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-drop-sqlf.sql @@ -0,0 +1,12 @@ +-- Autogenerated: do not edit this file + +DROP TABLE BATCH_STEP_EXECUTION_CONTEXT ; +DROP TABLE BATCH_JOB_EXECUTION_CONTEXT ; +DROP TABLE BATCH_STEP_EXECUTION ; +DROP TABLE BATCH_JOB_EXECUTION ; +DROP TABLE BATCH_JOB_PARAMS ; +DROP TABLE BATCH_JOB_INSTANCE ; + +DROP TABLE BATCH_STEP_EXECUTION_SEQ ; +DROP TABLE BATCH_JOB_EXECUTION_SEQ ; +DROP TABLE BATCH_JOB_SEQ ; diff --git a/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlf.sql b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlf.sql new file mode 100644 index 000000000..f52f984fe --- /dev/null +++ b/spring-batch-core/src/main/resources/org/springframework/batch/core/schema-sqlf.sql @@ -0,0 +1,79 @@ +-- Autogenerated: do not edit this file + +CREATE TABLE BATCH_JOB_INSTANCE ( + JOB_INSTANCE_ID BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, + VERSION BIGINT , + JOB_NAME VARCHAR(100) NOT NULL, + JOB_KEY VARCHAR(32) NOT NULL, + constraint JOB_INST_UN unique (JOB_NAME, JOB_KEY) +) ; + +CREATE TABLE BATCH_JOB_EXECUTION ( + JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, + VERSION BIGINT , + JOB_INSTANCE_ID BIGINT NOT NULL, + CREATE_TIME TIMESTAMP NOT NULL, + START_TIME TIMESTAMP DEFAULT NULL , + END_TIME TIMESTAMP DEFAULT NULL , + STATUS VARCHAR(10) , + EXIT_CODE VARCHAR(100) , + EXIT_MESSAGE VARCHAR(2500) , + LAST_UPDATED TIMESTAMP, + constraint JOB_INST_EXEC_FK foreign key (JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) +) ; + +CREATE TABLE BATCH_JOB_PARAMS ( + JOB_INSTANCE_ID BIGINT NOT NULL , + TYPE_CD VARCHAR(6) NOT NULL , + KEY_NAME VARCHAR(100) NOT NULL , + STRING_VAL VARCHAR(250) , + DATE_VAL TIMESTAMP DEFAULT NULL , + LONG_VAL BIGINT , + DOUBLE_VAL DOUBLE PRECISION , + constraint JOB_INST_PARAMS_FK foreign key (JOB_INSTANCE_ID) + references BATCH_JOB_INSTANCE(JOB_INSTANCE_ID) +) ; + +CREATE TABLE BATCH_STEP_EXECUTION ( + STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, + VERSION BIGINT NOT NULL, + STEP_NAME VARCHAR(100) NOT NULL, + JOB_EXECUTION_ID BIGINT NOT NULL, + START_TIME TIMESTAMP NOT NULL , + END_TIME TIMESTAMP DEFAULT NULL , + STATUS VARCHAR(10) , + COMMIT_COUNT BIGINT , + READ_COUNT BIGINT , + FILTER_COUNT BIGINT , + WRITE_COUNT BIGINT , + READ_SKIP_COUNT BIGINT , + WRITE_SKIP_COUNT BIGINT , + PROCESS_SKIP_COUNT BIGINT , + ROLLBACK_COUNT BIGINT , + EXIT_CODE VARCHAR(100) , + EXIT_MESSAGE VARCHAR(2500) , + LAST_UPDATED TIMESTAMP, + constraint JOB_EXEC_STEP_FK foreign key (JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) +) ; + +CREATE TABLE BATCH_STEP_EXECUTION_CONTEXT ( + STEP_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, + SHORT_CONTEXT VARCHAR(2500) NOT NULL, + SERIALIZED_CONTEXT CLOB , + constraint STEP_EXEC_CTX_FK foreign key (STEP_EXECUTION_ID) + references BATCH_STEP_EXECUTION(STEP_EXECUTION_ID) +) ; + +CREATE TABLE BATCH_JOB_EXECUTION_CONTEXT ( + JOB_EXECUTION_ID BIGINT NOT NULL PRIMARY KEY, + SHORT_CONTEXT VARCHAR(2500) NOT NULL, + SERIALIZED_CONTEXT CLOB , + constraint JOB_EXEC_CTX_FK foreign key (JOB_EXECUTION_ID) + references BATCH_JOB_EXECUTION(JOB_EXECUTION_ID) +) ; + +CREATE TABLE BATCH_STEP_EXECUTION_SEQ (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1)); +CREATE TABLE BATCH_JOB_EXECUTION_SEQ (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1)); +CREATE TABLE BATCH_JOB_SEQ (ID BIGINT PRIMARY KEY GENERATED BY DEFAULT AS IDENTITY, DUMMY VARCHAR(1)); diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml index c44444cb9..558267338 100644 --- a/spring-batch-samples/pom.xml +++ b/spring-batch-samples/pom.xml @@ -17,6 +17,11 @@ hsql + + com.vmware.sqlfire + sqlfireclient + 1.0.3 + org.springframework.batch spring-batch-core diff --git a/spring-batch-samples/src/main/resources/batch-derby.properties b/spring-batch-samples/src/main/resources/batch-derby.properties index 97302789d..385ec9ca5 100644 --- a/spring-batch-samples/src/main/resources/batch-derby.properties +++ b/spring-batch-samples/src/main/resources/batch-derby.properties @@ -14,4 +14,5 @@ batch.database.incrementer.parent=columnIncrementerParent batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler batch.grid.size=2 batch.jdbc.pool.size=6 -batch.verify.cursor.position=false \ No newline at end of file +batch.verify.cursor.position=false +batch.isolationlevel=ISOLATION_SERIALIZABLE diff --git a/spring-batch-samples/src/main/resources/batch-h2.properties b/spring-batch-samples/src/main/resources/batch-h2.properties index f8cedeb70..925428ced 100644 --- a/spring-batch-samples/src/main/resources/batch-h2.properties +++ b/spring-batch-samples/src/main/resources/batch-h2.properties @@ -15,3 +15,4 @@ batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler batch.grid.size=2 batch.jdbc.pool.size=6 batch.verify.cursor.position=true +batch.isolationlevel=ISOLATION_SERIALIZABLE diff --git a/spring-batch-samples/src/main/resources/batch-hsql.properties b/spring-batch-samples/src/main/resources/batch-hsql.properties index b4ca5b5b3..41423fa1d 100644 --- a/spring-batch-samples/src/main/resources/batch-hsql.properties +++ b/spring-batch-samples/src/main/resources/batch-hsql.properties @@ -18,3 +18,5 @@ batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler batch.jdbc.pool.size=6 batch.grid.size=6 batch.verify.cursor.position=true +batch.isolationlevel=ISOLATION_SERIALIZABLE + diff --git a/spring-batch-samples/src/main/resources/batch-mysql.properties b/spring-batch-samples/src/main/resources/batch-mysql.properties index a39515564..947c24b7b 100644 --- a/spring-batch-samples/src/main/resources/batch-mysql.properties +++ b/spring-batch-samples/src/main/resources/batch-mysql.properties @@ -15,3 +15,5 @@ batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler batch.jdbc.pool.size=6 batch.grid.size=50 batch.verify.cursor.position=true +batch.isolationlevel=ISOLATION_SERIALIZABLE + diff --git a/spring-batch-samples/src/main/resources/batch-oracle.properties b/spring-batch-samples/src/main/resources/batch-oracle.properties index 811284365..22c75d505 100644 --- a/spring-batch-samples/src/main/resources/batch-oracle.properties +++ b/spring-batch-samples/src/main/resources/batch-oracle.properties @@ -15,3 +15,5 @@ batch.lob.handler.class=org.springframework.jdbc.support.lob.OracleLobHandler batch.grid.size=2 batch.jdbc.pool.size=6 batch.verify.cursor.position=true +batch.isolationlevel=ISOLATION_SERIALIZABLE + diff --git a/spring-batch-samples/src/main/resources/batch-sqlf.properties b/spring-batch-samples/src/main/resources/batch-sqlf.properties new file mode 100644 index 000000000..f47ecf9d1 --- /dev/null +++ b/spring-batch-samples/src/main/resources/batch-sqlf.properties @@ -0,0 +1,20 @@ +# Placeholders batch.* +# for Derby: +batch.jdbc.driver=com.vmware.sqlfire.jdbc.ClientDriver +batch.jdbc.url=jdbc:sqlfire://localhost:1257/;update=true +batch.jdbc.user=SAMPLES +batch.jdbc.password=SAMPLES +batch.jdbc.testWhileIdle=false +batch.jdbc.validationQuery= +batch.jdbc.verifyCursorPosition=false +batch.drop.script=classpath:/org/springframework/batch/core/schema-drop-derby.sql +batch.schema.script=classpath:/org/springframework/batch/core/schema-sqlf.sql +batch.business.schema.script=business-schema-sqlf.sql +batch.data.source.init=true +batch.database.incrementer.class=org.springframework.jdbc.support.incrementer.DerbyMaxValueIncrementer +batch.database.incrementer.parent=columnIncrementerParent +batch.lob.handler.class=org.springframework.jdbc.support.lob.DefaultLobHandler +batch.grid.size=2 +batch.jdbc.pool.size=6 +batch.verify.cursor.position=false +batch.isolationlevel=ISOLATION_READ_COMMITTED \ No newline at end of file diff --git a/spring-batch-samples/src/main/resources/batch-sqlserver.properties b/spring-batch-samples/src/main/resources/batch-sqlserver.properties index a79606c7f..f6307adf9 100644 --- a/spring-batch-samples/src/main/resources/batch-sqlserver.properties +++ b/spring-batch-samples/src/main/resources/batch-sqlserver.properties @@ -15,3 +15,5 @@ batch.database.incrementer.parent=columnIncrementerParent batch.grid.size=2 batch.jdbc.pool.size=6 batch.verify.cursor.position=true +batch.isolationlevel=ISOLATION_SERIALIZABLE + diff --git a/spring-batch-samples/src/main/resources/batch-sybase.properties b/spring-batch-samples/src/main/resources/batch-sybase.properties index 922ba570c..706bc4c62 100644 --- a/spring-batch-samples/src/main/resources/batch-sybase.properties +++ b/spring-batch-samples/src/main/resources/batch-sybase.properties @@ -15,4 +15,6 @@ batch.database.incrementer.parent=columnIncrementerParent batch.jdbc.pool.size=6 batch.grid.size=6 batch.verify.cursor.position=true +batch.isolationlevel=ISOLATION_SERIALIZABLE + diff --git a/spring-batch-samples/src/main/resources/business-schema-sqlf.sql b/spring-batch-samples/src/main/resources/business-schema-sqlf.sql new file mode 100644 index 000000000..027892559 --- /dev/null +++ b/spring-batch-samples/src/main/resources/business-schema-sqlf.sql @@ -0,0 +1,100 @@ +-- Autogenerated: do not edit this file +-- You might need to remove this section the first time you run against a clean database +DROP TABLE BATCH_STAGING_SEQ ; +DROP TABLE TRADE_SEQ ; +DROP TABLE CUSTOMER_SEQ ; +DROP TABLE BATCH_STAGING ; +DROP TABLE TRADE ; +DROP TABLE CUSTOMER ; +DROP TABLE PLAYERS ; +DROP TABLE GAMES ; +DROP TABLE PLAYER_SUMMARY ; +DROP TABLE ERROR_LOG ; + +-- Autogenerated: do not edit this file + +CREATE TABLE CUSTOMER_SEQ (ID BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY (start with 5), DUMMY VARCHAR(1)); +CREATE TABLE BATCH_STAGING_SEQ (ID BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY (start with 0), DUMMY VARCHAR(1)); +CREATE TABLE TRADE_SEQ (ID BIGINT PRIMARY KEY GENERATED ALWAYS AS IDENTITY (start with 0), DUMMY VARCHAR(1)); + +CREATE TABLE BATCH_STAGING ( + ID BIGINT NOT NULL PRIMARY KEY, + JOB_ID BIGINT NOT NULL, + VALUE BLOB NOT NULL, + PROCESSED CHAR(1) NOT NULL +) ; + +CREATE TABLE TRADE ( + ID BIGINT NOT NULL PRIMARY KEY, + VERSION BIGINT , + ISIN VARCHAR(45) NOT NULL, + QUANTITY BIGINT , + PRICE DECIMAL(8,2) , + CUSTOMER VARCHAR(45) +) ; + +CREATE TABLE CUSTOMER ( + ID BIGINT NOT NULL PRIMARY KEY, + VERSION BIGINT , + NAME VARCHAR(45) , + CREDIT DECIMAL(10,2) +) ; + + +INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (1, 0, 'customer1', 100000); +INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (2, 0, 'customer2', 100000); +INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (3, 0, 'customer3', 100000); +INSERT INTO CUSTOMER (ID, VERSION, NAME, CREDIT) VALUES (4, 0, 'customer4', 100000); + +--INSERT INTO CUSTOMER (VERSION, NAME, CREDIT) VALUES (0, 'customer1', 100000); +--INSERT INTO CUSTOMER (VERSION, NAME, CREDIT) VALUES (0, 'customer2', 100000); +--INSERT INTO CUSTOMER (VERSION, NAME, CREDIT) VALUES (0, 'customer3', 100000); +--INSERT INTO CUSTOMER (VERSION, NAME, CREDIT) VALUES (0, 'customer4', 100000); + +CREATE TABLE PLAYERS ( + PLAYER_ID CHAR(8) NOT NULL PRIMARY KEY, + LAST_NAME VARCHAR(35) NOT NULL, + FIRST_NAME VARCHAR(25) NOT NULL, + POS VARCHAR(10) , + YEAR_OF_BIRTH BIGINT NOT NULL, + YEAR_DRAFTED BIGINT NOT NULL +) ; + +CREATE TABLE GAMES ( + PLAYER_ID CHAR(8) NOT NULL, + YEAR_NO BIGINT NOT NULL, + TEAM CHAR(3) NOT NULL, + WEEK BIGINT NOT NULL, + OPPONENT CHAR(3) , + COMPLETES BIGINT , + ATTEMPTS BIGINT , + PASSING_YARDS BIGINT , + PASSING_TD BIGINT , + INTERCEPTIONS BIGINT , + RUSHES BIGINT , + RUSH_YARDS BIGINT , + RECEPTIONS BIGINT , + RECEPTIONS_YARDS BIGINT , + TOTAL_TD BIGINT +) ; + +CREATE TABLE PLAYER_SUMMARY ( + ID CHAR(8) NOT NULL, + YEAR_NO BIGINT NOT NULL, + COMPLETES BIGINT NOT NULL , + ATTEMPTS BIGINT NOT NULL , + PASSING_YARDS BIGINT NOT NULL , + PASSING_TD BIGINT NOT NULL , + INTERCEPTIONS BIGINT NOT NULL , + RUSHES BIGINT NOT NULL , + RUSH_YARDS BIGINT NOT NULL , + RECEPTIONS BIGINT NOT NULL , + RECEPTIONS_YARDS BIGINT NOT NULL , + TOTAL_TD BIGINT NOT NULL +) ; + +CREATE TABLE ERROR_LOG ( + JOB_NAME CHAR(20) , + STEP_NAME CHAR(20) , + MESSAGE VARCHAR(300) NOT NULL +) ; diff --git a/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml b/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml index 6f0fd01f9..147ae9dd2 100644 --- a/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml +++ b/spring-batch-samples/src/main/resources/simple-job-launcher-context.xml @@ -19,7 +19,8 @@ Date: Tue, 18 Dec 2012 08:35:23 -0800 Subject: [PATCH 2/5] Had to add back in the reference to sqlfire. --- spring-batch-parent/pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spring-batch-parent/pom.xml b/spring-batch-parent/pom.xml index d293878fb..4a6d0960c 100644 --- a/spring-batch-parent/pom.xml +++ b/spring-batch-parent/pom.xml @@ -135,6 +135,11 @@ bootstrap + + gemstone + Release bundles for SQLFire and GemFire + http://dist.gemstone.com.s3.amazonaws.com/maven/release + objectstyle ObjectStyle.org Repository @@ -351,6 +356,11 @@ + + com.vmware.sqlfire + sqlfireclient + 1.0.3 + org.aspectj aspectjrt From bfb406a1cf5e10149e7ab787be73c7ba9a852315 Mon Sep 17 00:00:00 2001 From: wxlund Date: Tue, 18 Dec 2012 10:38:24 -0800 Subject: [PATCH 3/5] Provided a sample to support AmqpItemReader/Writer addition to spring-batch-2.2. --- spring-batch-samples/pom.xml | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml index 558267338..104dfc7fa 100644 --- a/spring-batch-samples/pom.xml +++ b/spring-batch-samples/pom.xml @@ -243,6 +243,16 @@ mail 1.4.1 + + org.springframework.amqp + spring-amqp + true + + + org.springframework.amqp + spring-rabbit + true + From 96f870af4fbd16e4f83015e40dee6b37d038d627 Mon Sep 17 00:00:00 2001 From: wxlund Date: Tue, 18 Dec 2012 10:40:31 -0800 Subject: [PATCH 4/5] And now commit with the files that have been added for the sample. --- .../rabbitmq/amqp/AmqpMessageProducer.java | 29 +++++++++++ .../rabbitmq/processor/MessageProcessor.java | 17 +++++++ .../resources/META-INF/spring/batch-beans.xml | 37 ++++++++++++++ .../META-INF/spring/config-beans.xml | 13 +++++ .../jobs/amqp/amqp-example-job-beans.xml | 18 +++++++ .../spring/jobs/amqp/amqp-example-job.xml | 23 +++++++++ .../spring/jobs/messaging/rabbitmq-beans.xml | 24 +++++++++ .../main/resources/default.amqp.properties | 4 ++ .../main/resources/jobs/amqp-example-job.xml | 23 +++++++++ .../batch/sample/AMQPJobFunctionalTests.java | 49 +++++++++++++++++++ 10 files changed, 237 insertions(+) create mode 100644 spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/amqp/AmqpMessageProducer.java create mode 100644 spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/processor/MessageProcessor.java create mode 100644 spring-batch-samples/src/main/resources/META-INF/spring/batch-beans.xml create mode 100644 spring-batch-samples/src/main/resources/META-INF/spring/config-beans.xml create mode 100644 spring-batch-samples/src/main/resources/META-INF/spring/jobs/amqp/amqp-example-job-beans.xml create mode 100644 spring-batch-samples/src/main/resources/META-INF/spring/jobs/amqp/amqp-example-job.xml create mode 100644 spring-batch-samples/src/main/resources/META-INF/spring/jobs/messaging/rabbitmq-beans.xml create mode 100644 spring-batch-samples/src/main/resources/default.amqp.properties create mode 100644 spring-batch-samples/src/main/resources/jobs/amqp-example-job.xml create mode 100644 spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/amqp/AmqpMessageProducer.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/amqp/AmqpMessageProducer.java new file mode 100644 index 000000000..72e053f49 --- /dev/null +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/amqp/AmqpMessageProducer.java @@ -0,0 +1,29 @@ +package org.springframework.batch.sample.rabbitmq.amqp; + +import org.springframework.amqp.core.AmqpTemplate; +import org.springframework.amqp.rabbit.core.RabbitTemplate; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + *

+ * Simple producer class that sends {@link String} messages to the configured queue to be processed. + *

+ */ +public class AmqpMessageProducer { + public static final int SEND_MESSAGE_COUNT = 10; + public static final String[] BEAN_CONFIG = { "classpath:/META-INF/spring/jobs/messaging/rabbitmq-beans.xml", + "classpath:/META-INF/spring/config-beans.xml" }; + + public static void main(String[] args) { + ApplicationContext applicationContext = new ClassPathXmlApplicationContext(BEAN_CONFIG); + AmqpTemplate amqpTemplate = applicationContext.getBean("inboundAmqpTemplate", RabbitTemplate.class); + + for (int i = 0; i < SEND_MESSAGE_COUNT; i++ ) { + amqpTemplate.convertAndSend("foo message: " + i); + } + + ((ConfigurableApplicationContext) applicationContext).close(); + } +} diff --git a/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/processor/MessageProcessor.java b/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/processor/MessageProcessor.java new file mode 100644 index 000000000..e527a2973 --- /dev/null +++ b/spring-batch-samples/src/main/java/org/springframework/batch/sample/rabbitmq/processor/MessageProcessor.java @@ -0,0 +1,17 @@ +package org.springframework.batch.sample.rabbitmq.processor; + +import org.springframework.batch.item.ItemProcessor; + +import java.util.Date; + +/** + *

+ * Simple {@link ItemProcessor} implementation to append a "processed on" {@link Date} to a received message. + *

+ */ +public class MessageProcessor implements ItemProcessor { + + public String process(String message) throws Exception { + return "Message: \"" + message + "\" processed on: " + new Date(); + } +} diff --git a/spring-batch-samples/src/main/resources/META-INF/spring/batch-beans.xml b/spring-batch-samples/src/main/resources/META-INF/spring/batch-beans.xml new file mode 100644 index 000000000..dedbab573 --- /dev/null +++ b/spring-batch-samples/src/main/resources/META-INF/spring/batch-beans.xml @@ -0,0 +1,37 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/spring-batch-samples/src/main/resources/META-INF/spring/config-beans.xml b/spring-batch-samples/src/main/resources/META-INF/spring/config-beans.xml new file mode 100644 index 000000000..f5dc575de --- /dev/null +++ b/spring-batch-samples/src/main/resources/META-INF/spring/config-beans.xml @@ -0,0 +1,13 @@ + + + + + + + diff --git a/spring-batch-samples/src/main/resources/META-INF/spring/jobs/amqp/amqp-example-job-beans.xml b/spring-batch-samples/src/main/resources/META-INF/spring/jobs/amqp/amqp-example-job-beans.xml new file mode 100644 index 000000000..8d77e3866 --- /dev/null +++ b/spring-batch-samples/src/main/resources/META-INF/spring/jobs/amqp/amqp-example-job-beans.xml @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + diff --git a/spring-batch-samples/src/main/resources/META-INF/spring/jobs/amqp/amqp-example-job.xml b/spring-batch-samples/src/main/resources/META-INF/spring/jobs/amqp/amqp-example-job.xml new file mode 100644 index 000000000..2e74b98eb --- /dev/null +++ b/spring-batch-samples/src/main/resources/META-INF/spring/jobs/amqp/amqp-example-job.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + diff --git a/spring-batch-samples/src/main/resources/META-INF/spring/jobs/messaging/rabbitmq-beans.xml b/spring-batch-samples/src/main/resources/META-INF/spring/jobs/messaging/rabbitmq-beans.xml new file mode 100644 index 000000000..4bca5f143 --- /dev/null +++ b/spring-batch-samples/src/main/resources/META-INF/spring/jobs/messaging/rabbitmq-beans.xml @@ -0,0 +1,24 @@ + + + + + + + + + + + + + + diff --git a/spring-batch-samples/src/main/resources/default.amqp.properties b/spring-batch-samples/src/main/resources/default.amqp.properties new file mode 100644 index 000000000..9394facee --- /dev/null +++ b/spring-batch-samples/src/main/resources/default.amqp.properties @@ -0,0 +1,4 @@ +rabbitmq.port=5672 +rabbitmq.host=127.0.0.1 +rabbitmq.inbound.queue=test.inbound +rabbitmq.outbound.queue=test.outbound diff --git a/spring-batch-samples/src/main/resources/jobs/amqp-example-job.xml b/spring-batch-samples/src/main/resources/jobs/amqp-example-job.xml new file mode 100644 index 000000000..3c5b7ffdc --- /dev/null +++ b/spring-batch-samples/src/main/resources/jobs/amqp-example-job.xml @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + 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 new file mode 100644 index 000000000..773a8eeb1 --- /dev/null +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/AMQPJobFunctionalTests.java @@ -0,0 +1,49 @@ +package org.springframework.batch.sample; + +import static org.junit.Assert.assertTrue; + +import javax.sql.DataSource; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.batch.core.explore.JobExplorer; +import org.springframework.batch.test.JobLauncherTestUtils; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; + +/** + * Run the job to read from the "test.inbound" queue, process the messages and write them to the "test.outbound" queue: + * mvn -q exec:java -Dexec.mainClass="org.springframework.batch.core.launch.support.CommandLineJobRunner" \ + * -Dexec.arguments="classpath*:/META-INF/spring/jobs/amqp/amqp-example-job.xml,amqp-example-job" +*/ + +@RunWith(SpringJUnit4ClassRunner.class) +@ContextConfiguration(locations = { "/simple-job-launcher-context.xml", "/jobs/amqp-example-job.xml", "/job-runner-context.xml" }) +public class AMQPJobFunctionalTests { + + @Autowired + private JobLauncherTestUtils jobLauncherTestUtils; + private SimpleJdbcTemplate simpleJdbcTemplate; + @Autowired + private JobExplorer jobExplorer; + + @Autowired + public void setDataSource(DataSource dataSource) { + this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); + } + + + @Test + public void testLaunchJob() throws Exception { + + jobLauncherTestUtils.launchJob(); + + int count = jobExplorer.getJobInstances("amqp-example-job", 0, 1).size(); + + assertTrue(count > 0); + + } + +} From 95ccb1a229dae3ab59c817c1baba4efaa5334789 Mon Sep 17 00:00:00 2001 From: Michael Minella Date: Tue, 18 Dec 2012 13:46:10 -0600 Subject: [PATCH 5/5] BATCH-1920 - Corrected pom and removed unused reference to JdbcTemplate --- spring-batch-samples/pom.xml | 2 +- .../src/main/resources/jobs/amqp-example-job.xml | 1 - .../batch/sample/AMQPJobFunctionalTests.java | 16 +++------------- 3 files changed, 4 insertions(+), 15 deletions(-) diff --git a/spring-batch-samples/pom.xml b/spring-batch-samples/pom.xml index 104dfc7fa..d98df5530 100644 --- a/spring-batch-samples/pom.xml +++ b/spring-batch-samples/pom.xml @@ -20,7 +20,7 @@ com.vmware.sqlfire sqlfireclient - 1.0.3 + true org.springframework.batch diff --git a/spring-batch-samples/src/main/resources/jobs/amqp-example-job.xml b/spring-batch-samples/src/main/resources/jobs/amqp-example-job.xml index 3c5b7ffdc..b8dba281c 100644 --- a/spring-batch-samples/src/main/resources/jobs/amqp-example-job.xml +++ b/spring-batch-samples/src/main/resources/jobs/amqp-example-job.xml @@ -9,7 +9,6 @@ http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd"> - 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 773a8eeb1..c1a10af1c 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 @@ -2,18 +2,15 @@ package org.springframework.batch.sample; import static org.junit.Assert.assertTrue; -import javax.sql.DataSource; - import org.junit.Test; import org.junit.runner.RunWith; import org.springframework.batch.core.explore.JobExplorer; import org.springframework.batch.test.JobLauncherTestUtils; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.jdbc.core.simple.SimpleJdbcTemplate; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; -/** +/** * Run the job to read from the "test.inbound" queue, process the messages and write them to the "test.outbound" queue: * mvn -q exec:java -Dexec.mainClass="org.springframework.batch.core.launch.support.CommandLineJobRunner" \ * -Dexec.arguments="classpath*:/META-INF/spring/jobs/amqp/amqp-example-job.xml,amqp-example-job" @@ -25,21 +22,14 @@ public class AMQPJobFunctionalTests { @Autowired private JobLauncherTestUtils jobLauncherTestUtils; - private SimpleJdbcTemplate simpleJdbcTemplate; @Autowired private JobExplorer jobExplorer; - - @Autowired - public void setDataSource(DataSource dataSource) { - this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource); - } - @Test public void testLaunchJob() throws Exception { - + jobLauncherTestUtils.launchJob(); - + int count = jobExplorer.getJobInstances("amqp-example-job", 0, 1).size(); assertTrue(count > 0);