我在Vert.x3.9.2和vertx-rabbitmq-client的同一版本中使用Java8。我正试图向交换机发布消息,但无论交换机有什么配置(主题/扇出(,都会抛出相同的异常:
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", // 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());
}
);
我认为问题在于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
提前谢谢。
new JsonObject()... // Another properties
对象是否具有具有字符串值的body
属性?这就是basicPulish从信息中提取的内容。请注意,没有属性可能会返回null。因此,如果你的所有属性都有非null值,这是不够的,你还应该有所有必需的属性:(