Add configurable port to ConnectionFactory and convert XML to use XSD
This commit is contained in:
@@ -23,6 +23,7 @@ import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
|
||||
import org.springframework.amqp.rabbit.core.RabbitTemplate;
|
||||
import org.springframework.amqp.support.converter.JsonMessageConverter;
|
||||
import org.springframework.amqp.support.converter.MessageConverter;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@@ -52,6 +53,9 @@ public abstract class AbstractStockAppRabbitConfiguration extends AbstractRabbit
|
||||
*/
|
||||
protected static String STOCK_REQUEST_ROUTING_KEY = STOCK_REQUEST_QUEUE_NAME;
|
||||
|
||||
@Value("${amqp.port:5672}")
|
||||
private int port = 5672;
|
||||
|
||||
|
||||
protected abstract void configureRabbitTemplate(RabbitTemplate template);
|
||||
|
||||
@@ -61,6 +65,7 @@ public abstract class AbstractStockAppRabbitConfiguration extends AbstractRabbit
|
||||
CachingConnectionFactory connectionFactory = new CachingConnectionFactory("localhost");
|
||||
connectionFactory.setUsername("guest");
|
||||
connectionFactory.setPassword("guest");
|
||||
connectionFactory.setPort(port);
|
||||
return connectionFactory;
|
||||
}
|
||||
|
||||
|
||||
@@ -1,23 +1,17 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<bean id="stockServiceGateway" class="org.springframework.amqp.rabbit.stocks.gateway.RabbitStockServiceGateway">
|
||||
<property name="rabbitTemplate" ref="rabbitTemplate" />
|
||||
<property name="defaultReplyToQueue" value="#{traderJoeQueue.name}" />
|
||||
</bean>
|
||||
|
||||
<bean id="messageListenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
|
||||
<property name="connectionFactory" ref="connectionFactory" />
|
||||
<property name="queueName" value="#{marketDataQueue.name},#{traderJoeQueue.name}"/>
|
||||
<property name="concurrentConsumers" value="5" />
|
||||
<property name="messageListener" ref="messageListenerAdapter" />
|
||||
</bean>
|
||||
|
||||
<bean id="messageListenerAdapter" class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
|
||||
<property name="delegate" ref="clientHandler" />
|
||||
<property name="messageConverter" ref="jsonMessageConverter" />
|
||||
</bean>
|
||||
<listener-container concurrency="5" connection-factory="connectionFactory" message-converter="jsonMessageConverter"
|
||||
xmlns="http://www.springframework.org/schema/rabbit">
|
||||
<listener ref="clientHandler" method="handleMessage" queue-names="#{marketDataQueue.name},#{traderJoeQueue.name}" />
|
||||
</listener-container>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -7,6 +7,8 @@
|
||||
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:property-placeholder system-properties-mode="OVERRIDE"/>
|
||||
|
||||
<!-- pick up rabbit broker configuration -->
|
||||
<context:component-scan base-package="org.springframework.amqp.rabbit.stocks.config.server"/>
|
||||
|
||||
|
||||
@@ -1,22 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
|
||||
|
||||
<bean id="marketDataGateway" class="org.springframework.amqp.rabbit.stocks.gateway.RabbitMarketDataGateway">
|
||||
<property name="rabbitTemplate" ref="rabbitTemplate" />
|
||||
</bean>
|
||||
|
||||
<bean id="messageListenerContainer" class="org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer">
|
||||
<property name="connectionFactory" ref="connectionFactory" />
|
||||
<property name="queueName" value="#{stockRequestQueue.name}" />
|
||||
<property name="concurrentConsumers" value="5" />
|
||||
<property name="messageListener" ref="messageListenerAdapter" />
|
||||
</bean>
|
||||
|
||||
<bean id="messageListenerAdapter" class="org.springframework.amqp.rabbit.listener.adapter.MessageListenerAdapter">
|
||||
<property name="delegate" ref="serverHandler" />
|
||||
<property name="messageConverter" ref="jsonMessageConverter" />
|
||||
</bean>
|
||||
<listener-container concurrency="5" connection-factory="connectionFactory" message-converter="jsonMessageConverter"
|
||||
xmlns="http://www.springframework.org/schema/rabbit">
|
||||
<listener ref="serverHandler" method="handleMessage" queue-names="#{stockRequestQueue.name}" />
|
||||
</listener-container>
|
||||
|
||||
</beans>
|
||||
|
||||
@@ -1,19 +1,18 @@
|
||||
<?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:context="http://www.springframework.org/schema/context"
|
||||
xmlns:mvc="http://www.springframework.org/schema/mvc" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:context="http://www.springframework.org/schema/context" xmlns:mvc="http://www.springframework.org/schema/mvc"
|
||||
xmlns:rabbit="http://www.springframework.org/schema/rabbit"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd
|
||||
http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit-1.0.xsd
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<bean id="stockServiceGateway"
|
||||
class="org.springframework.amqp.rabbit.stocks.gateway.RabbitStockServiceGateway">
|
||||
<bean id="stockServiceGateway" class="org.springframework.amqp.rabbit.stocks.gateway.RabbitStockServiceGateway">
|
||||
<property name="rabbitTemplate">
|
||||
<bean class="org.springframework.amqp.rabbit.core.RabbitTemplate">
|
||||
<property name="connectionFactory" ref="connectionFactory" />
|
||||
<property name="routingKey" value="app.stock.request" />
|
||||
<property name="messageConverter" ref="jsonMessageConverter"/>
|
||||
<property name="messageConverter" ref="jsonMessageConverter" />
|
||||
</bean>
|
||||
</property>
|
||||
<property name="defaultReplyToQueue" ref="tradeQueue" />
|
||||
@@ -35,26 +34,23 @@
|
||||
</bindings>
|
||||
</topic-exchange>
|
||||
|
||||
<listener-container
|
||||
connection-factory="connectionFactory" message-converter="jsonMessageConverter" xmlns="http://www.springframework.org/schema/rabbit">
|
||||
<listener-container connection-factory="connectionFactory" message-converter="jsonMessageConverter"
|
||||
xmlns="http://www.springframework.org/schema/rabbit">
|
||||
<listener ref="quoteController" method="handleQuote" queue-names="marketDataQueue" />
|
||||
<listener ref="quoteController" method="handleTrade" queue-names="tradeQueue" />
|
||||
</listener-container>
|
||||
|
||||
<rabbit:admin connection-factory="connectionFactory"/>
|
||||
|
||||
<bean id="connectionFactory"
|
||||
class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory" />
|
||||
<rabbit:admin connection-factory="connectionFactory" />
|
||||
|
||||
<bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.CachingConnectionFactory" />
|
||||
|
||||
<context:property-placeholder location="classpath:/client.properties" />
|
||||
|
||||
<bean id="quoteController"
|
||||
class="org.springframework.amqp.rabbit.stocks.web.QuoteController">
|
||||
<bean id="quoteController" class="org.springframework.amqp.rabbit.stocks.web.QuoteController">
|
||||
<property name="stockServiceGateway" ref="stockServiceGateway" />
|
||||
</bean>
|
||||
|
||||
<mvc:resources location="file:./src/main/resources/static/,classpath:/static/"
|
||||
mapping="static/**" />
|
||||
<mvc:resources location="file:./src/main/resources/static/,classpath:/static/" mapping="static/**" />
|
||||
|
||||
<mvc:default-servlet-handler />
|
||||
|
||||
|
||||
Reference in New Issue
Block a user