diff --git a/basic/tcp-amqp/README.md b/basic/tcp-amqp/README.md new file mode 100644 index 00000000..f1a03a59 --- /dev/null +++ b/basic/tcp-amqp/README.md @@ -0,0 +1,54 @@ +Spring Integration - TCP-AMQP Sample +==================================== + +# Overview + +This sample demonstrates basic functionality of bridging **Spring Integration TCP Adapters** with **Spring Integration AMQP Adapters**. + +Once the application is started, you enter some text in a telnet session and the data is written to an AMQP queue, which is then consumed and the result echoed to a netcat session. + + telnet->tcp-inbound-adapter->rabbit->tcp-outbound-adapter->netcat + +telnet: http://en.wikipedia.org/wiki/Telnet +netcat: http://en.wikipedia.org/wiki/Netcat + +> In order to run the example you will need a running instance of RabbitMQ. A local installation with just the basic defaults will be sufficient. Please visit: [http://www.rabbitmq.com/install.html](http://www.rabbitmq.com/install.html) for detailed installation procedures. + +# How to Run the Sample + +If you imported the example into your IDE, you can just run class **org.springframework.integration.samples.tcpamqp.Main**. For example in [SpringSource Tool Suite](http://www.springsource.com/developer/sts) (STS) do: + +* Right-click on Main class --> Run As --> Java Application + +Alternatively, you can start the sample from the command line ([Maven](http://maven.apache.org/) required): + +* mvn exec:java + +In another terminal start netcat, listening on port 11112 + + netcat -l 11112 + +In another terminat, telnet to localhost:11111 + + telnet localhost 11111 + +Data typed into the telnet terminal will be echoed to the netcat terminal, via the rabbit queue. + +# Used Spring Integration components + +### Spring Integration Modules (Maven dependencies) + +* spring-integration-core +* spring-integration-amqp +* spring-integration-tcp + +# Resources + +For further help please take a look at the Spring Integration documentation: + +* [http://static.springsource.org/spring-integration/reference/htmlsingle/#amqp](http://static.springsource.org/spring-integration/reference/htmlsingle/#amqp) + +Some further resources: + +* RabbitMQ - [http://www.rabbitmq.com/](http://www.rabbitmq.com/) +* Spring AMQP - [http://www.springsource.org/spring-amqp](http://www.springsource.org/spring-amqp) diff --git a/basic/tcp-amqp/pom.xml b/basic/tcp-amqp/pom.xml new file mode 100644 index 00000000..f19b314e --- /dev/null +++ b/basic/tcp-amqp/pom.xml @@ -0,0 +1,143 @@ + + 4.0.0 + + org.springframework.integration.samples + tcp-amqp + 2.1.0.BUILD-SNAPSHOT + jar + + Samples (Basic) - TCP-AMQP + http://www.springsource.org/spring-integration + + + UTF-8 + 2.1.0.RELEASE + 1.6.4 + 4.10 + + + + + repository.springframework.maven.release + Spring Framework Maven Release Repository + http://maven.springframework.org/release + + + repository.springframework.maven.milestone + Spring Framework Maven Milestone Repository + http://maven.springframework.org/milestone + + + repository.springframework.maven.snapshot + Spring Framework Maven Snapshot Repository + http://maven.springframework.org/snapshot + + + + + + + maven-eclipse-plugin + 2.8 + + + org.springframework.ide.eclipse.core.springnature + + + org.springframework.ide.eclipse.core.springbuilder + + true + true + + + + org.apache.maven.plugins + maven-compiler-plugin + 2.3.2 + + 1.6 + 1.6 + -Xlint:all + true + true + + + + org.codehaus.mojo + exec-maven-plugin + 1.2 + + org.springframework.integration.samples.tcpamqp.Main + + + + + + + + + + + junit + junit + ${junit.version} + test + + + + + + org.springframework.integration + spring-integration-core + ${spring.integration.version} + + + + org.springframework.integration + spring-integration-amqp + ${spring.integration.version} + + + + org.springframework.integration + spring-integration-groovy + ${spring.integration.version} + + + + org.springframework.integration + spring-integration-ip + ${spring.integration.version} + + + org.springframework.amqp + spring-rabbit + 1.0.1.BUILD-SNAPSHOT + + + + + + org.slf4j + slf4j-log4j12 + ${slf4j.version} + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + log4j-over-slf4j + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + + diff --git a/basic/tcp-amqp/src/main/java/org/springframework/integration/samples/tcpamqp/Main.java b/basic/tcp-amqp/src/main/java/org/springframework/integration/samples/tcpamqp/Main.java new file mode 100644 index 00000000..87d7542c --- /dev/null +++ b/basic/tcp-amqp/src/main/java/org/springframework/integration/samples/tcpamqp/Main.java @@ -0,0 +1,72 @@ +/* + * Copyright 2002-2012 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.tcpamqp; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.context.support.AbstractApplicationContext; +import org.springframework.context.support.ClassPathXmlApplicationContext; + +/** + * Starts the Spring Context and will initialize the Spring Integration message flow. + * + * @author Gary Russell + * @version 1.0 + * + */ +public final class Main { + + private static final Logger LOGGER = LoggerFactory.getLogger(Main.class); + + private Main() { } + + /** + * Load the Spring Integration Application Context + * + * @param args - command line arguments + */ + public static void main(final String... args) throws Exception { + + 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"); + + LOGGER.info("\n=========================================================" + + "\n " + + "\n This is the TCP-AMQP Sample - " + + "\n " + + "\n Start a netcat, listening on port 11112 - " + + "\n netcat -l 11112 " + + "\n " + + "\n In another terminal, telnet to localhost 11111 " + + "\n Enter text and you will see it echoed to the netcat " + + "\n " + + "\n Press Enter in this console to terminate " + + "\n " + + "\n=========================================================" ); + + System.in.read(); + context.close(); + } +} diff --git a/basic/tcp-amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml b/basic/tcp-amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml new file mode 100644 index 00000000..1cf0a493 --- /dev/null +++ b/basic/tcp-amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basic/tcp-amqp/src/main/resources/log4j.xml b/basic/tcp-amqp/src/main/resources/log4j.xml new file mode 100644 index 00000000..f391e2ed --- /dev/null +++ b/basic/tcp-amqp/src/main/resources/log4j.xml @@ -0,0 +1,28 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file