From 14995ec2f94f85139de0f106c929f6466a340d3b Mon Sep 17 00:00:00 2001 From: Gunnar Hillert Date: Tue, 2 Apr 2013 16:24:59 -0400 Subject: [PATCH] INTEXT-61 - Add Voldemort Sample --- samples/voldemort/README.md | 63 +++++++++++ samples/voldemort/pom.xml | 99 ++++++++++++++++ .../integration/samples/voldemort/Main.java | 107 ++++++++++++++++++ .../voldemort/service/BusinessService.java | 30 +++++ .../spring-integration-context.xml | 44 +++++++ .../voldemort/src/main/resources/log4j.xml | 28 +++++ 6 files changed, 371 insertions(+) create mode 100644 samples/voldemort/README.md create mode 100644 samples/voldemort/pom.xml create mode 100644 samples/voldemort/src/main/java/org/springframework/integration/samples/voldemort/Main.java create mode 100644 samples/voldemort/src/main/java/org/springframework/integration/samples/voldemort/service/BusinessService.java create mode 100644 samples/voldemort/src/main/resources/META-INF/spring/integration/spring-integration-context.xml create mode 100644 samples/voldemort/src/main/resources/log4j.xml diff --git a/samples/voldemort/README.md b/samples/voldemort/README.md new file mode 100644 index 0000000..7580576 --- /dev/null +++ b/samples/voldemort/README.md @@ -0,0 +1,63 @@ +Spring Integration - Project Voldemort Sample +============================================= + +## Overview + +This sample illustrates the usage of the [Voldemort][] adapters provided by the [Spring Integration Extensions][] project. The samples provides 2 simple use-cases: + +1. A user-entered String is persisted to [Voldemort][] using the *Voldemort Outbound Channel Adapter*. +2. [Voldemort][] is polled every 5 seconds using the *Voldemort Inbound Channel Adapter* and the retrieved values are printed to the console using the *Logging Channel Adapter*. + +## Requirements + +This sample requires a [Voldemort][] instance to be running locally on port 6666. In case you need to customize, please modify the respective values in `src/main/resources/META-INF/spring/integration/spring-integration-context.xml`. + +```xml + + + +``` + +## How to Run the Sample + +You can run the Voldemort sample by either: + +* running the "Main" class from within STS (Right-click on Main class --> Run As --> Java Application) +* or from the command line: + - mvn package + - mvn exec:java + +Once the application is started, you will be asked to entered a String: + + 13:24:54.275 INFO [org.springframework.integration.samples.voldemort.Main.main()][org.springframework.integration.samples.voldemort.Main] + ========================================================= + + Welcome to the Spring Integration Voldemort Sample! + + For more information please visit: + http://www.springsource.org/spring-integration + + ========================================================= + 13:24:55.460 INFO [org.springframework.integration.samples.voldemort.Main.main()][org.springframework.integration.samples.voldemort.Main] + ========================================================= + + Please press 'q + Enter' to quit the application. + + ========================================================= + Please enter a string and press : myString + Persisting String: 'myString' with key 'hello'. + +Every time the Voldemort database is polled, you will the following output: + + 13:27:40.449 INFO [task-scheduler-10][org.springframework.integration.samples.voldemort] [Payload=myString][Headers={timestamp=1364923660449, id=6c861b02-5084-4606-b7bb-b1910e14598f, voldemort_key=hello}] + 13:27:45.449 INFO [task-scheduler-2][org.springframework.integration.samples.voldemort] [Payload=myString][Headers={timestamp=1364923665449, id=8f6eaecc-08ec-41eb-815b-7140d2b660a0, voldemort_key=hello}] + +-------------------------------------------------------------------------------- + +For help please take a look at the Spring Integration documentation: + +http://www.springsource.org/spring-integration + +[Spring Integration Extensions]: https://github.com/SpringSource/spring-integration-extensions +[Voldemort]: http://www.project-voldemort.com/ + diff --git a/samples/voldemort/pom.xml b/samples/voldemort/pom.xml new file mode 100644 index 0000000..151fda3 --- /dev/null +++ b/samples/voldemort/pom.xml @@ -0,0 +1,99 @@ + + 4.0.0 + + org.springframework.integration.samples + voldemort + 1.0.0.BUILD-SNAPSHOT + jar + + voldemort-sample + http://www.springsource.org/spring-integration + + + 2.2.1 + + + + UTF-8 + 1.0.0.BUILD-SNAPSHOT + 1.2.17 + 4.11 + + + + + repo.springsource.org.milestone + Spring Framework Maven Milestone Repository + https://repo.springsource.org/libs-milestone + + + + + + + maven-eclipse-plugin + 2.9 + + + org.springframework.ide.eclipse.core.springnature + + + org.springframework.ide.eclipse.core.springbuilder + + true + true + + + + org.apache.maven.plugins + maven-compiler-plugin + 3.0 + + 1.6 + 1.6 + -Xlint:all + true + true + + + + org.codehaus.mojo + exec-maven-plugin + 1.2.1 + + org.springframework.integration.samples.voldemort.Main + + + + + + + + + + + junit + junit + ${junit.version} + test + + + + + + org.springframework.integration + spring-integration-voldemort + ${spring.integration.voldemort.version} + + + + + + log4j + log4j + ${log4j.version} + + + + diff --git a/samples/voldemort/src/main/java/org/springframework/integration/samples/voldemort/Main.java b/samples/voldemort/src/main/java/org/springframework/integration/samples/voldemort/Main.java new file mode 100644 index 0000000..82cfe98 --- /dev/null +++ b/samples/voldemort/src/main/java/org/springframework/integration/samples/voldemort/Main.java @@ -0,0 +1,107 @@ +/* + * Copyright 2002-2013 the original author or authors. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.samples.voldemort; + +import java.util.Scanner; + +import org.apache.log4j.Logger; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +import org.springframework.integration.samples.voldemort.service.BusinessService; + + +/** + * Starts the Spring Context and will initialize the Spring Integration routes. + * + * @author Gunnar Hillert + * @since 1.0 + * + */ +public final class Main { + + private static final Logger LOGGER = Logger.getLogger(Main.class); + + private Main() { } + + /** + * Load the Spring Integration Application Context + * + * @param args - command line arguments + */ + public static void main(final String... args) { + + if (LOGGER.isInfoEnabled()) { + LOGGER.info("\n=========================================================" + + "\n " + + "\n Welcome to Spring Integration! " + + "\n " + + "\n For more information please visit: " + + "\n http://www.springsource.org/spring-integration " + + "\n " + + "\n=========================================================" ); + } + + final AbstractApplicationContext context = + new ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/*-context.xml"); + + context.registerShutdownHook(); + + final Scanner scanner = new Scanner(System.in); + + final BusinessService service = context.getBean(BusinessService.class); + + if (LOGGER.isInfoEnabled()) { + LOGGER.info("\n=========================================================" + + "\n " + + "\n Please press 'q + Enter' to quit the application. " + + "\n " + + "\n=========================================================" ); + } + + System.out.print("Please enter a string and press : "); + + final String key = "hello"; + + while (true) { + + final String data = scanner.nextLine(); + + if("q".equals(data.trim())) { + break; + } + + try { + + System.out.println(String.format("Persisting String: '%s' with key '%s'.", data, key)); + service.saveData(key, data); + + } catch (Exception e) { + LOGGER.error("An exception was caught: " + e); + } + + System.out.print("Please enter a string and press :"); + + } + + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Exiting application...bye."); + } + + System.exit(0); + + } +} diff --git a/samples/voldemort/src/main/java/org/springframework/integration/samples/voldemort/service/BusinessService.java b/samples/voldemort/src/main/java/org/springframework/integration/samples/voldemort/service/BusinessService.java new file mode 100644 index 0000000..8c78a67 --- /dev/null +++ b/samples/voldemort/src/main/java/org/springframework/integration/samples/voldemort/service/BusinessService.java @@ -0,0 +1,30 @@ +/* + * Copyright 2002-2013 the original author or authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.springframework.integration.samples.voldemort.service; + +import org.springframework.integration.annotation.Header; + +/** + * + * @author Gunnar Hillert + * @since 1.0 + * + */ +public interface BusinessService { + + String saveData(@Header("voldemort_key") String key, String stringToPersist); + +} diff --git a/samples/voldemort/src/main/resources/META-INF/spring/integration/spring-integration-context.xml b/samples/voldemort/src/main/resources/META-INF/spring/integration/spring-integration-context.xml new file mode 100644 index 0000000..fbe1027 --- /dev/null +++ b/samples/voldemort/src/main/resources/META-INF/spring/integration/spring-integration-context.xml @@ -0,0 +1,44 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/samples/voldemort/src/main/resources/log4j.xml b/samples/voldemort/src/main/resources/log4j.xml new file mode 100644 index 0000000..dfe6fcf --- /dev/null +++ b/samples/voldemort/src/main/resources/log4j.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + +