[英]How to read file changes in azure blob storage?
I am trying to read a file from azure blob storage as byte stream as below:我正在尝试从 azure blob 存储中读取文件作为字节 stream 如下:
public static final String storageConnectionString =
"DefaultEndpointsProtocol=https;AccountName=*;AccountKey=*;EndpointSuffix=core.windows.net";
public static void main(String[] args) {
try {
CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString);
CloudBlobClient blobClient = storageAccount.createCloudBlobClient();
CloudBlobContainer container = blobClient.getContainerReference("inputfile");
CloudBlob blob = container.getBlockBlobReference("test.txt");
InputStream input = blob.openInputStream();
InputStreamReader inr = new InputStreamReader(input, "UTF-8");
String output = IOUtils.toString(inr);
System.out.println(output);
System.out.println("read is success");
} catch (Exception e) {
// Output the stack trace.
e.printStackTrace();
}
}
I am able to read the file from azure file storage.我能够从 azure 文件存储中读取文件。 I am trying to create something like Java WatchService where if there is any change in file i want read the changes and print data for example below let say i have file test.txt file in blob initially it have data some thing like below我正在尝试创建类似 Java WatchService 之类的东西,如果文件有任何更改,我想读取更改并打印数据,例如下面假设我在 blob 中有文件 test.txt 文件,最初它有如下数据
"Hello"
My program should print "Hello"
.我的程序应该打印"Hello"
。
After some time i will update file with "world"
, now i want to print only "world"
which is a new change in file.一段时间后,我将使用"world"
更新文件,现在我只想打印"world"
,这是文件中的新更改。
Is it possible in azure blob storage? azure blob存储是否可以? I saw the API of azure_blob_storage
but didn't find any method like java WatchServices.我看到了azure_blob_storage的azure_blob_storage
,但没有找到像java WatchServices这样的方法。 Could you please help me how can i read file changes in azure blob storage?您能帮我如何读取 azure blob 存储中的文件更改吗?
There's no such service.没有这样的服务。 However, you can use Event Grid which is an event repository, and subscribe to changes in your Azure storage account (new / updates blobs), then, trigger some function (maybe an Azure Function) to return the changes to client. However, you can use Event Grid which is an event repository, and subscribe to changes in your Azure storage account (new / updates blobs), then, trigger some function (maybe an Azure Function) to return the changes to client.
And here's a step by step how to do it:这里是一步一步如何做到这一点:
https://docs.microsoft.com/en-us/azure/event-grid/blob-event-quickstart-portal https://docs.microsoft.com/en-us/azure/event-grid/blob-event-quickstart-portal
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.