Here is another good example of remote method invocation with Redisson framework:
Let's assume YourServiceImpl
contains method you need to invoke remotely and implements YourService
interface.
YourServiceImpl should be registered in Redisson via RemoteService object:
YourService yourService = new YourServiceImpl();
RRemoteService remoteService = redisson.getRemoteService();
remoteService.register(YourService.class, yourService);
To invoke method remotely only service interface is needed:
RRemoteService remoteService = redisson.getRemoteService();
YourService service = remoteService.get(YourService.class);
MyObject result = service.myMethod(someParam1, someParam2);
Also it supports asynchronous calls.
// async interface for YourService
@RRemoteAsync(YourService.class)
public interface YourServiceAsync {
RFuture<Long> someMethod1(Long param1, String param2);
RFuture<Void> someMethod2(MyObject param);
}
RRemoteService remoteService = redisson.getRemoteService();
YourServiceAsync asyncService = remoteService.get(YourServiceAsync.class);
RFuture<Long> res = asyncService.someMethod1(12L, "param");
res.thenApply(r -> {
...
});
More details here