wolfstudy commented on a change in pull request #3672: Added perf 
producer/consumers for Go client lib
URL: https://github.com/apache/pulsar/pull/3672#discussion_r259564402
 
 

 ##########
 File path: pulsar-client-go/pulsar-perf-go/perf-consumer.go
 ##########
 @@ -0,0 +1,116 @@
+//
+// Licensed to the Apache Software Foundation (ASF) under one
+// or more contributor license agreements.  See the NOTICE file
+// distributed with this work for additional information
+// regarding copyright ownership.  The ASF licenses this file
+// to you under the Apache License, Version 2.0 (the
+// "License"); you may not use this file except in compliance
+// with the License.  You may obtain a copy of the License at
+//
+//   http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing,
+// software distributed under the License is distributed on an
+// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+// KIND, either express or implied.  See the License for the
+// specific language governing permissions and limitations
+// under the License.
+//
+
+package main
+
+import (
+       "context"
+       "encoding/json"
+       "fmt"
+       "github.com/apache/pulsar/pulsar-client-go/pulsar"
+       "github.com/spf13/cobra"
+       "log"
+       "sync/atomic"
+       "time"
+)
+
+type ConsumeArgs struct {
+       Topic             string
+       SubscriptionName  string
+       ReceiverQueueSize int
+}
+
+var consumeArgs ConsumeArgs
+
+var cmdConsume = &cobra.Command{
+       Use:   "consume <topic>",
+       Short: "Consume from topic",
+       Args:  cobra.ExactArgs(1),
+       Run: func(cmd *cobra.Command, args []string) {
+               consumeArgs.Topic = args[0]
+               consume()
+       },
+}
+
+func initConsumer() {
+       cmdConsume.Flags().StringVarP(&consumeArgs.SubscriptionName, 
"subscription", "s", "sub", "Subscription name")
+       cmdConsume.Flags().IntVarP(&consumeArgs.ReceiverQueueSize, 
"receiver-queue-size", "r", 1000, "Receiver queue size")
+}
+
+func consume() {
+       b, _ := json.MarshalIndent(clientArgs, "", "  ")
+       fmt.Println("Client config: ", string(b))
+       b, _ = json.MarshalIndent(consumeArgs, "", "  ")
+       fmt.Println("Consumer config: ", string(b))
+
+       client, err := pulsar.NewClient(pulsar.ClientOptions{
+               URL:                    clientArgs.ServiceUrl,
+               IOThreads:              clientArgs.IoThreads,
+               StatsIntervalInSeconds: 0,
+       })
+
+       if err != nil {
+               log.Fatal(err)
+       }
+
+       defer client.Close()
+
+       consumer, err := client.Subscribe(pulsar.ConsumerOptions{
+               Topic:            consumeArgs.Topic,
+               SubscriptionName: consumeArgs.SubscriptionName,
+       })
+
+       if err != nil {
+               log.Fatal(err)
+       }
+
+       defer consumer.Close()
+
+       ctx := context.Background()
+
+       var msgReceived int64 = 0
+       var bytesReceived int64 = 0
 
 Review comment:
   we can use the following way:
   
   ```
   var (
         msgReceived int64 
         bytesReceived int64 
   )
   ```
   The default value of int64 is 0, we do not need to display the specified
   

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


With regards,
Apache Git Services

Reply via email to