Fixed - Redisson config should be read at runtime. #3943 #3861

pull/4087/head
Nikita Koksharov 3 years ago
parent a0910bb588
commit 07d606de7c

@ -28,14 +28,8 @@ import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.redisson.client.runtime.RedissonClientProducer;
import io.quarkus.redisson.client.runtime.RedissonClientRecorder;
import io.quarkus.runtime.Quarkus;
import org.eclipse.microprofile.config.ConfigProvider;
import org.redisson.config.PropertiesConvertor;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
/**
*
@ -88,24 +82,7 @@ class QuarkusRedissonClientProcessor {
@BuildStep
@Record(ExecutionTime.RUNTIME_INIT)
RedissonClientItemBuild build(RedissonClientRecorder recorder) throws IOException {
InputStream configStream;
Optional<String> configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class);
if (configFile.isPresent()) {
configStream = getClass().getResourceAsStream(configFile.get());
} else {
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("redisson.yaml");
}
if (configStream != null) {
byte[] array = new byte[configStream.available()];
configStream.read(array);
recorder.configureRedisson(new String(array, StandardCharsets.UTF_8));
} else {
String yaml = PropertiesConvertor.toYaml("quarkus.redisson.", ConfigProvider.getConfig().getPropertyNames(), prop -> {
return ConfigProvider.getConfig().getValue(prop, String.class);
});
recorder.configureRedisson(yaml);
}
recorder.createProducer();
return new RedissonClientItemBuild();
}

@ -16,15 +16,20 @@
package io.quarkus.redisson.client.runtime;
import io.quarkus.arc.DefaultBean;
import org.eclipse.microprofile.config.ConfigProvider;
import org.redisson.Redisson;
import org.redisson.api.RedissonClient;
import org.redisson.config.Config;
import org.redisson.config.PropertiesConvertor;
import javax.annotation.PreDestroy;
import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.inject.Produces;
import javax.inject.Singleton;
import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
/**
*
@ -34,24 +39,34 @@ import java.io.IOException;
@ApplicationScoped
public class RedissonClientProducer {
private String config;
private RedissonClient redisson;
@Produces
@Singleton
@DefaultBean
public RedissonClient create() throws IOException {
if (config != null){
Config c = Config.fromYAML(config);
redisson = Redisson.create(c);
InputStream configStream;
Optional<String> configFile = ConfigProvider.getConfig().getOptionalValue("quarkus.redisson.file", String.class);
if (configFile.isPresent()) {
configStream = getClass().getResourceAsStream(configFile.get());
} else {
redisson = Redisson.create();
configStream = Thread.currentThread().getContextClassLoader().getResourceAsStream("redisson.yaml");
}
String config;
if (configStream != null) {
byte[] array = new byte[configStream.available()];
configStream.read(array);
config = new String(array, StandardCharsets.UTF_8);
} else {
String yaml = PropertiesConvertor.toYaml("quarkus.redisson.", ConfigProvider.getConfig().getPropertyNames(), prop -> {
return ConfigProvider.getConfig().getValue(prop, String.class);
});
config = yaml;
}
return redisson;
}
public void setConfig(String config) {
this.config = config;
Config c = Config.fromYAML(config);
redisson = Redisson.create(c);
return redisson;
}
@PreDestroy

@ -26,9 +26,8 @@ import io.quarkus.runtime.annotations.Recorder;
@Recorder
public class RedissonClientRecorder {
public void configureRedisson(String config) {
RedissonClientProducer producer = Arc.container().instance(RedissonClientProducer.class).get();
producer.setConfig(config);
public void createProducer() {
Arc.container().instance(RedissonClientProducer.class).get();
}
}

Loading…
Cancel
Save