forked from spring-projects/spring-integration-extensions
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request spring-projects#20 from lukasz-antoniak/INTEXT-36
* lukasz-antoniak-INTEXT-36: INTEXT-61 - Add Voldemort Sample INTEXT-36 - Cleanup INTEXT-36 - Add Voldemort Module
- Loading branch information
Showing
67 changed files
with
4,228 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 | ||
<bean id="config" class="voldemort.client.ClientConfig"> | ||
<property name="bootstrapUrls" value="tcp://localhost:6666" /> | ||
</bean> | ||
``` | ||
|
||
## 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 <enter>: 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/ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<groupId>org.springframework.integration.samples</groupId> | ||
<artifactId>voldemort</artifactId> | ||
<version>1.0.0.BUILD-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>voldemort-sample</name> | ||
<url>http://www.springsource.org/spring-integration</url> | ||
|
||
<prerequisites> | ||
<maven>2.2.1</maven> | ||
</prerequisites> | ||
|
||
<properties> | ||
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||
<spring.integration.voldemort.version>1.0.0.BUILD-SNAPSHOT</spring.integration.voldemort.version> | ||
<log4j.version>1.2.17</log4j.version> | ||
<junit.version>4.11</junit.version> | ||
</properties> | ||
|
||
<repositories> | ||
<repository> | ||
<id>repo.springsource.org.milestone</id> | ||
<name>Spring Framework Maven Milestone Repository</name> | ||
<url>https://repo.springsource.org/libs-milestone</url> | ||
</repository> | ||
</repositories> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-eclipse-plugin</artifactId> | ||
<version>2.9</version> | ||
<configuration> | ||
<additionalProjectnatures> | ||
<projectnature>org.springframework.ide.eclipse.core.springnature</projectnature> | ||
</additionalProjectnatures> | ||
<additionalBuildcommands> | ||
<buildcommand>org.springframework.ide.eclipse.core.springbuilder</buildcommand> | ||
</additionalBuildcommands> | ||
<downloadSources>true</downloadSources> | ||
<downloadJavadocs>true</downloadJavadocs> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
<version>3.0</version> | ||
<configuration> | ||
<source>1.6</source> | ||
<target>1.6</target> | ||
<compilerArgument>-Xlint:all</compilerArgument> | ||
<showWarnings>true</showWarnings> | ||
<showDeprecation>true</showDeprecation> | ||
</configuration> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.codehaus.mojo</groupId> | ||
<artifactId>exec-maven-plugin</artifactId> | ||
<version>1.2.1</version> | ||
<configuration> | ||
<mainClass>org.springframework.integration.samples.voldemort.Main</mainClass> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
|
||
<dependencies> | ||
|
||
<!-- Testing --> | ||
|
||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${junit.version}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<!-- Spring Integration --> | ||
|
||
<dependency> | ||
<groupId>org.springframework.integration</groupId> | ||
<artifactId>spring-integration-voldemort</artifactId> | ||
<version>${spring.integration.voldemort.version}</version> | ||
</dependency> | ||
|
||
<!-- Logging --> | ||
|
||
<dependency> | ||
<groupId>log4j</groupId> | ||
<artifactId>log4j</artifactId> | ||
<version>${log4j.version}</version> | ||
</dependency> | ||
|
||
</dependencies> | ||
</project> |
107 changes: 107 additions & 0 deletions
107
samples/voldemort/src/main/java/org/springframework/integration/samples/voldemort/Main.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 <enter>: "); | ||
|
||
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 <enter>:"); | ||
|
||
} | ||
|
||
if (LOGGER.isInfoEnabled()) { | ||
LOGGER.info("Exiting application...bye."); | ||
} | ||
|
||
System.exit(0); | ||
|
||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
.../main/java/org/springframework/integration/samples/voldemort/service/BusinessService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
|
||
} |
44 changes: 44 additions & 0 deletions
44
...s/voldemort/src/main/resources/META-INF/spring/integration/spring-integration-context.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:int="http://www.springframework.org/schema/integration" | ||
xmlns:int-voldemort="http://www.springframework.org/schema/integration/voldemort" | ||
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-2.2.xsd | ||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/integration/voldemort http://www.springframework.org/schema/integration/voldemort/spring-integration-voldemort.xsd"> | ||
|
||
<int:channel id="requestChannel"/> | ||
|
||
<!-- See also: | ||
http://static.springsource.org/spring-integration/reference/htmlsingle/#gateway-proxy | ||
http://www.eaipatterns.com/MessagingGateway.html --> | ||
<int:gateway id="gateway" | ||
default-request-timeout="5000" | ||
default-reply-timeout="5000" | ||
default-request-channel="requestChannel" | ||
service-interface="org.springframework.integration.samples.voldemort.service.BusinessService"> | ||
<int:method name="saveData"/> | ||
</int:gateway> | ||
|
||
<bean id="config" class="voldemort.client.ClientConfig"> | ||
<property name="bootstrapUrls" value="tcp://localhost:6666" /> | ||
</bean> | ||
|
||
<bean id="clientFactory" class="voldemort.client.SocketStoreClientFactory" destroy-method="close"> | ||
<constructor-arg name="config" ref="config" /> | ||
</bean> | ||
|
||
<bean id="storeClient" factory-bean="clientFactory" factory-method="getStoreClient"> | ||
<constructor-arg value="test" /> | ||
</bean> | ||
|
||
<int-voldemort:outbound-channel-adapter store-client="storeClient" | ||
channel="requestChannel" /> | ||
|
||
<int-voldemort:inbound-channel-adapter store-client="storeClient" search-key="hello" | ||
channel="loggit" > | ||
<int:poller fixed-rate="5000"/> | ||
</int-voldemort:inbound-channel-adapter> | ||
|
||
<int:logging-channel-adapter id="loggit" log-full-message="true" logger-name="org.springframework.integration.samples.voldemort"/> | ||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd"> | ||
<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> | ||
|
||
<!-- Appenders --> | ||
<appender name="console" class="org.apache.log4j.ConsoleAppender"> | ||
<param name="Target" value="System.out" /> | ||
<layout class="org.apache.log4j.PatternLayout"> | ||
<param name="ConversionPattern" value="%d{HH:mm:ss.SSS} %-5p [%t][%c] %m%n" /> | ||
</layout> | ||
</appender> | ||
|
||
<!-- Loggers --> | ||
<logger name="org.springframework.integration"> | ||
<level value="warn" /> | ||
</logger> | ||
|
||
<logger name="org.springframework.integration.samples.voldemort"> | ||
<level value="info" /> | ||
</logger> | ||
|
||
<!-- Root Logger --> | ||
<root> | ||
<priority value="warn" /> | ||
<appender-ref ref="console" /> | ||
</root> | ||
|
||
</log4j:configuration> |
Oops, something went wrong.