You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@pulsar.apache.org by GitBox <gi...@apache.org> on 2019/07/17 04:02:59 UTC

[GitHub] [pulsar] wolfstudy commented on a change in pull request #4725: [docs] Add functions-develop file for Pulsar Functions(new)

wolfstudy commented on a change in pull request #4725: [docs] Add functions-develop file for Pulsar Functions(new)
URL: https://github.com/apache/pulsar/pull/4725#discussion_r304211821
 
 

 ##########
 File path: site2/docs/functions-develop.md
 ##########
 @@ -0,0 +1,570 @@
+---
+id: functions-develop
+title: Develop Pulsar Functions
+sidebar_label: Develop functions
+---
+
+This tutorial walks you through how to develop Pulsar Functions.
+
+## Available APIs
+In Java, Python, and Go, you have two options to write Pulsar Functions.
+
+Interface | Description | Use cases
+:---------|:------------|:---------
+Language-native interface | No Pulsar-specific libraries or special dependencies required (only core libraries from Java/Python/Go). | Functions that do not require access to the function [context](#context).
+Pulsar Function SDK for Java/Python/Go | Pulsar-specific libraries that provide a range of functionality not provided by "native" interfaces. | Functions that require access to the function [context](#context).
+
+<!--DOCUSAURUS_CODE_TABS-->
+<!--Java-->
+<!--Python-->
+In Python, the language-native function, which adds an exclamation point to all incoming strings and publishes the resulting string to a topic, has no external dependencies.
+
+```python
+def process(input):
+    return "{}!".format(input)
+```
+
+However, the function uses Pulsar Functions [SDK for Python](#python-sdk-functions):
+
+```python
+from pulsar import Function
+
+class DisplayFunctionName(Function):
+    def process(self, input, context):
+        function_name = context.function_name()
+        return "The function processing this message has the name {0}".format(function_name)
+```
+<!--Go-->
+The following example uses Pulsar Functions SDK.
+
+```
+import (
 
 Review comment:
   Sorry, Go Function does not support schema-related functions, so now Go Function's input and output can only be `[]byte`. 
   
   Here, this [code example](https://github.com/apache/pulsar/blob/master/pulsar-function-go/examples/inputFunc.go#L20-L36) might be more appropriate:
   ```
   package main
   
   import (
   	"context"
   	"fmt"
   
   	"github.com/apache/pulsar/pulsar-function-go/pf"
   )
   
   func HandleRequest(ctx context.Context, in []byte) error{
   	fmt.Println(string(in) + "!")
   	return nil
   }
   
   func main() {
   	pf.Start(HandleRequest)
   }
   ```

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services