Skip to content

Commit

Permalink
Barrier: Use Boot AutoConfig for RabbitMQ
Browse files Browse the repository at this point in the history
Also support a browser GET.
  • Loading branch information
garyrussell authored and artembilan committed Sep 21, 2015
1 parent ecab656 commit 23f4a04
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 15 deletions.
5 changes: 5 additions & 0 deletions basic/barrier/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@
<version>4.2.0.RELEASE</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,30 @@

package org.springframework.integration.samples.barrier;

import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.context.ConfigurableApplicationContext;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.ImportResource;

/**
* @author Gary Russell
* @since 4.2
*/
@Configuration
@EnableAutoConfiguration
@SpringBootApplication
@ImportResource("/META-INF/spring/integration/server-context.xml")
public class Application {

public static void main(String[] args) throws Exception {
ConfigurableApplicationContext server = SpringApplication.run(Application.class, args);

// https://github.com/spring-projects/spring-boot/issues/3945
CachingConnectionFactory connectionFactory = server.getBean(CachingConnectionFactory.class);
connectionFactory.setPublisherConfirms(true);
connectionFactory.resetConnection();
// https://github.com/spring-projects/spring-boot/issues/3945

ConfigurableApplicationContext client
= new SpringApplicationBuilder("/META-INF/spring/integration/client-context.xml")
.web(false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,14 @@
<int:channel id="requestChannel"/>

<int-http:outbound-gateway request-channel="requestChannel"
url="http://localhost:8080/receiveGateway"
url="#{url}"
http-method="POST"
expected-response-type="java.lang.String"/>

<beans profile="default">
<bean id="url" class="java.lang.String">
<constructor-arg value="http://localhost:8080/postGateway" />
</bean>
</beans>

</beans>
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,17 @@
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">

<int-http:inbound-gateway request-channel="receiveChannel"
path="/receiveGateway"
path="/postGateway"
error-channel="errorChannel"
supported-methods="POST"/>

<int-http:inbound-gateway request-channel="createPayload"
path="/getGateway"
error-channel="errorChannel"
supported-methods="GET"/>

<int:transformer input-channel="createPayload" output-channel="receiveChannel" expression="'A,B,C'" />

<int:channel id="receiveChannel" />

<int:header-enricher input-channel="receiveChannel" output-channel="processChannel">
Expand All @@ -28,7 +35,7 @@
<int:chain input-channel="processChannel" order="1">
<int:header-filter header-names="content-type, content-length" />
<int:splitter delimiters="," />
<int-amqp:outbound-channel-adapter amqp-template="amqpTemplate"
<int-amqp:outbound-channel-adapter amqp-template="rabbitTemplate"
exchange-name="barrier.sample.exchange" routing-key="barrier.sample.key"
confirm-ack-channel="confirmations"
confirm-nack-channel="confirmations"
Expand Down Expand Up @@ -62,17 +69,10 @@

<int-amqp:inbound-channel-adapter channel="nullChannel"
queue-names="barrier.sample.queue"
connection-factory="connectionFactory" />
connection-factory="rabbitConnectionFactory" />

<!-- Infrastructure -->

<rabbit:connection-factory id="connectionFactory" host="localhost" publisher-confirms="true"
publisher-returns="true"/>

<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" mandatory="true" />

<rabbit:admin connection-factory="connectionFactory" />

<rabbit:queue name="barrier.sample.queue" auto-delete="true" />

<rabbit:direct-exchange name="barrier.sample.exchange" auto-delete="true">
Expand Down
5 changes: 5 additions & 0 deletions basic/barrier/src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@
<root level="warn">
<appender-ref ref="STDOUT" />
</root>

<logger name="org.springframework" level="WARN" />
<logger name="org.springframework.integration" level="WARN" />
<logger name="org.springframework.amqp" level="WARN" />

</configuration>
1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ project('barrier') {
dependencies {
compile 'org.springframework.boot:spring-boot-starter-web'
compile 'org.springframework.boot:spring-boot-starter-integration'
compile 'org.springframework.boot:spring-boot-starter-amqp'
compile "org.springframework.integration:spring-integration-core:$springIntegrationVersion"
compile "org.springframework.integration:spring-integration-amqp:$springIntegrationVersion"
compile "org.springframework.integration:spring-integration-http:$springIntegrationVersion"
Expand Down

0 comments on commit 23f4a04

Please sign in to comment.