Repository navigation
Closed
Labels
Description
I could create a server lease to a single client as follows:
@Slf4j
public class LeaseServer {
private static final String SERVER_TAG = "server";
public static void main(String[] args) throws InterruptedException {
// Queue for incoming messages represented as Flux
// Imagine that every fireAndForget that is pushed is processed by a worker
int queueCapacity = 50;
BlockingQueue<String> messagesQueue = new ArrayBlockingQueue<>(queueCapacity);
// emulating a worker that process data from the queue
Thread workerThread =
new Thread(
() -> {
try {
while (!Thread.currentThread().isInterrupted()) {
String message = messagesQueue.take();
System.out.println("consume message:" + message);
Thread.sleep(100000); // emulating processing
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
});
workerThread.start();
CloseableChannel server = getFireAndForgetServer(messagesQueue, workerThread);
TimeUnit.MINUTES.sleep(10);
server.dispose();
}
private static CloseableChannel getFireAndForgetServer(BlockingQueue<String> messagesQueue, Thread workerThread) {
CloseableChannel server =
RSocketServer.create((setup, sendingSocket) ->
Mono.just(new RSocket() {
@Override
public Mono<Void> fireAndForget(Payload payload) {
// add element. if overflows errors and terminates execution
// specifically to show that lease can limit rate of fnf requests in
// that example
try {
if (!messagesQueue.offer(payload.getDataUtf8())) {
System.out.println("Queue has been overflowed. Terminating execution");
sendingSocket.dispose();
workerThread.interrupt();
}
} finally {
payload.release();
}
return Mono.empty();
}
}))
.lease(() -> Leases.create().sender(new LeaseCalculator(SERVER_TAG, messagesQueue)))
.bindNow(TcpServerTransport.create("localhost", 7000));
return server;
}
}But how do I issue a lease to multiple clients connected to that server?
Otherwise my queue will be written multiple times by multiple clients, resulting in an overflow of the service.
I can't find the details in the public documents and materials.
Your help was very much appreciated.
And I ask for help on stackoverflow: https://stackoverflow.com/questions/65227829/how-do-rsocket-issue-lease-to-multiple-clients
Activity
OlegDokuka commentedon Dec 19, 2020
Hi @kevinten10!
Thank you for asking!
Great news for you! We are working hard to improve the current lease API and provide you with a straight forward way of lease issuing to multiple Requesters.
Please track the progress here #885! Feel free to use a snapshot from that repo and try the API out! Any feedback is more than appreciated. Also, you may find a set of examples on how to control multiple requesters here -> https://github.com/rsocket/rsocket-java/pull/885/files#diff-05334cc64278a568fba3834c8d5798b66ed451a337dd96c6ed2f54659b8e35c8
Stay tuned,
Oleh
kevinten10 commentedon Dec 20, 2020
@OlegDokuka Thanks for your answer!
I read this commit #885 .
Looking forward to a more complete
leasemechanism.This will enable
leaseto be truly applied in a distributed environment.I will further explore the use of
lease.Best regrads.
kevinten10 commentedon Dec 20, 2020
@OlegDokuka By the way
Whether to consider providing default implementation of common indicators for
lease, such as queue capacity, cpu indicators, etc.It can avoid repeated development.
OlegDokuka commentedon Dec 20, 2020
@kevinten10 I will consider that, however, the actual advanced implementation is out of library scope. But feel free to build out something and if it is not that complex, we can definitely consider porting it into the core library.
Also, most likely we will provide a standard mechanism that should simplify significantly stats based lease management implementation
Cheers,
Oleh
kitkars commentedon Dec 29, 2020
@OlegDokuka @rstoyanchev
Just curious - currently lease supplier does not seem to know any knowledge on the client side/requester. Is this expected?
For ex: It certain cases it could be useful - to adjust the lease based on the client.
Thanks.
OlegDokuka commentedon Feb 17, 2021
@kitkars sorry for the late answer. This is up to the application logic. Your clients may provide different information at the setup phase and then you may provide this info to the lease manager so it can decide how to treat a particular connection. Lease is just a mechanism to manage responder load, but the actual algorithm is on the application implementers shoulders