From e522dbddad76ced178978eb4e15765ba5efbf50d Mon Sep 17 00:00:00 2001 From: Bjorn Harvold Date: Sun, 8 Feb 2015 14:35:14 +0700 Subject: [PATCH] Web Socket configuration now works with CF --- .idea/workspace.xml | 277 ++++++++++++------ .../bearchoke-platform-base.iml | 4 +- .../bearchoke-platform-base/pom.xml | 4 +- .../base/config/RabbitMQCloudConfig.java | 2 + .../main/resources/rabbit-cloud.properties | 20 ++ .../main/resources/rabbit-local.properties | 3 +- .../bearchoke-server/manifest.yml | 2 +- .../server/config/WebSocketConfig.java | 15 +- 8 files changed, 228 insertions(+), 99 deletions(-) create mode 100644 bearchoke-backend/bearchoke-platform-base/src/main/resources/rabbit-cloud.properties diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 81ee56c..76b8c5b 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -447,7 +447,7 @@ - + @@ -456,21 +456,61 @@ - - + + - - + + - - + + - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + @@ -481,11 +521,6 @@ @@ -629,6 +669,7 @@ + @@ -797,9 +838,68 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - @@ -826,11 +926,11 @@ + - @@ -1406,11 +1506,12 @@ + - @@ -1437,15 +1538,15 @@ - + - + + - @@ -1496,63 +1597,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1826,13 +1870,6 @@ - - - - - - - @@ -1851,30 +1888,86 @@ - + - - + + - + - - + + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/bearchoke-backend/bearchoke-platform-base/bearchoke-platform-base.iml b/bearchoke-backend/bearchoke-platform-base/bearchoke-platform-base.iml index fe1c38f..db54712 100644 --- a/bearchoke-backend/bearchoke-platform-base/bearchoke-platform-base.iml +++ b/bearchoke-backend/bearchoke-platform-base/bearchoke-platform-base.iml @@ -21,8 +21,8 @@ - - + + diff --git a/bearchoke-backend/bearchoke-platform-base/pom.xml b/bearchoke-backend/bearchoke-platform-base/pom.xml index f090391..bba5ece 100644 --- a/bearchoke-backend/bearchoke-platform-base/pom.xml +++ b/bearchoke-backend/bearchoke-platform-base/pom.xml @@ -247,8 +247,8 @@ stax - stax-ri - 1.0 + stax-api + 1.0.1 com.cenqua.clover diff --git a/bearchoke-backend/bearchoke-platform-base/src/main/java/com/bearchoke/platform/base/config/RabbitMQCloudConfig.java b/bearchoke-backend/bearchoke-platform-base/src/main/java/com/bearchoke/platform/base/config/RabbitMQCloudConfig.java index 51be470..5f19b29 100644 --- a/bearchoke-backend/bearchoke-platform-base/src/main/java/com/bearchoke/platform/base/config/RabbitMQCloudConfig.java +++ b/bearchoke-backend/bearchoke-platform-base/src/main/java/com/bearchoke/platform/base/config/RabbitMQCloudConfig.java @@ -22,9 +22,11 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; +import org.springframework.context.annotation.PropertySource; @Configuration @Profile("rabbit-cloud") +@PropertySource(value = "classpath:rabbit-cloud.properties") @Slf4j public class RabbitMQCloudConfig extends AbstractCloudConfig { diff --git a/bearchoke-backend/bearchoke-platform-base/src/main/resources/rabbit-cloud.properties b/bearchoke-backend/bearchoke-platform-base/src/main/resources/rabbit-cloud.properties new file mode 100644 index 0000000..abee4b3 --- /dev/null +++ b/bearchoke-backend/bearchoke-platform-base/src/main/resources/rabbit-cloud.properties @@ -0,0 +1,20 @@ +# +# 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. +# + +rabbitmq.host=tiger.cloudamqp.com +rabbitmq.username=uetwdtmj +rabbitmq.password=6pKR5W2qQ9UXM9M5LIrG1jMTPF9HDU99 +rabbitmq.virtualhost=uetwdtmj \ No newline at end of file diff --git a/bearchoke-backend/bearchoke-platform-base/src/main/resources/rabbit-local.properties b/bearchoke-backend/bearchoke-platform-base/src/main/resources/rabbit-local.properties index 319d66c..2442149 100644 --- a/bearchoke-backend/bearchoke-platform-base/src/main/resources/rabbit-local.properties +++ b/bearchoke-backend/bearchoke-platform-base/src/main/resources/rabbit-local.properties @@ -17,4 +17,5 @@ rabbitmq.host=localhost rabbitmq.port=5672 rabbitmq.username=guest -rabbitmq.password=guest \ No newline at end of file +rabbitmq.password=guest +rabbitmq.virtualhost=/ \ No newline at end of file diff --git a/bearchoke-backend/bearchoke-server/manifest.yml b/bearchoke-backend/bearchoke-server/manifest.yml index 7cd1929..428a526 100644 --- a/bearchoke-backend/bearchoke-server/manifest.yml +++ b/bearchoke-backend/bearchoke-server/manifest.yml @@ -1,7 +1,7 @@ --- applications: - name: bearchoke-server - memory: 1G + memory: 2G instances: 1 host: bearchoke-server path: target/bearchoke-server-0.0.1-SNAPSHOT.war diff --git a/bearchoke-backend/bearchoke-server/src/main/java/com/bearchoke/platform/server/config/WebSocketConfig.java b/bearchoke-backend/bearchoke-server/src/main/java/com/bearchoke/platform/server/config/WebSocketConfig.java index 9745384..37f30bd 100644 --- a/bearchoke-backend/bearchoke-server/src/main/java/com/bearchoke/platform/server/config/WebSocketConfig.java +++ b/bearchoke-backend/bearchoke-server/src/main/java/com/bearchoke/platform/server/config/WebSocketConfig.java @@ -27,6 +27,7 @@ import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.core.env.Environment; import org.springframework.http.HttpHeaders; import org.springframework.http.server.ServerHttpRequest; import org.springframework.http.server.ServerHttpResponse; @@ -38,6 +39,7 @@ import org.springframework.messaging.simp.SimpMessageSendingOperations; import org.springframework.messaging.simp.config.ChannelRegistration; import org.springframework.messaging.simp.config.MessageBrokerRegistry; +import org.springframework.messaging.simp.config.StompBrokerRelayRegistration; import org.springframework.messaging.simp.stomp.StompCommand; import org.springframework.messaging.simp.stomp.StompHeaderAccessor; import org.springframework.messaging.support.ChannelInterceptorAdapter; @@ -70,6 +72,9 @@ @Slf4j public class WebSocketConfig extends AbstractSessionWebSocketMessageBrokerConfigurer { + @Inject + private Environment environment; + @Inject private CustomObjectMapper objectMapper; @@ -115,7 +120,15 @@ public boolean configureMessageConverters(List converters) { @Override public void configureMessageBroker(MessageBrokerRegistry config) { config.setApplicationDestinationPrefixes("/app"); - config.enableStompBrokerRelay("/queue/", "/topic/"); + + StompBrokerRelayRegistration stompBrokerRelayRegistration = config.enableStompBrokerRelay("/queue/", "/topic/"); + + stompBrokerRelayRegistration.setRelayHost(environment.getProperty("rabbitmq.host")); + stompBrokerRelayRegistration.setVirtualHost(environment.getProperty("rabbitmq.virtualhost")); + stompBrokerRelayRegistration.setClientLogin(environment.getProperty("rabbitmq.username")); + stompBrokerRelayRegistration.setSystemLogin(environment.getProperty("rabbitmq.username")); + stompBrokerRelayRegistration.setClientPasscode(environment.getProperty("rabbitmq.password")); + stompBrokerRelayRegistration.setSystemPasscode(environment.getProperty("rabbitmq.password")); // only if we want to use . instead of / for path separator e.g. /app/user.chat // config.setPathMatcher(new AntPathMatcher("."));