From a24994dc1cabb03e854fb1741d2bb6e2e6f9b2c7 Mon Sep 17 00:00:00 2001 From: Gunnar Hillert Date: Mon, 22 Aug 2011 13:04:41 -0400 Subject: [PATCH] INTSAMPLES-30 - initial commit of the AMQP Sample Added .DS_Store to .gitignore Removed the image as it is problematic with Github. Will be added to the SI AMQP reference documentation instead Removed a ":" from the readme Removed a class that was not used anymore polishing --- .gitignore | 1 + README.md | 1 + basic/amqp/README.md | 52 ++++++++ basic/amqp/pom.xml | 122 ++++++++++++++++++ .../integration/samples/amqp/Main.java | 70 ++++++++++ .../service/StringConversionService.java | 31 +++++ .../spring-integration-context.xml | 54 ++++++++ basic/amqp/src/main/resources/logback.xml | 24 ++++ 8 files changed, 355 insertions(+) create mode 100644 basic/amqp/README.md create mode 100644 basic/amqp/pom.xml create mode 100644 basic/amqp/src/main/java/org/springframework/integration/samples/amqp/Main.java create mode 100644 basic/amqp/src/main/java/org/springframework/integration/service/StringConversionService.java create mode 100644 basic/amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml create mode 100644 basic/amqp/src/main/resources/logback.xml diff --git a/.gitignore b/.gitignore index ed11aa81..a32372f3 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ target/ log.roo .project .classpath +.DS_Store diff --git a/README.md b/README.md index 74547be9..81c293db 100644 --- a/README.md +++ b/README.md @@ -22,6 +22,7 @@ Below is a short description of each category. This is a good place to get started. The samples here are technically motivated and demonstrate the bare minimum with regard to configuration and code to help you to get introduced to the basic concepts, API and configuration of Spring Integration. For example, if you are looking for an answer on how to wire a **Service Activator** to a **Channel** or how to apply a **Gateway** to your message exchange or how to get started with using the **MAIL** or **XML** module, this would be the right place to find a relevant sample. The bottom line is that this is a good starting point. +* **amqp** - demonstrates the functionality of the various **AMQP Adapters** * **control-bus** - demonstrates the functionality of the **Control Bus** * **feed** - demonstrates the functionality of the **Feed Adapter** (RSS/ATOM) * **file** - demonstrates aspects of the various File Adapters (e.g. **File Inbound/Outbound Channel Adapters**, file **polling**) diff --git a/basic/amqp/README.md b/basic/amqp/README.md new file mode 100644 index 00000000..280774d3 --- /dev/null +++ b/basic/amqp/README.md @@ -0,0 +1,52 @@ +Spring Integration - AMQP Sample +================================ + +# Overview + +This sample demonstrates basic functionality of the **Spring Integration AMQP Adapter**, which uses the [Advanced Message Queuing Protocol](http://www.amqp.org/) (AMQP) to send and retrieve messages. As AMQP Broker implementation the sample uses [RabbitMQ](http://www.rabbitmq.com/). + +Once the application is started, you enter some text on the command prompt and a message containing that entered text is dispatched to the AMQP queue. In return that message is retrieved by Spring Integration and then printed to the console. + +> 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.amqp.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 package +* mvn exec:java + +# Used Spring Integration components + +### Spring Integration Modules (Maven dependencies) + +* spring-integration-core +* spring-integration-amqp +* spring-integration-stream + +### Spring Integration Adapters + +* int-stream:stdin-channel-adapter +* **int-amqp:outbound-channel-adapter** +* **int-amqp:inbound-channel-adapter** +* int-stream:stdout-channel-adapter +* int:poller +* int:channel +* int:interceptors +* int:wire-tap +* logging-channel-adapter + +# 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/amqp/pom.xml b/basic/amqp/pom.xml new file mode 100644 index 00000000..a605186c --- /dev/null +++ b/basic/amqp/pom.xml @@ -0,0 +1,122 @@ + + 4.0.0 + + org.springframework.integration.samples + amqp + 2.1-SNAPSHOT + jar + + amqp + http://www.springsource.org/spring-integration + + + UTF-8 + 2.1.0.BUILD-SNAPSHOT + 1.6.1 + 4.7 + + + + + repository.springframework.maven.release + Spring Framework Maven Release Repository + http://maven.springframework.org/release + + + + + + + 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.amqp.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-stream + ${spring.integration.version} + + + + + + ch.qos.logback + logback-classic + 0.9.28 + + + org.slf4j + slf4j-api + ${slf4j.version} + + + org.slf4j + log4j-over-slf4j + ${slf4j.version} + + + org.slf4j + jcl-over-slf4j + ${slf4j.version} + + + + diff --git a/basic/amqp/src/main/java/org/springframework/integration/samples/amqp/Main.java b/basic/amqp/src/main/java/org/springframework/integration/samples/amqp/Main.java new file mode 100644 index 00000000..18451051 --- /dev/null +++ b/basic/amqp/src/main/java/org/springframework/integration/samples/amqp/Main.java @@ -0,0 +1,70 @@ +/* + * Copyright 2002-2011 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.amqp; + +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 Gunnar Hillert + * @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) { + + 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(); + + LOGGER.info("\n=========================================================" + + "\n " + + "\n This is the AMQP Sample - " + + "\n " + + "\n Please enter some text and press return. The entered " + + "\n Message will be sent to the configured RabbitMQ Queue," + + "\n then again immediately retrieved from the Message " + + "\n Broker and ultimately printed to the command line. " + + "\n " + + "\n=========================================================" ); + + } +} diff --git a/basic/amqp/src/main/java/org/springframework/integration/service/StringConversionService.java b/basic/amqp/src/main/java/org/springframework/integration/service/StringConversionService.java new file mode 100644 index 00000000..c0434b24 --- /dev/null +++ b/basic/amqp/src/main/java/org/springframework/integration/service/StringConversionService.java @@ -0,0 +1,31 @@ +/* + * Copyright 2002-2010 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.service; + +/** + * Provides string manipulation services. + */ +public interface StringConversionService { + + /** + * Converts a String to Upper Case. + * + * @param stringToConvert The string to convert to upper case + * @return The converted upper case string. + */ + String convertToUpperCase(String stringToConvert); + +} diff --git a/basic/amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml b/basic/amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml new file mode 100644 index 00000000..598fc3cf --- /dev/null +++ b/basic/amqp/src/main/resources/META-INF/spring/integration/spring-integration-context.xml @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/basic/amqp/src/main/resources/logback.xml b/basic/amqp/src/main/resources/logback.xml new file mode 100644 index 00000000..2bbecb62 --- /dev/null +++ b/basic/amqp/src/main/resources/logback.xml @@ -0,0 +1,24 @@ + + + + + + + %d %5p | %t | %-55logger{55} | %m %n + + + + + + + + + + + + + + + + +