Azure / azure-functions-java-library

Contains annotations for writing Azure Functions in Java
MIT License
43 stars 43 forks source link

[BUG] Should be able to support variable binding name for @EventGridTrigger #194

Closed fangjian0423 closed 1 year ago

fangjian0423 commented 1 year ago

hi, Team. Could you please help to take a look at this issue?

Copy from https://github.com/Azure/azure-sdk-for-java/issues/32326.

Describe the bug I have a application that will listen for EventGridEvent. I don't want to "hardcode" the evengridtopic to use. I want to use %variable% syntax like for other triggers (look at CosmosDBOutput, _

like

@FunctionName("ProcessFileUpload")
    public void ProcessFileUpload(
            @EventGridTrigger(name = "event") String uploadData,
            @CosmosDBOutput(name = "database",
                databaseName = "%DatabaseName%",
                collectionName = "%CollectionName%",
                connectionStringSetting = "CosmosConnectionString") OutputBinding<String> outputItem,
                final ExecutionContext context) {
        context.getLogger().info("Uploaded data: " + uploadData);
        outputItem.setValue(uploadData);
    }

Suppose that I want to deploy the same application but they will monitor different Topics , it will be easy to change the value in function.json.

But now, I'll have to clone the repository and change the name "hardcoded in EventGridTrigger(name="topic1") -> EventGridTrigger(name="topic2").. It doesn't make sense, unless I missed something and there a way to do that.

Exception or Stack Trace [2022-11-24T13:09:14.376Z] The 'blobStorageEventGridTrigger' function is in error: The binding name %EventGridTopic% is invalid. Please assign a valid name to the binding.

Code Snippet here my code

@FunctionName("blobStorageEventGridTrigger")
    public void execute(
            @EventGridTrigger(
                    name = "%EventGridTopic%")
            EventSchema content,
            final ExecutionContext context) {
        LOGGER.info("Java Event Grid trigger function executed. EventSchema:[{}]", content);
        handleRequest(content, context);
    }

in local.settings.json

...
"EventGridTopic": "blobeventtopic",
....

if I change to code to

@FunctionName("blobStorageEventGridTrigger")
    public void execute(
            @EventGridTrigger(
                    //name = "%EventGridTopic%")
                    name = "blobeventtopic")
            EventSchema content,
            final ExecutionContext context) {
        LOGGER.info("Java Event Grid trigger function executed. EventSchema:[{}]", content);
        handleRequest(content, context);
    }

the application will run

Functions:

        blobStorageEventGridTrigger: eventGridTrigger

For detailed output, run func with --verbose flag.
[2022-11-24T13:24:42.794Z] Worker process started and initialized.
[2022-11-24T13:24:47.387Z] Host lock lease acquired by instance ID '000000000000000000000000A69F7E4C'.

Expected behavior I expect to be able to set the topic name to listen with configuration using %% syntax

Setup (please complete the following information):

Information Checklist Kindly make sure that you have added all the following information above and checkoff the required fields otherwise we will treat the issuer as an incomplete report

kaibocai commented 1 year ago

Reply back to the original issue, will keep monitoring that one and close this issue.