Azure / azure-functions-java-library

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

Add CustomBinding annotation #76

Closed pragnagopa closed 5 years ago

pragnagopa commented 5 years ago

Sample code to use CustomBinding annotation

@FunctionName("CustomTriggerSample")
    public static String CustomTriggerSample(       
        @CustomBinding(direction = "in", name = "customTriggerInputName", type = "customTrigger") String customTriggerInput
    ) 

Fixes #75

jeffhollan commented 5 years ago

Looks great - would be curious to know if IDEs will throw a fit if you have a custom attribute and additional properties like hubname = "mySignalRHub" that aren't explicitly defined in the interface.

pragnagopa commented 5 years ago

To add additional properties, users need to define an annotation as there annotations cannot be inherited. Will provide code samples on how to add additional properties.

pragnagopa commented 5 years ago

@jeffhollan - Here is the example code for defining additional properties:

package com.microsoft.azure.functions.worker.broker.tests;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.ElementType;

import com.microsoft.azure.functions.annotation.CustomBinding;

@Target(ElementType.PARAMETER)
@Retention(RetentionPolicy.RUNTIME)
@CustomBinding(direction = "in", name = "message", type = "customBinding")
public @interface TestCustomBinding {
   String index();
   String path();
}

public void CustomBinding_Valid(@HttpTrigger(name = "req", methods = { HttpMethod.GET,
      HttpMethod.POST }, authLevel = AuthorizationLevel.FUNCTION) HttpRequestMessage<String> request,
      @TestCustomBinding(index = "testIndex", path = "testPath") String customInput) {
  }

Users have to define an annotation. Does this look ok?