commit | c24191b37a98d8731b34fb9fd44c151a2ef3a99e | [log] [tgz] |
---|---|---|
author | Miloš Matijašević <milosmatijasevic2015@gmail.com> | Tue Jan 26 04:04:52 2021 +0100 |
committer | GitHub <noreply@github.com> | Tue Jan 26 11:04:52 2021 +0800 |
tree | 6bfd78aa669fafd0ebcb9c50adce529ec8c73ac3 | |
parent | a1dca8c4e31eb6522bc40e2de4882be74266a657 [diff] |
Clearing message queues after seek requests (#419) ### Motivation Message queues should be cleared after seek requests (`Seek` and `SeekByTime`). If this is not performed messages that stay in message queues will be consumed before the sough message. ### Modifications Cleaning `queueCh` and `messageCh` after successful seek request in partition_consumer.go. ### Verifying this change - [x] Make sure that the change passes the CI checks. This change is already covered by existing tests, such as `TestConsumerSeekByTime` and `TestConsumerSeek`. This change added tests and can be verified as follows: - Extended `TestConsumerSeekByTime` and `TestConsumerSeek` test for consuming correctly sought message even if some messages stay in message queues. Signed-off-by: milos-matijasevic <milosmatijasevic2015@gmail.com>
A Go client library for the Apache Pulsar project.
This projects is developing a pure-Go client library for Pulsar that does not depend on the C++ Pulsar library.
Once feature parity and stability are reached, this will supersede the current CGo based library.
Check the Projects page at https://github.com/apache/pulsar-client-go/projects for tracking the status and the progress.
Import the client library:
import "github.com/apache/pulsar-client-go/pulsar"
Create a Producer:
client, err := pulsar.NewClient(pulsar.ClientOptions{
URL: "pulsar://localhost:6650",
})
defer client.Close()
producer, err := client.CreateProducer(pulsar.ProducerOptions{
Topic: "my-topic",
})
_, err = producer.Send(context.Background(), &pulsar.ProducerMessage{
Payload: []byte("hello"),
})
defer producer.Close()
if err != nil {
fmt.Println("Failed to publish message", err)
}
fmt.Println("Published message")
Create a Consumer:
client, err := pulsar.NewClient(pulsar.ClientOptions{
URL: "pulsar://localhost:6650",
})
defer client.Close()
consumer, err := client.Subscribe(pulsar.ConsumerOptions{
Topic: "my-topic",
SubscriptionName: "my-sub",
Type: pulsar.Shared,
})
defer consumer.Close()
msg, err := consumer.Receive(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Received message msgId: %#v -- content: '%s'\n",
msg.ID(), string(msg.Payload()))
Create a Reader:
client, err := pulsar.NewClient(pulsar.ClientOptions{URL: "pulsar://localhost:6650"})
if err != nil {
log.Fatal(err)
}
defer client.Close()
reader, err := client.CreateReader(pulsar.ReaderOptions{
Topic: "topic-1",
StartMessageID: pulsar.EarliestMessageID(),
})
if err != nil {
log.Fatal(err)
}
defer reader.Close()
for reader.HasNext() {
msg, err := reader.Next(context.Background())
if err != nil {
log.Fatal(err)
}
fmt.Printf("Received message msgId: %#v -- content: '%s'\n",
msg.ID(), string(msg.Payload()))
}
Contributions are welcomed and greatly appreciated. See CONTRIBUTING.md for details on submitting patches and the contribution workflow.
Name | Scope | |||
---|---|---|---|---|
users@pulsar.apache.org | User-related discussions | Subscribe | Unsubscribe | Archives |
dev@pulsar.apache.org | Development-related discussions | Subscribe | Unsubscribe | Archives |
Pulsar slack channel #dev-go
at https://apache-pulsar.slack.com/
You can self-register at https://apache-pulsar.herokuapp.com/
Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0