MicroProfile LRA - 如何在 WildFly JEE 应用程序上定义自定义参与者 URI?

MicroProfile LRA - How to define custom participant URI on a WildFly JEE application?

当 MicroProfile LRA 协调器和参与者 运行 在不同的 Docker 容器上时,需要为每个参与者定义自定义 URI。

否则,LRA 协调员会尝试通过使用基于“本地主机”的 URI 引用参与者 compensate/complete API 来调用它们。

是否可以在 WildFly 环境中为参与者定义自定义 URI? 一般来说,是否可以定义参与者如何在任何 LRA 注册?

默认情况下,参与者端点来自 JAX-RS UriInfo class 中提供的呼叫者信息。此 class 包含参与者调用者的基本 URI。这个想法是协调器应该能够在与参与者的原始请求相同的 URI 上调用参与者。

我创建了一个简单的 docker 图像 https://hub.docker.com/repository/docker/xstefank/uriinfo-wildfly,它将在路径 /uriinfo/ping return 上作为参与者 URL 将使用的基本 URI。

在本地调用它会得到 - Base URI is http://localhost:8080/uriinfo/ 预计会从本地计算机调用。将此图像部署到 OpenShift/Kubernetes 并公开此应用程序的路由可以得到 Base URI is http://uriinfo-wildfly-testing.6923.rh-us-east-1.openshiftapps.com/uriinfo/。最后,从同一个项目中部署的不同 pod 调用它会得到 Base URI is http://uriinfo-wildfly:8080/uriinfo/,这对应于实际调用:

$ curl localhost:8080/uriinfo/ping
Base URI is http://localhost:8080/uriinfo/

$ curl http://uriinfo-wildfly-testing.6923.rh-us-east-1.openshiftapps.com/uriinfo/ping
Base URI is http://uriinfo-wildfly-testing.6923.rh-us-east-1.openshiftapps.com/uriinfo/

# called from different pod in the same openshift project
$ curl http://uriinfo-wildfly:8080/uriinfo/ping
Base URI is http://uriinfo-wildfly:8080/uriinfo/

另一种选择是通过 NarayanaLRAClient#joinLRA 方法手动注册您需要的 URL,其中 take individual URLs for different LRA endpoints or a base URI that will derive the URLs as mentioned above.