java - 在 Azure 应用服务中运行 Wildfly,如何配置 JGroups 进行 session 复制

标签 java azure wildfly azure-web-app-service jgroups

可以通过自定义 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>

以上示例代码中关键类的更多详细信息,请参见下文。

  1. WebSiteManagementClient & WebSiteManagementClientImpl
  2. HostingEnvironmentsOperations
  3. AddressResponse

关于java - 在 Azure 应用服务中运行 Wildfly,如何配置 JGroups 进行 session 复制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37663500/

相关文章:

java - 在 WildFly for IBM MQ 上部署 MDB 因连接错误而失败

java - 是什么导致数组越界错误以及如何清理我的代码?

java - 想要将数组的值相互组合并显示它们

java - 如何在jdbc中执行oracle过程

azure - nuget 命令在 azure devops 中 IncludeReferencedProjects

c# - 无法在 Azure C# 上创建存储帐户

java - context.lookup ("datasource")返回 org.jboss.jca.adapters.jdbc.WrapperDataSource

java - 制作幻灯片程序

multithreading - 如何停止Azure辅助角色

java - JSR 352 : Wildfly9/JBeret - How to call a batch job that it is not contained at the same deployment file level