微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Quarkus:java.lang.IllegalStateException:未找到该频道的订阅者

如何解决Quarkus:java.lang.IllegalStateException:未找到该频道的订阅者

我正在使用 Quarkus 并且我有一个运行缓慢的命令式进程:

@ApplicationScoped
public class SlowApplication {

private static final Logger LOGGER = Logger.getLogger(SlowApplication.class.getName());

@Inject @Channel("texto") public Emitter<String> emitter;

public Integer slowProcess(int num) {
    for (int n=0;n<num;n++) {
        LOGGER.info("Start Num: "+n);
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printstacktrace();
        }
        emitter.send("Number is: "+n);
        LOGGER.info("End Num: "+n);
    }
    return num;
}

我想通过使用 REST API 从流程中获得更新:

@Path("/test")
@ApplicationScoped
public class MainWeb {

@Inject
SlowApplication app;

@Inject
Bridge bridge;

@Inject @Channel("texto-sent") public Multi<String> textos;

@GET
@Produces(MediaType.TEXT_HTML)
public String hello() {
    return "hello";
}

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/custom")
public Uni<String> custom() {
    return Uni.createFrom().item(app.slowProcess(4)).onItem().transform(n -> String.format("Finished %s",n));
}

@GET
@Produces(MediaType.TEXT_HTML)
@Path("/stream")
public Multi<String> stream() {
    return textos;
}

}

@ApplicationScoped
public class Bridge {
private static final Logger LOGGER = Logger.getLogger(Bridge.class.getName());

@Outgoing("texto-sent")
@Incoming("texto")
public String receive(String str) {
    LOGGER.infof("Received " + str);
    return "Received " + str;
}

到达时出现以下错误

emitter.send("Number is: "+n);

java.lang.IllegalStateException: SRMSG00027: 找不到频道文本的订阅

链接Github code包括 pom 和依赖版本)

知道为什么 @Incoming("texto") 不被识别吗?

完全错误

java.lang.IllegalStateException: SRMSG00027: No subscriber found for the channel texto
    at io.smallrye.reactive.messaging.extension.AbstractEmitter.verify(AbstractEmitter.java:157)
    at io.smallrye.reactive.messaging.extension.AbstractEmitter.emit(AbstractEmitter.java:139)
    at io.smallrye.reactive.messaging.extension.EmitterImpl.send(EmitterImpl.java:29)
    at org.jds.sandBox.createUni.SlowApplication.slowProcess(SlowApplication.java:25)
    at org.jds.sandBox.createUni.SlowApplication_Subclass.slowProcess$$superaccessor1(SlowApplication_Subclass.zig:204)
    at org.jds.sandBox.createUni.SlowApplication_Subclass$$function$$1.apply(SlowApplication_Subclass$$function$$1.zig:35)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:63)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
    at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    at org.jds.sandBox.createUni.SlowApplication_Subclass.slowProcess(SlowApplication_Subclass.zig:161)
    at org.jds.sandBox.createUni.SlowApplication_ClientProxy.slowProcess(SlowApplication_ClientProxy.zig:128)
    at org.jds.sandBox.createUni.MainWeb.custom(MainWeb.java:37)
    at org.jds.sandBox.createUni.MainWeb_Subclass.custom$$superaccessor1(MainWeb_Subclass.zig:237)
    at org.jds.sandBox.createUni.MainWeb_Subclass$$function$$1.apply(MainWeb_Subclass$$function$$1.zig:29)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.proceed(AroundInvokeInvocationContext.java:54)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.proceed(InvocationInterceptor.java:63)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor.monitor(InvocationInterceptor.java:49)
    at io.quarkus.arc.runtime.devconsole.InvocationInterceptor_Bean.intercept(InvocationInterceptor_Bean.zig:521)
    at io.quarkus.arc.impl.InterceptorInvocation.invoke(InterceptorInvocation.java:41)
    at io.quarkus.arc.impl.AroundInvokeInvocationContext.perform(AroundInvokeInvocationContext.java:41)
    at io.quarkus.arc.impl.InvocationContexts.performAroundInvoke(InvocationContexts.java:32)
    at org.jds.sandBox.createUni.MainWeb_Subclass.custom(MainWeb_Subclass.zig:195)
    at org.jds.sandBox.createUni.MainWeb_ClientProxy.custom(MainWeb_ClientProxy.zig:213)
    at org.jds.sandBox.createUni.MainWeb$quarkusrestinvoker$custom_0989e6157a2c7c5acc3973ff53d46eb621670726.invoke(MainWeb$quarkusrestinvoker$custom_0989e6157a2c7c5acc3973ff53d46eb621670726.zig:33)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:29)
    at org.jboss.resteasy.reactive.server.handlers.InvocationHandler.handle(InvocationHandler.java:7)
    at org.jboss.resteasy.reactive.common.core.AbstractResteasyReactiveContext.run(AbstractResteasyReactiveContext.java:122)
    at org.jboss.resteasy.reactive.server.handlers.RestinitialHandler.beginProcessing(RestinitialHandler.java:47)
    at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:17)
    at org.jboss.resteasy.reactive.server.vertx.ResteasyReactiveVertxHandler.handle(ResteasyReactiveVertxHandler.java:7)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:137)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
    at io.quarkus.vertx.http.runtime.StaticResourcesRecorder.lambda$start$1(StaticResourcesRecorder.java:65)
    at io.vertx.ext.web.impl.RouteState.handleContext(RouteState.java:1038)
    at io.vertx.ext.web.impl.RoutingContextImplBase.iterateNext(RoutingContextImplBase.java:101)
    at io.vertx.ext.web.impl.RoutingContextImpl.next(RoutingContextImpl.java:132)
    at io.vertx.ext.web.handler.impl.StaticHandlerImpl.lambda$sendStatic$1(StaticHandlerImpl.java:206)
    at io.vertx.core.impl.ContextImpl.lambda$null$0(ContextImpl.java:327)
    at io.vertx.core.impl.ContextImpl.executeTask(ContextImpl.java:366)
    at io.vertx.core.impl.EventLoopContext.lambda$executeAsync$0(EventLoopContext.java:38)
    at io.netty.util.concurrent.AbstractEventExecutor.safeExecute(AbstractEventExecutor.java:164)
    at io.netty.util.concurrent.SingleThreadEventExecutor.runAllTasks(SingleThreadEventExecutor.java:472)
    at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:500)
    at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:989)
    at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
    at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
    at java.base/java.lang.Thread.run(Thread.java:835)

解决方法

解决问题的方法是:

  • 使用 MutinyEmitter 而不是 Emitter
  • 使用 emitter.sendAndForget 而不是 emitter.send

SlowApplication 的新代码:

    @ApplicationScoped
public class SlowApplication {
    
    private static final Logger LOGGER = Logger.getLogger(SlowApplication.class.getName());
    
@Inject @Channel("texto") public MutinyEmitter<String> emitter;

public Integer slowProcess(int num) {
    for (int n=0;n<num;n++) {
        LOGGER.info("Start Num: "+n);
        try {
            Thread.sleep(250);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        emitter.sendAndForget("Number is: "+n);
        LOGGER.info("End Num: "+n);
    }
    return num;
}

我还将 MainWeb 方法中的流更改为:

@GET
@Path("/stream")
@Produces(MediaType.SERVER_SENT_EVENTS)
@SseElementType("text/html")
public Multi<String> stream() {
    return textos;
}

注意:我按照 Clement 的建议更新到了 1.13.7.Final 版本。

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其他元素将获得点击?
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。)
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbcDriver发生异常。为什么?
这是用Java进行XML解析的最佳库。
Java的PriorityQueue的内置迭代器不会以任何特定顺序遍历数据结构。为什么?
如何在Java中聆听按键时移动图像。
Java“Program to an interface”。这是什么意思?