I am using azure sdk for java v11.0.1 to upload files to blob storage.This error comes sometimes once in a week and it creates an outage for the application.
java.util.concurrent.TimeoutException: The source did not signal an event for 60 seconds and has been terminated.
2023-03-21T10:30:53.721545956Z at io.reactivex.internal.operators.single.SingleTimeout$TimeoutMainObserver.run(SingleTimeout.java:123) ~[rxjava-2.2.9.jar!/:na]
2023-03-21T10:30:53.721551557Z at io.reactivex.internal.schedulers.ScheduledDirectTask.call(ScheduledDirectTask.java:38) ~[rxjava-2.2.9.jar!/:na]
2023-03-21T10:30:53.721555757Z at io.reactivex.internal.schedulers.ScheduledDirectTask.call(ScheduledDirectTask.java:26) ~[rxjava-2.2.9.jar!/:na]
2023-03-21T10:30:53.721559957Z at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264) ~[na:na]
2023-03-21T10:30:53.721563857Z at java.base/java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) ~[na:na]
The above error message indicates that a timeout occurred while attempting to upload a file to AZURE Storage using the SDK for Java. The timeout occurred because the source did not signal an event for 60 seconds and was terminated automatically.
I have used below code to upload the Files to Azure Blob Storage.
import com.azure.storage.blob.BlobClient;
import com.azure.storage.blob.BlobContainerClient;
import com.azure.storage.blob.BlobServiceClient;
import com.azure.storage.blob.BlobServiceClientBuilder;
public class App {
public static void main(String[] args) {
String connectStr ="DefaultEndpointsProtocol=https;AccountName=<storageaccountname>;AccountKey=xxxxxxxxxxxxxxxxxxxxxxxxxxxxL132fS9qbo2NGFL/GdLuwyWiSn+AStm9symA==;EndpointSuffix=core.windows.net";
BlobServiceClient blobServiceClient = new BlobServiceClientBuilder().connectionString(connectStr).buildClient();
String containerName = "<containername>";
BlobContainerClient containerClient = blobServiceClient.getBlobContainerClient(containerName);
String localPath = "<localpath>;
BlobClient blobClient = containerClient.getBlobClient("sample09.xlsx");
blobClient.uploadFromFile(localPath);
System.out.println("File uploaded!!!!");;
}
}
You need to change the below dependency in pom.xml
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-identity</artifactId>
<version>1.7.2</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.azure</groupId>
<artifactId>azure-storage-blob</artifactId>
<version>12.21.1</version>
</dependency>
Once ran the above code files are uploaded to Azure Container successfully.
