I am try to integrate Reactive Quarkus application with Hazelcast for caching and to mange distributed data(because multiple pods can run). I created sample project. https://github.com/kavishkamk/hazelcast-quarkus-test. But I have to convert this code to handle with Reactive code. like say
import ......domain.Device;
import io.quarkus.hibernate.reactive.panache.PanacheRepositoryBase;
import io.smallrye.mutiny.Uni;
import javax.enterprise.context.ApplicationScoped;
@ApplicationScoped
public class DeviceRepository implements PanacheRepositoryBase<Device, Integer> {
private final HazelcastInstance hazelcastInstance;
public DeviceRepository(HazelcastInstance hazelcastInstance) {
this.hazelcastInstance = hazelcastInstance;
}
// get device by device name
public Uni<Device> getDeviceByDeviceRef(String deviceRef) {
Map<String, Device> capitalcities = hazelcastInstance.getMap("device-map");
// first check the cash
return capitalcities.get(deviceRef)
.ifNull().find("deviceRef", deviceRef).firstResult();
}
}
this is not a valid code. but I think I have to use this kind of pattern or to use any kind of HazelcastInstance Async clinet. Can some one help me to solve this issue.
I also saw https://vertx.io/docs/vertx-hazelcast/java/ vert.x instance. Do i have to use this kind of native pattern. I am using implementation 'com.hazelcast:quarkus-hazelcast-client:4.0.0' in my quarkus app. So I think there is a already available solution for this.
or is it safe to just call to get the response like this.
public Uni<Device> getDeviceByDeviceRef(String deviceRef) {
Map<String, Person> capitalcities = hazelcastInstance.getMap("user-map1");
Device device = capitalcities.get(deviceRef);
if(device != null) {
return Uni.createForm.item(device);
}
// first check the cash
return find("deviceRef", deviceRef).firstResult();
}
But this hazelcast cluster running as a container and call through the network.
docker run \
-it \
--network hazelcast-network \
--rm \
-e HZ_CLUSTERNAME=hello-world \
-p 5701:5701 hazelcast/hazelcast:5.3.1
Thank you very much
EDIT
The problem is I assign the reserved map to java.util.Map instead of IMap. I i map there is a CompletionStage object. I include the test project link bellow. Thank you.
https://github.com/kavishkamk/hazelcast-quarkus-test/tree/java-embedded-instance