当以非快速周期调用java函数时,我的Blob输出成功运行。但是在快速循环中调用函数时会出错。由于Java不支持持久单例,因此我只需要使每个文件都具有唯一的名称即可。
如何为名称添加随机字符串或guid,以使每个文件都获得唯一的名称,即使时间戳是相同的。
错误:
system.Private.CoreLib: Exception while executing function: Functions.TopicTriggerDatalakeOutput.
Microsoft.Azure.WebJobs.Host: Error while handling parameter _binder after function returned:.
Microsoft.WindowsAzure.Storage: The specified block list is invalid.
CODE:
@BlobOutput(
name = "target",
connection = "DataLakeConnString",
path = "profile/blob_{DateTime}.csv")
OutputBinding<String> outputItem,
基于Java的Azure函数声明部分中提供的Blob名称必须为常量,因此,如果要在绑定中直接向Blob添加随机GUID,则不可能。
但是您的想法仍然可以实现,只需将逻辑放在函数中,就像这样:
String connectStr = "DefaultEndpointsProtocol=https;AccountName=0730bowmanwindow;AccountKey=xxx;EndpointSuffix=core.windows.net";
String containerName = "yourcontainername";
String fileName = "yourblobprefix" + java.util.UUID.randomUUID() + ".txt";
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();
BlobContainerClient containerClient = blobServiceClient.createBlobContainer(containerName);
BlobClient blobClient = containerClient.getBlobClient(fileName);
long streamlong = request.getBody().get().length();
String st = request.getBody().get();
InputStream inputstream = new ByteArrayInputStream(st.getBytes());
blobClient.upload(inputstream, streamlong, true);