Barrier: Use Boot AutoConfig for RabbitMQ
Also support a browser GET.
This commit is contained in:
committed by
Artem Bilan
parent
ecab656cc1
commit
23f4a04661
@@ -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>
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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">
|
||||
@@ -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"
|
||||
@@ -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">
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user