Browse Source

Introduce StompReactorNettyTcpClient

Issue: SPR-11153
pull/432/head
Rossen Stoyanchev 11 years ago
parent
commit
0a12f28b58
  1. 16
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java
  2. 35
      spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompReactorNettyTcpClient.java
  3. 2
      spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java

16
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java

@ -250,12 +250,22 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler @@ -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<byte[]> tcpClient) {
public void setTcpClient(TcpOperations<byte[]> 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<byte[]> getTcpClient() {
return this.tcpClient;
}
@Override
protected void startInternal() {
@ -264,7 +274,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler @@ -264,7 +274,7 @@ public class StompBrokerRelayMessageHandler extends AbstractBrokerMessageHandler
this.brokerChannel.subscribe(this);
if (this.tcpClient == null) {
this.tcpClient = new ReactorNettyTcpClient<byte[]>(this.relayHost, this.relayPort, new StompCodec());
this.tcpClient = new StompReactorNettyTcpClient(this.relayHost, this.relayPort);
}
if (logger.isDebugEnabled()) {

35
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompReactorNettyTcpClient.java

@ -0,0 +1,35 @@ @@ -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<byte[]> {
public StompReactorNettyTcpClient(String host, int port) {
super(host, port, new StompCodec());
}
}

2
spring-messaging/src/test/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandlerTests.java

@ -55,7 +55,7 @@ public class StompBrokerRelayMessageHandlerTests { @@ -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);
}

Loading…
Cancel
Save