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 2020/09/09 05:59:23 UTC

[GitHub] [pulsar] Huanli-Meng commented on a change in pull request #8005: [docs] Update Functions package content

Huanli-Meng commented on a change in pull request #8005:
URL: https://github.com/apache/pulsar/pull/8005#discussion_r485351818



##########
File path: site2/docs/functions-package.md
##########
@@ -4,58 +4,24 @@ title: Package Pulsar Functions
 sidebar_label: "How-to: Package"
 ---
 
-This section provides step-by-step instructions to package Pulsar functions in Java, Python, and Go. 
+You can package Pulsar functions in Java, Python, and Go. Packaging a window function in Java is the same as [packaging a function in Java](#java).
 
-> **Tip**
->
-> - Packaging a window function in Java is the same as [packaging a function in Java](#java) as below. 
->
-> - Currently, the window function is not available in Python and Go.
+> **Note**    
+> Currently, window function is not available in Python and Go.

Review comment:
       ```suggestion
   > Currently, the window function is unavailable in Python and Go.
   ```

##########
File path: site2/docs/functions-package.md
##########
@@ -4,58 +4,24 @@ title: Package Pulsar Functions
 sidebar_label: "How-to: Package"
 ---
 
-This section provides step-by-step instructions to package Pulsar functions in Java, Python, and Go. 
+You can package Pulsar functions in Java, Python, and Go. Packaging a window function in Java is the same as [packaging a function in Java](#java).

Review comment:
       a window function or the window function?

##########
File path: site2/docs/functions-package.md
##########
@@ -4,58 +4,24 @@ title: Package Pulsar Functions
 sidebar_label: "How-to: Package"
 ---
 
-This section provides step-by-step instructions to package Pulsar functions in Java, Python, and Go. 
+You can package Pulsar functions in Java, Python, and Go. Packaging a window function in Java is the same as [packaging a function in Java](#java).
 
-> **Tip**
->
-> - Packaging a window function in Java is the same as [packaging a function in Java](#java) as below. 
->
-> - Currently, the window function is not available in Python and Go.
+> **Note**    
+> Currently, window function is not available in Python and Go.
 
 ## Prerequisite
 
-Before running a Pulsar function, you need to start Pulsar.
-
-### Run a standalone Pulsar in Docker
-
-This example uses Docker to run a standalone Pulsar.
-
-```bash
-docker run -it \
-    -p 6650:6650 \
-    -p 8080:8080 \
-    -v $PWD/data:/pulsar/data \
-    apachepulsar/pulsar:latest \
-    bin/pulsar standalone
-```
-
-> **Tip**
->
-> - `$PWD/data` is the local directory. `-v` maps the `/pulsar/data` directory in the Docker image to the local `$PWD/data` directory.
->
-> - To check whether the image starts, use the command `docker ps`.
-
-### Run Pulsar cluster in k8s
-
-For details about how to deploy a Pulsar cluster in the k8s environment, For details, see [here](helm-overview.md).
+Before running a Pulsar function, you need to start Pulsar. You can [run a standalone Pulsar in Docker](getting-started-docker.md), or [run Pulsar cluster in Kubernetes](getting-started-helm.md).

Review comment:
       run pulsar cluster or run pulsar? 

##########
File path: site2/docs/functions-package.md
##########
@@ -127,49 +93,41 @@ This example demonstrates how to package a function in Java.
         }
     }
     ```
+ 
+     For the package imported, you can use one of the following interfaces:

Review comment:
       ```suggestion
        For the imported package, you can use one of the following interfaces:
   ```

##########
File path: site2/docs/functions-package.md
##########
@@ -4,58 +4,24 @@ title: Package Pulsar Functions
 sidebar_label: "How-to: Package"
 ---
 
-This section provides step-by-step instructions to package Pulsar functions in Java, Python, and Go. 
+You can package Pulsar functions in Java, Python, and Go. Packaging a window function in Java is the same as [packaging a function in Java](#java).
 
-> **Tip**
->
-> - Packaging a window function in Java is the same as [packaging a function in Java](#java) as below. 
->
-> - Currently, the window function is not available in Python and Go.
+> **Note**    
+> Currently, window function is not available in Python and Go.
 
 ## Prerequisite
 
-Before running a Pulsar function, you need to start Pulsar.
-
-### Run a standalone Pulsar in Docker
-
-This example uses Docker to run a standalone Pulsar.
-
-```bash
-docker run -it \
-    -p 6650:6650 \
-    -p 8080:8080 \
-    -v $PWD/data:/pulsar/data \
-    apachepulsar/pulsar:latest \
-    bin/pulsar standalone
-```
-
-> **Tip**
->
-> - `$PWD/data` is the local directory. `-v` maps the `/pulsar/data` directory in the Docker image to the local `$PWD/data` directory.
->
-> - To check whether the image starts, use the command `docker ps`.
-
-### Run Pulsar cluster in k8s
-
-For details about how to deploy a Pulsar cluster in the k8s environment, For details, see [here](helm-overview.md).
+Before running a Pulsar function, you need to start Pulsar. You can [run a standalone Pulsar in Docker](getting-started-docker.md), or [run Pulsar cluster in Kubernetes](getting-started-helm.md).
 
+To check whether the Docker image starts, you can use the `docker ps` command.
 
 ## Java 
 
-This example demonstrates how to package a function in Java.
-
-> **Note**
->
-> This example assumes that you have [run a standalone Pulsar in Docker](#run-a-standalone-pulsar-in-docker) successfully.
-
+To package a function in Java, complete the following steps.
 
-1. Create a new maven project with a pom file.
+1. Create a new maven project with a pom file. In the following code sample, `mainClass` is your package name.

Review comment:
       it should be Maven

##########
File path: site2/docs/functions-package.md
##########
@@ -289,45 +233,31 @@ This example demonstrates how to package a function by **one python file** in Py
     ...
     ```
 
-    > **Tip**
-    >
-    > - For the description about the parameters (for example, `--classname`, `--py`, `--inputs`, and so on), run the command `./bin/pulsar-admin functions` or see [here](reference-pulsar-admin.md#functions).
-    > 
-    > - If you want to start a function in cluster mode, replace `localrun` with `create` in the command above. The following log indicates that the Python function starts successfully.
-    >
-    >   ```text
-    >   "Created successfully"
-    >   ```
-
 ### ZIP file
 
-This example demonstrates how to package a function by **ZIP file** in Python.
+To package a function with **ZIP file** in Python, complete the following steps.

Review comment:
       ```suggestion
   To package a function with the **ZIP file** in Python, complete the following steps.
   ```

##########
File path: site2/docs/functions-package.md
##########
@@ -449,34 +360,30 @@ This example demonstrates how to package a function in Go.
     }
     ```
 
-    > **Tip**
-    > 
-    > You can use context to connect with the Go function.
-    >
-    > ```
-    > if fc, ok := pf.FromContext(ctx); ok {
-    >    fmt.Printf("function ID is:%s, ", fc.GetFuncID())
-    >    fmt.Printf("function version is:%s\n", fc.GetFuncVersion())
-    > }
-    > ```
-
-    > **Note**
-    >
-    > - In `main()`, you **only** need to register the function name to `Start()`. **Only** one function name can be received in `Start()`. 
-    >
-    > - Go function uses Go reflection based on the received function name to verify whether the parameter list and returned value list implemented are correct. The parameter list and returned value list specified **must be** one of the following sample functions:
-    >
-    >   ```
-    >   func ()
-    >   func () error
-    >   func (input) error
-    >   func () (output, error)
-    >   func (input) (output, error)
-    >   func (context.Context) error
-    >   func (context.Context, input) error
-    >   func (context.Context) (output, error)
-    >   func (context.Context, input) (output, error)
-    >   ```
+    You can use context to connect to the Go function.
+    
+    ```
+    if fc, ok := pf.FromContext(ctx); ok {
+        fmt.Printf("function ID is:%s, ", fc.GetFuncID())
+        fmt.Printf("function version is:%s\n", fc.GetFuncVersion())
+     }
+     ```
+
+    When writing a Go function, remember that
+    - In `main()`, you **only** need to register the function name to `Start()`. **Only** one function name is received in `Start()`. 
+    - Go function uses Go reflection based on the received function name to verify whether the parameter list and returned value list implemented are correct. The parameter list and returned value list specified **must be** one of the following sample functions:

Review comment:
       I think this sentence needs to be refined:
   whether the parameter list and returned value list implemented are correct.
   The parameter list and returned value list specified **must be** one of the following sample functions:

##########
File path: site2/docs/functions-package.md
##########
@@ -127,49 +93,41 @@ This example demonstrates how to package a function in Java.
         }
     }
     ```
+ 
+     For the package imported, you can use one of the following interfaces:
+    - Function interface provided by Java 8: `java.util.function.Function`
+    - Pulsar Function interface: `org.apache.pulsar.functions.api.Function`
 
-    > **Tip**
-    >
-    > For the package imported, you can use one of the following interfaces:
-    >
-    > - Function interface provided by Java 8: `java.util.function.Function`
-    >
-    > - Pulsar Function interface: `org.apache.pulsar.functions.api.Function`
-    >
-    > The main difference between the two interfaces is that the `org.apache.pulsar.functions.api.Function` interface provides the context interface. When you write a function and want to interact with it, you can use context to obtain a wide variety of information and functionality for Pulsar Functions.
-    > 
-    > **Example** 
-    >
-    > This example uses `org.apache.pulsar.functions.api.Function` interface with context.
-    >
-    > ```
-    > package org.example.functions;
-    >
-    > import org.apache.pulsar.functions.api.Context;
-    > import org.apache.pulsar.functions.api.Function;
-    > 
-    > import java.util.Arrays;
-    >
-    > public class WordCountFunction implements Function<String, Void> {
-    >    // This function is invoked every time a message is published to the input topic
-    >    @Override
-    >    public Void process(String input, Context context) throws Exception {
-    >       Arrays.asList(input.split(" ")).forEach(word -> {
-    >           String counterKey = word.toLowerCase();
-    >           context.incrCounter(counterKey, 1);
-    >        });
-    >       return null;
-    >   }
-    > }
-    > ```
+    The main difference between the two interfaces is that the `org.apache.pulsar.functions.api.Function` interface provides the context interface. When you write a function and want to interact with it, you can use context to obtain a wide variety of information and functionality for Pulsar Functions.
+
+    The following example uses `org.apache.pulsar.functions.api.Function` interface with context.
+
+    ```
+    package org.example.functions;
+    import org.apache.pulsar.functions.api.Context;
+    import org.apache.pulsar.functions.api.Function;
+    
+    import java.util.Arrays;
+    public class WordCountFunction implements Function<String, Void> {
+       // This function is invoked every time a message is published to the input topic
+        @Override
+        public Void process(String input, Context context) throws Exception {
+           Arrays.asList(input.split(" ")).forEach(word -> {
+               String counterKey = word.toLowerCase();
+               context.incrCounter(counterKey, 1);
+            });
+           return null;
+       }
+     }
+     ```
 
 3. Package the Java function.
 
     ```bash
     mvn package
     ```
 
-    After the Java function is packaged, a `target` directory is automatically created. Open the `target` directory to see if there is a jar package similar to `java-function-1.0-SNAPSHOT.jar`.
+    After the Java function is packaged, a `target` directory is created automatically. Open the `target` directory to see if there is a jar package similar to `java-function-1.0-SNAPSHOT.jar`.

Review comment:
       ```suggestion
       After the Java function is packaged, a `target` directory is created automatically. Open the `target` directory to check if there is a JAR package similar to `java-function-1.0-SNAPSHOT.jar`.
   ```




----------------------------------------------------------------
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