labuladong commented on code in PR #17455:
URL: https://github.com/apache/pulsar/pull/17455#discussion_r963237255
##########
site2/docs/client-libraries-go.md:
##########
@@ -442,85 +433,114 @@ if err := consumer.Unsubscribe(); err != nil {
### Consumer operations
-Pulsar Go consumers have the following methods available:
+Pulsar
[`Consumer`](https://pkg.go.dev/github.com/apache/pulsar-client-go/pulsar#Consumer)
interface have the following methods available:
+
+| Method | Description
|
Return type |
+|:---------------------------------------------------|:-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-------------------------|
+| `Subscription()` | Returns the consumer's
subscription name
|
`string` |
+| `Unsubcribe()` | Unsubscribes the
consumer from the assigned topic. Throws an error if the unsubscribe operation
is somehow unsuccessful.
| `error` |
+| `Receive(context.Context)` | Receives a single
message from the topic. This method blocks until a message is available.
| `(Message, error)` |
+| `Chan()` | Chan returns a channel
from which to consume messages.
|
`<-chan ConsumerMessage` |
+| `Ack(Message)` |
[Acknowledges](reference-terminology.md#acknowledgment-ack) a message to the
Pulsar [broker](reference-terminology.md#broker)
| `error` |
+| `AckID(MessageID)` |
[Acknowledges](reference-terminology.md#acknowledgment-ack) a message to the
Pulsar [broker](reference-terminology.md#broker) by message ID
| `error` |
+| `ReconsumeLater(msg Message, delay time.Duration)` | ReconsumeLater mark a
message for redelivery after custom delay.
| None |
+| `Nack(Message)` | Acknowledge the failure
to process a single message (not blocking).
|
None |
+| `NackID(MessageID)` | Acknowledge the failure
to process a single message (not blocking).
|
None |
+| `Seek(MessageID)` | Reset the subscription
associated with this consumer to a specific message id. The message id can
either be a specific message or represent the first or last messages in the
topic. | `error` |
+| `SeekByTime(time.Time)` | Reset the subscription
associated with this consumer to a specific message publish time.
|
`error` |
+| `Close()` | Closes the consumer,
disabling its ability to receive messages from the broker
| None |
+| `Name()` | Name returns the name
of consumer
| `string` |
+
+#### Create single-topic consumer
-Method | Description | Return type
-:------|:------------|:-----------
-`Subscription()` | Returns the consumer's subscription name | `string`
-`Unsubcribe()` | Unsubscribes the consumer from the assigned topic. Throws an
error if the unsubscribe operation is somehow unsuccessful. | `error`
-`Receive(context.Context)` | Receives a single message from the topic. This
method blocks until a message is available. | `(Message, error)`
-`Chan()` | Chan returns a channel from which to consume messages. | `<-chan
ConsumerMessage`
-`Ack(Message)` | [Acknowledges](reference-terminology.md#acknowledgment-ack) a
message to the Pulsar [broker](reference-terminology.md#broker) |
-`AckID(MessageID)` |
[Acknowledges](reference-terminology.md#acknowledgment-ack) a message to the
Pulsar [broker](reference-terminology.md#broker) by message ID |
-`ReconsumeLater(msg Message, delay time.Duration)` | ReconsumeLater mark a
message for redelivery after custom delay |
-`Nack(Message)` | Acknowledge the failure to process a single message. |
-`NackID(MessageID)` | Acknowledge the failure to process a single message. |
-`Seek(msgID MessageID)` | Reset the subscription associated with this consumer
to a specific message id. The message id can either be a specific message or
represent the first or last messages in the topic. | `error`
-`SeekByTime(time time.Time)` | Reset the subscription associated with this
consumer to a specific message publish time. | `error`
-`Close()` | Closes the consumer, disabling its ability to receive messages
from the broker |
-`Name()` | Name returns the name of consumer | `string`
+```go
+client, err := pulsar.NewClient(pulsar.ClientOptions{URL:
"pulsar://localhost:6650"})
+if err != nil {
+ log.Fatal(err)
+}
+
+defer client.Close()
-### Receive example
+consumer, err := client.Subscribe(pulsar.ConsumerOptions{
+ // fill `Topic` field will create a single-topic consumer
+ Topic: "topic-1",
+ SubscriptionName: "my-sub",
+ Type: pulsar.Shared,
+})
+if err != nil {
+ log.Fatal(err)
+}
+defer consumer.Close()
+```
-#### How to use regex consumer
+#### Create specific-partition consumer
```go
-client, err := pulsar.NewClient(pulsar.ClientOptions{
- URL: "pulsar://localhost:6650",
-})
+client, err := pulsar.NewClient(pulsar.ClientOptions{URL:
"pulsar://localhost:6650"})
+if err != nil {
+ log.Fatal(err)
+}
defer client.Close()
-p, err := client.CreateProducer(pulsar.ProducerOptions{
- Topic: topicInRegex,
- DisableBatching: true,
+// subscribe a specific partition of a topic
+consumer, err := client.Subscribe(pulsar.ConsumerOptions{
+ // pulsar partition is a special topic has the suffix '-partition-xx'
+ Topic: "my-partitioned-topic-partition-2",
+ SubscriptionName: "my-sub",
+ Type: pulsar.Shared,
})
Review Comment:
You are right, I'll remove this example. See
[1aeac82](https://github.com/apache/pulsar/pull/17455/commits/1aeac82a64cf0b1fb04a07ec82511cc4800d376c).
--
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.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]