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 2021/11/18 09:18:48 UTC

[GitHub] [pulsar] storm-5 edited a comment on issue #12832: go client: message ID serialization / deserialization, then AckID failed

storm-5 edited a comment on issue #12832:
URL: https://github.com/apache/pulsar/issues/12832#issuecomment-972675070


   > could you provide the go code to test this issue?
   
   here is. I have wipe the sensitive info.
   
   ```go
   
   package main
   
   import (
   	"context"
   	"fmt"
   	"time"
   
   	"github.com/apache/pulsar-client-go/pulsar"
   )
   
   func main() {
   	url := ""
   	token := ""
   	topic := ""
   	subscName := ""
   
   	client, _ := pulsar.NewClient(pulsar.ClientOptions{
   		URL:               url,
   		Authentication:    pulsar.NewAuthenticationToken(token),
   		OperationTimeout:  30 * time.Second,
   		ConnectionTimeout: 30 * time.Second,
   	})
   
   	consumer, err := client.Subscribe(pulsar.ConsumerOptions{
   		Topic:            topic,
   		SubscriptionName: subscName,
   		Type:             pulsar.Shared,
   		RetryEnable:      true,
   		DLQ: &pulsar.DLQPolicy{
   			MaxDeliveries:    1,
   			RetryLetterTopic: topic + "-RETRY",
   			DeadLetterTopic:  topic + "-DLQ",
   		},
   	})
   	fmt.Printf("%s", err)
   
   	producer, _ := client.CreateProducer(pulsar.ProducerOptions{
   		Topic: topic,
   	})
   	snmid, _ := producer.Send(context.Background(), &pulsar.ProducerMessage{
   		Payload: []byte("hello"),
   	})
   	fmt.Printf("%x", snmid.Serialize())
   
   	ctx, cancel := context.WithTimeout(context.Background(), 10000*time.Millisecond)
   	defer cancel()
   	for {
   		msg, _ := consumer.Receive(ctx)
   		midOri := msg.ID()
   		midBytes := midOri.Serialize()
   		midNew, _ := pulsar.DeserializeMessageID(midBytes)
   		consumer.AckID(midNew)
   		// consumer.AckID(midOri)
   		// consumer.Ack(msg)
   		fmt.Printf("%s, ", msg.Payload())
   	}
   }
   ```


-- 
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: commits-unsubscribe@pulsar.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org