Influx 写入 api 捕获异常

问题描述 投票:0回答:1

背景

我有一个使用

influxdb-client-java
版本
7.0.0
的项目。我正在使用
WriteApi
编写点,它启动后台线程将数据发送到 influxdb 实例。

我的问题

我想抓住

UnauthorizedException
并对其采取行动。

问题

我可以在某处注册一个异常处理程序吗?或者我怎样才能实现这一点?

我在网上搜索过,但找不到任何有用的文档。

java influxdb
1个回答
0
投票

我找到了实现它的方法。

WriteApi
有一个
listenEvents
方法可供您使用。一个例子:

final var writeApi = client.makeWriteApi(writeOptions);
     writeApi.listenEvents(WriteErrorEvent.class, event -> {
     if (event.getThrowable() instanceof UnauthorizedException) {
          log.error("Could not send data to influx. The provided influx token is either wrong or does not has the write permission granted.");
          System.exit(-1);
     }
});
© www.soinside.com 2019 - 2024. All rights reserved.