pulsar-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From GitBox <...@apache.org>
Subject [GitHub] [pulsar] jerrypeng commented on a change in pull request #4507: [Docs] Update site2/docs/functions-overview.md
Date Tue, 11 Jun 2019 16:53:34 GMT
jerrypeng commented on a change in pull request #4507: [Docs] Update site2/docs/functions-overview.md
URL: https://github.com/apache/pulsar/pull/4507#discussion_r292559163
 
 

 ##########
 File path: site2/docs/functions-overview.md
 ##########
 @@ -262,18 +280,46 @@ class ContextAwareFunction(Function):
         log.info("Function tenant/namespace/name: {0}/{1}/{2}".format(function_tenant, function_namespace,
function_name))
 ```
 
+### Go
+
+The following is a Go function example that uses information about its context.
+
+```
+import (
+	"context"
+	"fmt"
+
+    "github.com/apache/pulsar/pulsar-function-go/log"
+	"github.com/apache/pulsar/pulsar-function-go/pf"
+)
+
+func contextFunc(ctx context.Context) {
+	if fc, ok := pf.FromContext(ctx); ok {
+		tenant := fc.GetFuncTenant()
+		namespace := fc.GetFuncNamespace()
+		name := fc.GetFuncName()
+		log.Info("Function tenant/namespace/name: %s/%s/%s\n", tenant, namespace, name)
+	}
+}
+
+func main() {
+	pf.Start(contextFunc)
+}
+
+```
+
 ## Deployment
 
-The Pulsar Functions feature was built to support a variety of deployment options. At the
moment, there are two ways to run Pulsar Functions:
+Pulsar Functions support a variety of deployment options. You can run Pulsar Functions in
the following ways.
 
 Deployment mode | Description
 :---------------|:-----------
-[Local run mode](#local-run-mode) | The function runs in your local environment, for example
on your laptop
-[Cluster mode](#cluster-run-mode) | The function runs *inside of* your Pulsar cluster, on
the same machines as your Pulsar [brokers](reference-terminology.md#broker)
+[Local run mode](#local-run-mode) | The function runs in your local environment, for example,
on your laptop.
+[Cluster mode](#cluster-run-mode) | The function runs *inside of* your Pulsar cluster, on
the same machines as your Pulsar [brokers](reference-terminology.md#broker).
 
 ### Local run mode
 
-If you run a Pulsar Function in **local run** mode, it will run on the machine from which
the command is run (this could be your laptop, an [AWS EC2](https://aws.amazon.com/ec2/) instance,
etc.). Here's an example [`localrun`](reference-pulsar-admin.md#localrun) command:
+If you run Pulsar Functions in the **local run** mode, you run it on the machine where you
run commands(for example, your laptop, an [AWS EC2](https://aws.amazon.com/ec2/) instance).
The following example is about the [`localrun`](reference-pulsar-admin.md#localrun) command.
 
 Review comment:
   ```suggestion
   If you run a Pulsar Function in the **local run** mode, you run it on the machine where
you run commands(for example, your laptop, an [AWS EC2](https://aws.amazon.com/ec2/) instance).
The following example is about the [`localrun`](reference-pulsar-admin.md#localrun) command.
   ```

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

Mime
View raw message