当前位置: 首页 > 知识库问答 >
问题:

使用Vert. x-redis和Quakus构建原生图像的问题

淳于博
2023-03-14

我在使用vertx redis客户端以本机模式构建quarkus应用程序时遇到问题

我正在尝试创建一个包含连接、设置和添加方法的缓存类。当我使用set和get方法时,我试图打开一个新的redis连接。

使用。/mvnw编译夸克斯:开发应用程序运行正常。但是,当我试图构建一个本地映像时,我收到错误:

Error: No instances of io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace:  object io.netty.buffer.UnreleasableByteBuf
        object io.vertx.core.buffer.impl.BufferImpl
        object io.vertx.redis.client.impl.types.BulkType
        method io.vertx.redis.client.impl.RESPParser.handle(Buffer)
Call path from entry point to io.vertx.redis.client.impl.RESPParser.handle(Buffer): 
        at io.vertx.redis.client.impl.RESPParser.handle(RESPParser.java:51)
        at io.vertx.redis.client.impl.RESPParser.handle(RESPParser.java:25)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
        at io.vertx.core.impl.WorkerContext.lambda$wrapTask$0(WorkerContext.java:35)
        at io.vertx.core.impl.WorkerContext$$Lambda$547/789610232.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

com.oracle.svm.core.util.UserError$UserException: No instances of io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace:  object io.netty.buffer.UnreleasableByteBuf
        object io.vertx.core.buffer.impl.BufferImpl
        object io.vertx.redis.client.impl.types.BulkType
        method io.vertx.redis.client.impl.RESPParser.handle(Buffer)
Call path from entry point to io.vertx.redis.client.impl.RESPParser.handle(Buffer): 
        at io.vertx.redis.client.impl.RESPParser.handle(RESPParser.java:51)
        at io.vertx.redis.client.impl.RESPParser.handle(RESPParser.java:25)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
        at io.vertx.core.impl.WorkerContext.lambda$wrapTask$0(WorkerContext.java:35)
        at io.vertx.core.impl.WorkerContext$$Lambda$547/789610232.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

        at com.oracle.svm.core.util.UserError.abort(UserError.java:75)
        at com.oracle.svm.hosted.FallbackFeature.reportAsFallback(FallbackFeature.java:223)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:737)
        at com.oracle.svm.hosted.NativeImageGenerator.doRun(NativeImageGenerator.java:526)
        at com.oracle.svm.hosted.NativeImageGenerator.lambda$run$0(NativeImageGenerator.java:444)
        at java.util.concurrent.ForkJoinTask$AdaptedRunnableAction.exec(ForkJoinTask.java:1386)
        at java.util.concurrent.ForkJoinTask.doExec(ForkJoinTask.java:289)
        at java.util.concurrent.ForkJoinPool$WorkQueue.runTask(ForkJoinPool.java:1056)
        at java.util.concurrent.ForkJoinPool.runWorker(ForkJoinPool.java:1692)
        at java.util.concurrent.ForkJoinWorkerThread.run(ForkJoinWorkerThread.java:157)
Caused by: com.oracle.graal.pointsto.constraints.UnsupportedFeatureException: No instances of io.netty.buffer.UnpooledByteBufAllocator$InstrumentedUnpooledUnsafeHeapByteBuf are allowed in the image heap as this class should be initialized at image runtime. To see how this object got instantiated use -H:+TraceClassInitialization.
Detailed message:
Trace:  object io.netty.buffer.UnreleasableByteBuf
        object io.vertx.core.buffer.impl.BufferImpl
        object io.vertx.redis.client.impl.types.BulkType
        method io.vertx.redis.client.impl.RESPParser.handle(Buffer)
Call path from entry point to io.vertx.redis.client.impl.RESPParser.handle(Buffer): 
        at io.vertx.redis.client.impl.RESPParser.handle(RESPParser.java:51)
        at io.vertx.redis.client.impl.RESPParser.handle(RESPParser.java:25)
        at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:369)
        at io.vertx.core.impl.WorkerContext.lambda$wrapTask$0(WorkerContext.java:35)
        at io.vertx.core.impl.WorkerContext$$Lambda$547/789610232.run(Unknown Source)
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
        at java.lang.Thread.run(Thread.java:748)
        at com.oracle.svm.core.thread.JavaThreads.threadStartRoutine(JavaThreads.java:460)
        at com.oracle.svm.core.posix.thread.PosixJavaThreads.pthreadStartRoutine(PosixJavaThreads.java:193)
        at com.oracle.svm.core.code.IsolateEnterStub.PosixJavaThreads_pthreadStartRoutine_e1f4a8c0039f8337338252cd8734f63a79b5e3df(generated:0)

        at com.oracle.graal.pointsto.constraints.UnsupportedFeatures.report(UnsupportedFeatures.java:130)
        at com.oracle.graal.pointsto.BigBang.finish(BigBang.java:565)
        at com.oracle.svm.hosted.NativeImageGenerator.runPointsToAnalysis(NativeImageGenerator.java:688)
        ... 7 more

我的缓存类:

import io.quarkus.runtime.annotations.RegisterForReflection;
import io.vertx.core.Vertx;
import io.vertx.redis.client.Redis;
import io.vertx.redis.client.RedisAPI;
import io.vertx.redis.client.RedisOptions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import java.util.concurrent.CompletableFuture;

@ApplicationScoped
public class Cache {
    Logger logger = LoggerFactory.getLogger(Cache.class);

    RedisAPI redis;

    @Inject
    Vertx vertx;

    private void verifyConnection() {
        if(redis == null) {
            CompletableFuture<RedisAPI> connectionResult = new CompletableFuture<RedisAPI>();
            Redis.createClient(vertx, new RedisOptions())
                    .connect(onConnect -> {
                        if (onConnect.succeeded()) {
                            Redis client = onConnect.result();
                            connectionResult.complete(RedisAPI.api(client));
                        } else {
                            connectionResult.complete(null);
                        }
                    });
            redis = connectionResult.join();
        }
    }

    public String get (String key) {
        verifyConnection();
        CompletableFuture<String> lambdaResult = new CompletableFuture<>();
        redis.get(key, res -> {
            if (res.succeeded()) {
                if (res.result() != null) {
                    lambdaResult.complete(res.result().toString());
                } else {
                    lambdaResult.complete(null);
                }
            } else {
                lambdaResult.complete(null);
            }
        });

        return lambdaResult.join();
    }

    public void set(String key, String data) {
        verifyConnection();
        redis.append(key, data, res -> {
            if (res.failed()) {
                logger.error("Error to send data to Cache");
            }
        });
    }
}

共有1个答案

戚翰飞
2023-03-14

这是一个迹象,我们可能需要一个扩展,使其工作,但你可以尝试在你的应用程序中首先通过调整GraalVM设置。

你可以尝试制作io。维特斯。雷迪斯。客户impl。RESPParser可在运行时初始化。你可以查一下https://quarkus.io/guides/writing-native-applications-tips#delaying-类初始化,以获取有关如何在应用程序中执行此操作的更多信息。

如果你最终让它工作,请报告Quarkus开发,因为我们有一个Redis扩展在工作中,你的反馈可能对即将工作的人有用。

 类似资料:
  • 我正在尝试在MacOS上为AWS Lambda函数构建本机映像。该应用程序在IDE中编译和运行良好,但在尝试本机映像构建时,我遇到了以下问题: > 错误:4种方法中不支持的功能详细信息:错误:在映像堆中检测到Random/SplittableRandom类的实例。在映像生成过程中创建的实例具有缓存的种子值,其行为不符合预期。要查看这个对象是如何被实例化的,请使用--trace object ins

  • 我刚刚从https://micronaut.io/launch for Java8下载了一个新项目,该项目具有以下特性: AWS lambda AWS Lambda运行时 GraalVM支持 在readme.md中,它实际上只显示了使用gradle获得本机映像的构建指令。但是用Maven怎么做呢?

  • DockerFile: 在之后,GPG行显示为红色,图像创建失败。为什么?

  • 我正在用“原生脚本-照片-缩放”和原生脚本-图像-缩放在我的角应用程序中尝试图像缩放,但它引发了“PhotoDraweeView不是构造函数错误”,有人能帮我吗? 我的代码HTML: 导出类AppModule{}

  • 最近我开始学习、和非阻塞Java框架,其中一个引起了我的注意——。 我想,同样的问题可能适用于akka(Play框架),因为他们的理念或目标之一是相同的,那就是减少线程数量,从而提高应用程序的可扩展性。 建议它所消耗的线程数与CPU内核数相当,但它也表明,有时您必须执行阻塞操作,因此它鼓励开发人员在单独的工作线程上执行阻塞操作(垂直于vert.x的工作线程)。 这就是我要问的问题: 如果我应该在一

  • 有人知道如何在CloudBuild上构建quarkus原生映像吗?我使用以下命令来执行此操作: 在本地,一切都很好,但当我试图在谷歌云上做这件事时,它抛出了一个错误: 我使用以下cloudbuild.yaml 现在我有了一个新问题--当我试图安装docker容器运行时时,我得到以下错误: