Last active
August 29, 2015 13:56
-
-
Save garyrussell/8888626 to your computer and use it in GitHub Desktop.
Spring Boot App Using Spring Integration AMQP
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
/* | |
* Copyright 2014 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 foo; | |
public interface Gate { | |
void send(String out); | |
String result(); | |
} |
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
<?xml version="1.0" encoding="UTF-8"?> | |
<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>foo</groupId> | |
<artifactId>amqpboot</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<!-- Inherit defaults from Spring Boot --> | |
<parent> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-parent</artifactId> | |
<version>1.0.0.RC1</version> | |
</parent> | |
<properties> | |
<spring.integration.version>4.0.0.M3</spring.integration.version> | |
<spring.version>4.0.1.RELEASE</spring.version> | |
</properties> | |
<!-- Add typical dependencies for a web application --> | |
<dependencies> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-web</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-amqp</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-starter-integration</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework</groupId> | |
<artifactId>spring-messaging</artifactId> | |
<version>${spring.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.integration</groupId> | |
<artifactId>spring-integration-core</artifactId> | |
<version>${spring.integration.version}</version> | |
</dependency> | |
<dependency> | |
<groupId>org.springframework.integration</groupId> | |
<artifactId>spring-integration-amqp</artifactId> | |
<version>${spring.integration.version}</version> | |
</dependency> | |
</dependencies> | |
<!-- Package as an executable JAR --> | |
<build> | |
<plugins> | |
<plugin> | |
<groupId>org.springframework.boot</groupId> | |
<artifactId>spring-boot-maven-plugin</artifactId> | |
</plugin> | |
</plugins> | |
</build> | |
<!-- Allow access to Spring milestones and snapshots --> | |
<!-- (you don't need this if you are using anything after 1.0.0.RELEASE) --> | |
<repositories> | |
<repository> | |
<id>spring-snapshots</id> | |
<url>http://repo.spring.io/snapshot</url> | |
<snapshots><enabled>true</enabled></snapshots> | |
</repository> | |
<repository> | |
<id>spring-milestones</id> | |
<url>http://repo.spring.io/milestone</url> | |
<snapshots><enabled>true</enabled></snapshots> | |
</repository> | |
</repositories> | |
<pluginRepositories> | |
<pluginRepository> | |
<id>spring-snapshots</id> | |
<url>http://repo.spring.io/snapshot</url> | |
</pluginRepository> | |
<pluginRepository> | |
<id>spring-milestones</id> | |
<url>http://repo.spring.io/milestone</url> | |
</pluginRepository> | |
</pluginRepositories> | |
</project> |
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
/* | |
* Copyright 2014 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 foo; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.EnableAutoConfiguration; | |
import org.springframework.context.annotation.ImportResource; | |
import org.springframework.stereotype.Controller; | |
import org.springframework.web.bind.annotation.RequestMapping; | |
import org.springframework.web.bind.annotation.ResponseBody; | |
@Controller | |
@EnableAutoConfiguration | |
@ImportResource("foo/si-context.xml") | |
public class SampleController { | |
@Autowired | |
private Gate gate; | |
@RequestMapping("/") | |
@ResponseBody | |
String home() throws Exception { | |
gate.send("Hello, world!"); | |
return gate.result(); | |
} | |
public static void main(String[] args) throws Exception { | |
SpringApplication.run(SampleController.class, args); | |
} | |
} |
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
<?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-amqp="http://www.springframework.org/schema/integration/amqp" | |
xmlns:rabbit="http://www.springframework.org/schema/rabbit" | |
xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd | |
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd | |
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.2.xsd | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | |
<int:gateway default-request-channel="out" | |
default-reply-channel="in" default-reply-timeout="1000" | |
service-interface="foo.Gate" /> | |
<int:channel id="out" /> | |
<int-amqp:outbound-channel-adapter | |
channel="out" | |
amqp-template="rabbitTemplate" | |
exchange-name="ex" routing-key="foo" /> | |
<rabbit:queue id="queue" /> <!-- anon, auto-delete --> | |
<rabbit:direct-exchange name="ex" auto-delete="true"> | |
<rabbit:bindings> | |
<rabbit:binding queue="queue" key="foo"/> | |
</rabbit:bindings> | |
</rabbit:direct-exchange> | |
<rabbit:admin id="admin" connection-factory="rabbitConnectionFactory" /> | |
<int-amqp:inbound-channel-adapter queue-names="#{queue.name}" channel="in" /> | |
<int:channel id="in"> | |
<int:queue /> | |
</int:channel> | |
</beans> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment