From 0a12f28b58c834fac8a873d2862d0cc94f7a5163 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Mon, 23 Dec 2013 14:51:08 -0500 Subject: [PATCH] Introduce StompReactorNettyTcpClient Issue: SPR-11153 --- .../stomp/StompBrokerRelayMessageHandler.java | 16 +++++++-- .../stomp/StompReactorNettyTcpClient.java | 35 +++++++++++++++++++ .../StompBrokerRelayMessageHandlerTests.java | 2 +- 3 files changed, 49 insertions(+), 4 deletions(-) create mode 100644 spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompReactorNettyTcpClient.java diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java index 658958b8d7..e6f10320f1 100644 --- a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java @@ -250,12 +250,22 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler } /** - * Used for unit testing. + * Configure a TCP client for managing TCP connections to the STOMP broker. By default + * {@link org.springframework.messaging.simp.stomp.StompReactorNettyTcpClient} is used. */ - void setTcpClient(TcpOperations tcpClient) { + public void setTcpClient(TcpOperations tcpClient) { this.tcpClient = tcpClient; } + /** + * Get the configured TCP client. Never {@code null} unless not configured + * invoked and this method is invoked before the handler is started and + * hence a default implementation initialized. + */ + public TcpOperations getTcpClient() { + return this.tcpClient; + } + @Override protected void startInternal() { @@ -264,7 +274,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler this.brokerChannel.subscribe(this); if (this.tcpClient == null) { - this.tcpClient = new ReactorNettyTcpClient(this.relayHost, this.relayPort, new StompCodec()); + this.tcpClient = new StompReactorNettyTcpClient(this.relayHost, this.relayPort); } if (logger.isDebugEnabled()) { diff --git a/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompReactorNettyTcpClient.java b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompReactorNettyTcpClient.java new file mode 100644 index 0000000000..353f26c04b --- /dev/null +++ b/spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompReactorNettyTcpClient.java @@ -0,0 +1,35 @@ +/* + * Copyright 2002-2013 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 org.springframework.messaging.simp.stomp; + +import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient; +import reactor.tcp.encoding.Codec; + +/** + * A variation of {@link ReactorNettyTcpClient} for sending and receiving STOMP frames. + * + * @author Rossen Stoyanchev + * @since 4.0.1 + */ +public class StompReactorNettyTcpClient extends ReactorNettyTcpClient { + + + public StompReactorNettyTcpClient(String host, int port) { + super(host, port, new StompCodec()); + } + +} diff --git a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java index adde608df9..432296d9ad 100644 --- a/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java +++ b/spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java @@ -55,7 +55,7 @@ public class StompBrokerRelayMessageHandlerTests { this.brokerRelay = new StompBrokerRelayMessageHandler(new StubMessageChannel(), new StubMessageChannel(), new StubMessageChannel(), Arrays.asList("/topic")); - this.brokerRelay.setTcpClient(tcpClient); + this.brokerRelay.setTcpClient(this.tcpClient); }