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 2018/07/09 07:43:30 UTC

[GitHub] k2la opened a new pull request #2117: Fix Output In Pulsar Go Client Documentation

k2la opened a new pull request #2117: Fix Output In Pulsar Go Client Documentation
URL: https://github.com/apache/incubator-pulsar/pull/2117
 
 
   ### Motivation
   
   In http://pulsar.incubator.apache.org/docs/latest/clients/go/#Produceroperations ,
   
   ```
   producer.SendAsync(ctx, asyncMsg, func(msg pulsar.ProducerMessage, err error) {
   	if err != nil {
   		log.Fatal(err)
   	}
   
   	fmt.Printf("Message %s succesfully published\n", msg.ID())
   })
   ```
   
   cannot be compiled because `msg` doesn't have ID method.
   
   ```
   $ go build producer.go
   # command-line-arguments
   ./producer.go:54:56: msg.ID undefined (type pulsar.ProducerMessage has no field or method ID)
   ```
   
   ### Modifications
   
   I changed `msg.ID()` to `msg.Payload`.
   
   ```
   producer.SendAsync(ctx, asyncMsg, func(msg pulsar.ProducerMessage, err error) {
   	if err != nil {
   		log.Fatal(err)
   	}
   
   	fmt.Printf("Message %s succesfully published\n", msg.Payload)
   })
   ``` 
   
   ### Result
   
   This modified code can be compiled and executed successfully.
   
   ```
   $ go build producer.go
   $ ./producer
   2018/07/09 16:22:17 INFO  | ConnectionPool:63 | Created connection for pulsar://localhost:6650
   2018/07/09 16:22:17 INFO  | ClientConnection:279 | [[::1]:62559 -> [::1]:6650] Connected to broker
   2018/07/09 16:22:17 INFO  | HandlerBase:53 | [persistent://public/default/my-topic, ] Getting connection from pool
   2018/07/09 16:22:17 INFO  | ConnectionPool:63 | Created connection for pulsar://ac47a8d4f588:6650
   2018/07/09 16:22:17 INFO  | ClientConnection:281 | [[::1]:62560 -> [::1]:6650] Connected to broker through proxy. Logical broker: pulsar://ac47a8d4f588:6650
   2018/07/09 16:22:17 INFO  | ProducerImpl:154 | [persistent://public/default/my-topic, ] Created producer on broker [[::1]:62560 -> [::1]:6650]
   Message async-message-0 successfully published
   Message async-message-1 successfully published
   Message async-message-2 successfully published
   Message async-message-3 successfully published
   Message async-message-4 successfully published
   Message async-message-5 successfully published
   Message async-message-6 successfully published
   Message async-message-7 successfully published
   Message async-message-8 successfully published
   ```
   

----------------------------------------------------------------
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:
users@infra.apache.org


With regards,
Apache Git Services