Support Reactor Netty 2 / Netty 5 in spring-messaging
Closes gh-28847
This commit is contained in:
@@ -47,6 +47,7 @@ import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.messaging.simp.broker.BrokerAvailabilityEvent;
|
||||
import org.springframework.messaging.support.ExecutorSubscribableChannel;
|
||||
import org.springframework.messaging.support.MessageBuilder;
|
||||
import org.springframework.messaging.tcp.TcpOperations;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
@@ -56,11 +57,10 @@ import static org.assertj.core.api.Assertions.assertThatExceptionOfType;
|
||||
* Integration tests for {@link StompBrokerRelayMessageHandler} running against ActiveMQ.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
*/
|
||||
public class StompBrokerRelayMessageHandlerIntegrationTests {
|
||||
public abstract class AbstractStompBrokerRelayIntegrationTests {
|
||||
|
||||
private static final Log logger = LogFactory.getLog(StompBrokerRelayMessageHandlerIntegrationTests.class);
|
||||
private static final Log logger = LogFactory.getLog(AbstractStompBrokerRelayIntegrationTests.class);
|
||||
|
||||
private StompBrokerRelayMessageHandler relay;
|
||||
|
||||
@@ -77,7 +77,6 @@ public class StompBrokerRelayMessageHandlerIntegrationTests {
|
||||
|
||||
|
||||
@BeforeEach
|
||||
@SuppressWarnings("deprecation")
|
||||
public void setup(TestInfo testInfo) throws Exception {
|
||||
logger.debug("Setting up before '" + testInfo.getTestMethod().get().getName() + "'");
|
||||
|
||||
@@ -121,10 +120,15 @@ public class StompBrokerRelayMessageHandlerIntegrationTests {
|
||||
this.relay.setSystemHeartbeatSendInterval(0);
|
||||
this.relay.setPreservePublishOrder(true);
|
||||
|
||||
TcpOperations<byte[]> tcpClient = initTcpClient(this.port);
|
||||
this.relay.setTcpClient(tcpClient);
|
||||
|
||||
this.relay.start();
|
||||
this.eventPublisher.expectBrokerAvailabilityEvent(true);
|
||||
}
|
||||
|
||||
protected abstract TcpOperations<byte[]> initTcpClient(int port);
|
||||
|
||||
@AfterEach
|
||||
public void stop() throws Exception {
|
||||
try {
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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
|
||||
*
|
||||
* https://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.TcpOperations;
|
||||
import org.springframework.messaging.tcp.reactor.ReactorNetty2TcpClient;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link StompBrokerRelayMessageHandler} running against
|
||||
* ActiveMQ with {@link ReactorNetty2TcpClient}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ReactorNetty2StompBrokerRelayIntegrationTests extends AbstractStompBrokerRelayIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected TcpOperations<byte[]> initTcpClient(int port) {
|
||||
return new ReactorNetty2TcpClient<>("127.0.0.1", port, new StompTcpMessageCodec());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
/*
|
||||
* Copyright 2002-2022 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
|
||||
*
|
||||
* https://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.TcpOperations;
|
||||
import org.springframework.messaging.tcp.reactor.ReactorNettyTcpClient;
|
||||
|
||||
/**
|
||||
* Integration tests for {@link StompBrokerRelayMessageHandler} running against
|
||||
* ActiveMQ with {@link ReactorNettyTcpClient}.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
public class ReactorNettyStompBrokerRelayIntegrationTests extends AbstractStompBrokerRelayIntegrationTests {
|
||||
|
||||
@Override
|
||||
protected TcpOperations<byte[]> initTcpClient(int port) {
|
||||
return new ReactorNettyTcpClient<>("127.0.0.1", port, new StompReactorNettyCodec());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -37,6 +37,7 @@ import org.junit.jupiter.api.TestInfo;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.converter.StringMessageConverter;
|
||||
import org.springframework.messaging.simp.stomp.StompSession.Subscription;
|
||||
import org.springframework.messaging.tcp.reactor.ReactorNetty2TcpClient;
|
||||
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
|
||||
import org.springframework.util.Assert;
|
||||
|
||||
@@ -57,6 +58,8 @@ public class ReactorNettyTcpStompClientTests {
|
||||
|
||||
private ReactorNettyTcpStompClient client;
|
||||
|
||||
private ReactorNettyTcpStompClient client2;
|
||||
|
||||
|
||||
@BeforeEach
|
||||
public void setup(TestInfo testInfo) throws Exception {
|
||||
@@ -75,9 +78,16 @@ public class ReactorNettyTcpStompClientTests {
|
||||
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||
taskScheduler.afterPropertiesSet();
|
||||
|
||||
this.client = new ReactorNettyTcpStompClient("127.0.0.1", stompConnector.getServer().getSocketAddress().getPort());
|
||||
int port = stompConnector.getServer().getSocketAddress().getPort();
|
||||
String host = "127.0.0.1";
|
||||
|
||||
this.client = new ReactorNettyTcpStompClient(host, port);
|
||||
this.client.setMessageConverter(new StringMessageConverter());
|
||||
this.client.setTaskScheduler(taskScheduler);
|
||||
|
||||
this.client2 = new ReactorNettyTcpStompClient(new ReactorNetty2TcpClient<>(host, port, new StompTcpMessageCodec()));
|
||||
this.client2.setMessageConverter(new StringMessageConverter());
|
||||
this.client2.setTaskScheduler(taskScheduler);
|
||||
}
|
||||
|
||||
private TransportConnector createStompConnector() throws Exception {
|
||||
@@ -90,6 +100,7 @@ public class ReactorNettyTcpStompClientTests {
|
||||
public void shutdown() throws Exception {
|
||||
try {
|
||||
this.client.shutdown();
|
||||
this.client2.shutdown();
|
||||
}
|
||||
catch (Throwable ex) {
|
||||
logger.error("Failed to shut client", ex);
|
||||
@@ -103,14 +114,24 @@ public class ReactorNettyTcpStompClientTests {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void publishSubscribe() throws Exception {
|
||||
public void publishSubscribeOnReactorNetty() throws Exception {
|
||||
testPublishSubscribe(this.client);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void publishSubscribeOnReactorNetty2() throws Exception {
|
||||
testPublishSubscribe(this.client2);
|
||||
}
|
||||
|
||||
private void testPublishSubscribe(ReactorNettyTcpStompClient clientToUse) throws Exception {
|
||||
String destination = "/topic/foo";
|
||||
ConsumingHandler consumingHandler1 = new ConsumingHandler(destination);
|
||||
CompletableFuture<StompSession> consumerFuture1 = this.client.connectAsync(consumingHandler1);
|
||||
CompletableFuture<StompSession> consumerFuture1 = clientToUse.connectAsync(consumingHandler1);
|
||||
|
||||
ConsumingHandler consumingHandler2 = new ConsumingHandler(destination);
|
||||
CompletableFuture<StompSession> consumerFuture2 = this.client.connectAsync(consumingHandler2);
|
||||
CompletableFuture<StompSession> consumerFuture2 = clientToUse.connectAsync(consumingHandler2);
|
||||
|
||||
assertThat(consumingHandler1.awaitForSubscriptions(5000)).isTrue();
|
||||
assertThat(consumingHandler2.awaitForSubscriptions(5000)).isTrue();
|
||||
@@ -118,7 +139,7 @@ public class ReactorNettyTcpStompClientTests {
|
||||
ProducingHandler producingHandler = new ProducingHandler();
|
||||
producingHandler.addToSend(destination, "foo1");
|
||||
producingHandler.addToSend(destination, "foo2");
|
||||
CompletableFuture<StompSession> producerFuture = this.client.connectAsync(producingHandler);
|
||||
CompletableFuture<StompSession> producerFuture = clientToUse.connectAsync(producingHandler);
|
||||
|
||||
assertThat(consumingHandler1.awaitForMessageCount(2, 5000)).isTrue();
|
||||
assertThat(consumingHandler1.getReceived()).containsExactly("foo1", "foo2");
|
||||
|
||||
Reference in New Issue
Block a user