可以通过自定义 Java 应用程序将 Wildfly 作为 Azure 应用程序服务运行 [ https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/] 。但是,应用服务节点在向 JGroups 注册时不知道内部 IP 地址。他们总是暴露 127.0.0.1。为了使 JGroups 集群成员进行通信,我们需要一个众所周知的节点 IP 地址。
Wildfly 如何确定可用于向 JGroups 集群注册的主机的内部 IP 地址?
最佳答案
根据我的经验,我认为您可以尝试使用 Azure SDK for Java 从 WebSiteManagementClient
获取主机的内部 IP 地址。
下面是获取内部 IP 地址的示例代码。
String userName = "<user-name>";
String password = "<password>";
String resourceGroupName = "<resource-group-name>";
String name = "<webapp-name>";
ServiceClientCredentials credentials = new BasicAuthenticationCredentials(userName, password);
WebSiteManagementClient webSiteManagementClient = new WebSiteManagementClientImpl(credentials);
HostingEnvironmentsOperations hostingEnvironmentsOperations = webSiteManagementClient.getHostingEnvironmentsOperations();
ServiceResponse<AddressResponse> serviceResponse = hostingEnvironmentsOperations.getHostingEnvironmentVips(resourceGroupName, name);
AddressResponse addressResponse = (AddressResponse) serviceResponse.getBody();
String internalIp = addressResponse.getInternalIpAddress();
要运行上述示例,您需要将依赖库添加到您的 Maven 项目中,请参阅下面的依赖项。
<dependency>
<groupId>com.microsoft.azure</groupId>
<artifactId>azure-svc-mgmt-websites</artifactId>
<version>0.9.2</version>
</dependency>
以上示例代码中关键类的更多详细信息,请参见下文。
关于java - 在 Azure 应用服务中运行 Wildfly,如何配置 JGroups 进行 session 复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37663500/