Skip to content

Instantly share code, notes, and snippets.

@trisberg
Last active March 23, 2018 17:23
Show Gist options
  • Save trisberg/e113d1ccc15859fba13b3796cec69062 to your computer and use it in GitHub Desktop.
Save trisberg/e113d1ccc15859fba13b3796cec69062 to your computer and use it in GitHub Desktop.

Demo - Simple riff Java function using javac

Create the function code

  1. Create the source directory and class file

    $ mkdir -p upper/functions
    $ cd upper
    $ touch ./functions/Upper.java
  2. Write the function class

    Add the Function implementation

    function/Upper.java
    package functions;
    
    import java.util.function.Function;
    
    public class Upper implements Function<String, String> {
    
    	public String apply(String name) {
    		return name.toUpperCase();
    	}
    }
  3. Build and package the function

    $ mkdir -p bin
    $ javac -source 1.8 -target 1.8 -d bin ./functions/Upper.java
    $ jar cvf upper.jar -C bin functions/Upper.class

Now it is time for riff

  1. Create function and deploy to riff

    $ riff create java --artifact upper.jar \
        --handler 'functions.Upper'
  2. Test the function running in riff

    $ riff publish -d hello -r
    Posting to http://192.168.99.100:32657/requests/upper
    HELLO
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment