Azure / azure-functions-java-library

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

No trigger binding specified for CustomBindings #90

Closed TsuyoshiUshio closed 5 years ago

TsuyoshiUshio commented 5 years ago

Problem

I have an extension it works on .NET side. I create a Java implementation using CustomBinding, I install the extension and execute Azure Functions with maven, then I encounter this issue. What is missing my configuration?

KafkaTrigger-Java: No trigger binding specified. A function must have a trigger input binding.

Configuration

My Trigger's definition is like this.

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@CustomBinding(direction = "in", name = "kafkaEvents", type = "KafkaTriggerAttribute")
public @interface KafkaTrigger {

I tried to change the type for other type. the "KafkaTriggerAttirbute" is taken from the definition of IExtensionConfigProvider implementation of C#.

            // register our trigger binding provider
            var triggerBindingProvider = new KafkaTriggerAttributeBindingProvider(config, options, converterManager, nameResolver, loggerFactory);
            context.AddBindingRule<KafkaTriggerAttribute>()
                .BindToTrigger(triggerBindingProvider);

The function.json which is genareted by pacakge is

{
  "scriptFile" : "../kafka-function-1.0-SNAPSHOT.jar",
  "entryPoint" : "com.contoso.kafka.Function.run",
  "bindings" : [ {
    "type" : "KafkaTriggerAttribute",
    "direction" : "in",
    "name" : "kafkaEvents",
    "topic" : "pageviews",
    "consumerGroup" : "azfunc",
    "brokerList" : "LocalBroker"
  } ]
}

I also tried the same value of the type of C# function.json 's type. it was "kafkaTrigger" however, It doesn't work. It returns "[04/20/2019 18:27:40] KafkaTrigger-Java: The binding type(s) 'kafkaTrigger' are not registered. Please ensure the type is correct and the binding extension is installed." Any ideas?

Implementation of IExtensionConfigProvider

https://github.com/Azure/azure-functions-kafka-extension/blob/tsuyoshi/javaimpl/src/Microsoft.Azure.WebJobs.Extensions.Kafka/Config/KafkaExtensionConfigProvider.cs#L21

Java implementation

https://github.com/Azure/azure-functions-kafka-extension/blob/tsuyoshi/javaimpl/binding-library/java/src/main/java/com/microsoft/azure/functions/kafka/annotation/KafkaTrigger.java

pragnagopa commented 5 years ago

"type" : "KafkaTriggerAttribute", does not look right. type needs to point to the binding type or trigger type.

TsuyoshiUshio commented 5 years ago

Hi @pragnagopa In this case what is the binding type and trigger type?

binding type might be Kafka, right?

    [Extension("Kafka", configurationSection: "kafka")]
    public class KafkaExtensionConfigProvider : IExtensionConfigProvider

Then What is the trigger type? Where can I find it?

pragnagopa commented 5 years ago

Right. binding type is kafka "type" : "Kafka"

TsuyoshiUshio commented 5 years ago

Hi @pragnagopa

I tried Kafka however, the result was the same.

[04/22/2019 17:48:02] KafkaTrigger-Java: No trigger binding specified. A function must have a trigger input binding.

This is the function.json. How can I register the trigger bindings? How the code find out the list of the trigger bindings?

{
  "scriptFile" : "../kafka-function-1.0-SNAPSHOT.jar",
  "entryPoint" : "com.contoso.kafka.Function.run",
  "bindings" : [ {
    "type" : "Kafka",
    "direction" : "in",
    "name" : "kafkaEvents",
    "topic" : "pageviews",
    "consumerGroup" : "azfunc",
    "brokerList" : "LocalBroker"
  } ]
}
TsuyoshiUshio commented 5 years ago

Hi @pragnagopa

I did some research. I read the code of azure-funcitons-host, I found the code for the BindingMetadata it says

        public bool IsTrigger
        {
            get
            {
                return Type.EndsWith("trigger", StringComparison.OrdinalIgnoreCase);
            }
        }

https://github.com/Azure/azure-functions-host/blob/f9540d6aaafc56ecd3d8d045edfc159a85ea9ba1/src/WebJobs.Script/Description/Binding/BindingMetadata.cs#L50

Also, When I see the schema of the function.json, I can't find kafka trigger on schema.

http://json.schemastore.org/function

Do I need to register the trigger? Or In case of KafkaTriggerAttribute, then KafkaTrigger ? In case of SinaglR, they don't have a trigger.

TsuyoshiUshio commented 5 years ago

Eventually, 'kafkaTrigger' works. It might be the name of KafkaTriggerAttribute'. The binding name should be something with 'trigger'. It also has other problem. I missed the installation of the DLL of the Extension. In this case it shows the same error message. In this case, I missed install the extension nuget packages. That is why I can't find the target dll on the bin folder. For the local installation the extension, this works for me.

func extensions install --source ~/Downloads/NuGet  -p Microsoft.Azure.WebJobs.Extensions.Kafka --version 0.0.1-alpha