Java functions can be added by loading a Java jar file (.jar). When adding a Java files, you also need to specify the name of the class to execute as the function. For example, if the Python file is called function.py and the class is exclamation, then the class name would be “function.exclamation”. The file can contain multiple classes, but only one will be used. If there is no class in the Python file, for example when using a basic function, just specify the filename without the extension (ex. function).
ADDING A Java FUNCTION FILE
- From the left sidebar menu, select Functions/Add.
- Click on the Choose File button from the Function File field.
- Using the dialog box, select the Java jar file containing the function code.
- If the jar file has more than one class, then the Class Name drop-down will contain all the classes. Choose the class you want to execute as the function.
- Enter the function name in the Function Name field. The name will default to the filename without the extension.
- Select the namespace where you want to create the function in the Namespace field. Note that all topics (input, output, logs) must be in the same namespace as the function.
- If the Runtime field did not default to Java, set it to Java.
- Specify the input topic for the function in the Input Topic field. This the topic that the function will connect to and process messages from. If the input topic doesn’t exist when the function is added, it will be automatically created.
- Optionally, specify the output topic in the Output Topic field. If the function returns a value, you specify an output topic for this value to be published to. If the output topic doesn’t exist it will be created automatically when the function executes.
- Optionally, specify the log topic in the Log Topic field. If the function generates logs, you should specify a log topic. If the log topic doesn’t exist, it will be created when the function generates a log message.
- Specify the number of instances of this function to run in the Instances field. If the input topic receives a high rate of messages, you may need multiple function instances to keep up with the load. Note that the number of instances you can create will be limited by your Plan.
- Select the processing guarantee in the Processing Guarantee field. This field specifies how many times the function will be executed successfully for each message on the input topic.
- If the processing guarantee is At Least Once, enter the function timeout in milliseconds in the Time Out In Ms field.
- If you want the message to be automatically acknowledged when the function runs successfully, click on the Auto Ack checkbox. If you disable automatic acknowledgment, you must explicitly acknowledge the message in your function.
- If your function uses configurations keys as input, click on Click For Config Keys to display the key settings. Enter the key and value the Add Key button. To remove a key you have added, click on the X beside the key name.
- To add the function, click on the Add button. If the function is successfully added you will see the Function Details screen for the function.