Add RSocketRequester configuration for tests

This commit is contained in:
Oleg Zhurakousky
2020-08-26 14:35:34 +02:00
parent c1240ebb91
commit 18b0f436d3
4 changed files with 91 additions and 89 deletions

View File

@@ -1,55 +0,0 @@
/*
* Copyright 2020-2020 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.cloud.function.rsocket;
import java.net.InetSocketAddress;
import java.time.Duration;
import io.rsocket.RSocket;
import io.rsocket.SocketAcceptor;
import io.rsocket.core.RSocketConnector;
import io.rsocket.core.RSocketServer;
import io.rsocket.transport.netty.client.TcpClientTransport;
import io.rsocket.transport.netty.server.TcpServerTransport;
import reactor.core.Disposable;
import reactor.util.retry.Retry;
import reactor.util.retry.RetrySpec;
import org.springframework.lang.Nullable;
/**
*
* @author Oleg Zhurakousky
* @since 3.1
*/
public abstract class RSocketConnectionUtils {
public static Disposable createServerSocket(RSocket rsocket, InetSocketAddress address) {
Disposable server = RSocketServer.create(SocketAcceptor.with(rsocket))
.bind(TcpServerTransport.create(address)) //TODO transport can actually be selected based on address (local or tcp)??
.subscribe();
return server;
}
public static RSocket createClientSocket(InetSocketAddress address, @Nullable RetrySpec retrySpec) {
RSocket socket = RSocketConnector.connectWith(TcpClientTransport.create(address)).log()
.retryWhen(retrySpec == null ? Retry.backoff(5, Duration.ofSeconds(1)) : retrySpec)
.block();
return socket;
}
}