簡體   English   中英

在Azure App Service中運行Wildfly,如何配置JGroups進行會話復制

[英]Running Wildfly in Azure App Service, how to configure JGroups for session replication

通過自定義Java應用程序[ https://azure.microsoft.com/en-us/documentation/articles/web-sites-java-custom-upload/] ,可以將Wildfly作為Azure App Service運行。 但是,在向JGroups注冊時,應用程序服務節點不知道內部IP地址。 他們總是暴露127.0.0.1。 為了使JGroups集群成員進行通信,我們需要該節點的IP地址。

Wildfly如何確定可用於向JGroups群集注冊的主機的內部IP地址?

根據我的經驗,我認為您可以嘗試使用Java的Azure SDK從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. WebSiteManagementClientWebSiteManagementClientImpl
  2. 托管環境操作
  3. 地址響應

您可以對bind_addr使用特殊的關鍵字, bind_addr詳細信息,請參見[1]。 例如, bind_addr=match-address:192.168.1.*嘗試選擇給定子網中的IP地址。

[1] http://www.jgroups.org/manual/index.html#Transport

您可以使用Peter的代碼(上述)檢測可用的IP地址,然后在JGroups中設置bind_addr ,例如:

InetAddress bind_addr; // detect address by using Azure's SDK
JChannel ch=new JChannel("config.xml");
TP transport=ch.getProtocolStack().getTransport();
transport.setBindAddress(bind_addr);
ch.connect("mycluster");

重要的是您需要在連接通道之前設置綁定地址。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM