1
votes

i need to created Azure function BlobTrigger using Java to monitor my storage container for new and updated blobs.

tried with below code

import java.util.*;
import com.microsoft.azure.serverless.functions.annotation.*;
import com.microsoft.azure.serverless.functions.*;
import java.nio.file.*;
import java.io.*;
import java.net.URL;
import java.net.URLConnection;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import com.microsoft.azure.storage.*;
import com.microsoft.azure.storage.blob.*;

@FunctionName("testblobtrigger")
 public String testblobtrigger(@BlobTrigger(name = "test", path = "testcontainer/{name}") String content) {
     try {
         return String.format("Blob content : %s!", content);

     } catch (Exception e) {
         // Output the stack trace.
         e.printStackTrace();
         return "Access Error!";
     }
 }

when executed it is showing error

Storage binding (blob/queue/table) must have non-empty connection. Invalid storage binding found on method:

it is working when added connection string

public String kafkablobtrigger(@BlobTrigger(name = "test", path = "testjavablobstorage/{name}",connection=storageConnectionString) String content) {

why i need to add connection string when using blobtrigger?

in C# it is working without connection string:

public static void ProcessBlobContainer1([BlobTrigger("container1/{blobName}")] CloudBlockBlob blob, string blobName)
{
    ProcessBlob("container1", blobName, blob);
}

i didn't see any Java sample for Azure functions for @BlobTrigger.

1
C# falls back to default configuration name. Maybe java doesn't? What's the problem with adding connection string? - Mikhail Shilkov

1 Answers

0
votes

After all, connection is necessary for the trigger to identify where the container locates.

After test I find @Mikhail is right. For C#, the default value(in local.settings.json or in application settings in portal) will be used if connection is ignored. But unfortunately there's no same settings for java.

You can add @StorageAccount("YourStorageConnection") below your @FuncionName as it's another valid way to choose. And value of YourStorageConnection in local.settings.json or in portal's application settings is up to you.

You can follow this tutorial, use mvn azure-functions:add to find four(Http/Blob/Queue/TimerTrigger) templates for java.