为什么Java Azure Function应用程序在尝试访问Azure数据采集时冻结



我正在开发一个Java Azure函数,该函数需要从Azure Datalake Gen2下载一个文件。
当该函数尝试读取文件时,它会冻结,不会引发异常,也不会向控制台写入任何内容。

我使用azure存储文件datalake SDK进行Java依赖,这是我的代码:

import com.azure.storage.common.StorageSharedKeyCredential;
import com.azure.storage.file.datalake.DataLakeDirectoryClient;
import com.azure.storage.file.datalake.DataLakeFileClient;
import com.azure.storage.file.datalake.DataLakeFileSystemClient;
import com.azure.storage.file.datalake.DataLakeServiceClient;
import com.azure.storage.file.datalake.DataLakeServiceClientBuilder;
public DataLakeServiceClient GetDataLakeServiceClient(String accountName, String accountKey)
{
StorageSharedKeyCredential sharedKeyCredential = new StorageSharedKeyCredential(accountName, accountKey);
DataLakeServiceClientBuilder builder = new DataLakeServiceClientBuilder();
builder.endpoint("https://" + accountName + ".dfs.core.windows.net");
builder.credential(sharedKeyCredential);
return builder.buildClient();
}
public void DownloadFile(DataLakeFileSystemClient fileSystemClient, String fileName) throws Exception{
DataLakeDirectoryClient directoryClient = fileSystemClient.getDirectoryClient("DIR");
DataLakeDirectoryClient subdirClient= directoryClient.getSubdirectoryClient("SUBDIR");
DataLakeFileClient fileClient = subdirClient.getFileClient(fileName);
File file = new File("downloadedFile.txt");
OutputStream targetStream = new FileOutputStream(file);
fileClient.read(targetStream);
targetStream.close();
}
@FunctionName("func")
public HttpResponseMessage run(
@HttpTrigger(name = "req", methods = {HttpMethod.GET}, authLevel = AuthorizationLevel.ANONYMOUS)
HttpRequestMessage<Optional<String>> request,
final ExecutionContext context
)
{
String fileName= request.getQueryParameters().get("file");
DataLakeServiceClient datalakeClient= GetDataLakeServiceClient("datalake", "<the shared key>");
DataLakeFileSystemClient datalakeFsClient= datalakeClient.getFileSystemClient("fs");
DownloadFile(datalakeFsClient, fileName);
}   

应用程序在点击fileClient.read(targetStream(时冻结
我尝试过非常小的文件,我检查过凭据和文件路径,数据采集的访问权限,我切换到SAS令牌-结果是一样的:没有任何错误,但应用程序冻结了

我正在使用这些Maven依赖项:

<dependency>
<groupId>com.microsoft.azure.functions</groupId>
<artifactId>azure-functions-java-library</artifactId>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-file-datalake</artifactId>
<version>12.2.0</version>
</dependency>

所以我也面临同样的问题。然后我发现了这个。

https://github.com/Azure/azure-functions-java-library/issues/113

这对我在java8,azure函数v3上起到了作用。

将FUNCTION S_WORKER_JAVA_LOAD_APP_LBS设置为True在功能应用程序应用程序设置中。然后保存并重新启动功能应用程序。它会起作用的。

如果它对你也有效,请检查并更新。

最新更新