Vert.x RabbitMQ编码空指针异常

huangapple go评论128阅读模式
英文:

Vert.x RabbitMQ encode NullPointerException

问题

我正在使用Java8Vert.x 3.9.2以及vertx-rabbitmq-client相同版本。我试图向一个交换机发布消息,但无论交换机的配置如何(主题/扇出),都会抛出相同的异常:

 java.lang.NullPointerException
        at io.vertx.rabbitmq.impl.Utils.encode(Utils.java:179)
        at io.vertx.rabbitmq.impl.RabbitMQClientImpl.lambda$basicPublish$8(RabbitMQClientImpl.java:213)
        at io.vertx.rabbitmq.impl.RabbitMQClientImpl.lambda$forChannel$34(RabbitMQClientImpl.java:488)
        at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:313)
        at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:834)

这是我的代码:

amqpClient
    .exchangeDeclare(
        "orders", // 名称
        "topic", // 类型
        true, // 持久性
        false, // 自动删除
        exchangeDeclareResult -> {
            if (exchangeDeclareResult.succeeded()) {
                amqpClient
                    .basicPublish(
                        "orders",
                        "test",
                        new JsonObject()..... // 其他属性
                        publishResult -> {
                            if (publishResult.succeeded())
                                mainPromise.complete();
                            else {
                                publishResult.cause().printStackTrace();
                                mainPromise.fail(publishResult.cause());
                            }
                        });
            }
            else
                mainPromise.fail(exchangeDeclareResult.cause());
        }
    );

我认为问题出在 JSON 内容序列化上。我的请求正文中的每个属性都有内容,我的意思是没有空值。在调试期间,我还注意到异常中有一条消息:

NullPointerException@91 "java.lang.NullPointerException"
cause: NullPointerException@91 "java.lang.NullPointerException"
depth:9
backtrace Object[5]@99
stackTraceElement[9]@133
suppressedExceptions: Collections$EmptyList@101 size=0

提前感谢。

英文:

I am working with Java8 in Vert.x 3.9.2 and vertx-rabbitmq-client same version. I am trying to publish a message to an exchange, but regardless the configuration the exchange has (topic/fanout) the same exception is thrown:

 java.lang.NullPointerException
        at io.vertx.rabbitmq.impl.Utils.encode(Utils.java:179)
        at io.vertx.rabbitmq.impl.RabbitMQClientImpl.lambda$basicPublish$8(RabbitMQClientImpl.java:213)
        at io.vertx.rabbitmq.impl.RabbitMQClientImpl.lambda$forChannel$34(RabbitMQClientImpl.java:488)
        at io.vertx.core.impl.ContextImpl.lambda$executeBlocking$2(ContextImpl.java:313)
        at io.vertx.core.impl.TaskQueue.run(TaskQueue.java:76)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
        at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
        at java.base/java.lang.Thread.run(Thread.java:834)

This is my code:

          amqpClient
             .exchangeDeclare(
                "orders", // name
                "topic", // type
                true, //durable
                false, //autodelete 
                exchangeDeclareResult -> {
                    if (exchangeDeclareResult.succeeded()) {
                        amqpClient
                            .basicPublish(
                                "orders", 
                                "test",
                                new JsonObject()..... // Another properties
                                publishResult -> {
                                    if (publishResult.succeeded())
                                        mainPromise.complete();
                                    else {
                                        publishResult.cause().printStackTrace();
                                        mainPromise.fail(publishResult.cause());
                                    }
                                });
                    } 
                    else
                        mainPromise.fail(exchangeDeclareResult.cause());
                }
            );

I think the problem is about json content serialization. Every property in my body has content, I mean there is no null values. An aditional issue I can notice is a message in the exception during debug:

NullPointerException@91 "java.lang.NullPointerException"
cause: NullPointerException@91 "java.lang.NullPointerException"
depth:9
backtrace Object[5]@99
stackTraceElement[9]@133
suppressedExceptions: Collections$EmptyList@101 size=0

Thanks in advance.

答案1

得分: 1

new JsonObject()... // Another properties 对象是否具有一个具有字符串值的 body 属性?这是从消息中提取的内容,由 basicPublish 完成。请注意,如果没有该属性,可能会返回 null。因此,如果所有属性都具有非 null 值,仍然不足以确保成功,您还应该具备所有必需的属性 Vert.x RabbitMQ编码空指针异常

英文:

Does the new JsonObject()... // Another properties object have a body property that has a string value? That is what basicPulish is extracting from the message. Note that not having a property might return null. So it isn't sufficient if all of your properties have non-null values, you should also have all required properties Vert.x RabbitMQ编码空指针异常

huangapple
  • 本文由 发表于 2020年8月7日 12:38:14
  • 转载请务必保留本文链接:https://go.coder-hub.com/63295301.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定