syklevin opened a new issue #340:
URL: https://github.com/apache/pulsar-client-go/issues/340


   #### Expected behavior
   
   According to the docs of KeyShared type: `multiple consumer will be able to 
use the same subscription and all messages with the same key will be dispatched 
to only one consumer`
   
   #### Actual behavior
   
   Both consumers got all messages, with different message key
   
   Tell us what happens instead
   
   #### Steps to reproduce
   
   ```go
   
   func TestPulsarPubsubWithSharedKey(t *testing.T) {
        cli, err := pulsar.NewClient(pulsar.ClientOptions{
                URL: "pulsar://localhost:6650",
        })
        if err != nil {
                t.Fatal(err)
        }
   
        topic := "topic-1"
   
        psr, err := cli.CreateProducer(pulsar.ProducerOptions{
                Topic: topic,
        })
        if err != nil {
                t.Fatal(err)
        }
   
        csr1, err := cli.Subscribe(pulsar.ConsumerOptions{
                Topic:            topic,
                SubscriptionName: "test-sub-1",
                Type:             pulsar.KeyShared,
        })
        if err != nil {
                t.Fatal(err)
        }
   
        csr2, err := cli.Subscribe(pulsar.ConsumerOptions{
                Topic:            topic,
                SubscriptionName: "test-sub-2",
                Type:             pulsar.KeyShared,
        })
        if err != nil {
                t.Fatal(err)
        }
   
        go func() {
                for {
                        select {
                        case cm := <-csr1.Chan():
                                fmt.Println("csr1 received", 
string(cm.Payload()))
                                cm.Ack(cm.Message)
                        case cm := <-csr2.Chan():
                                fmt.Println("csr2 received", 
string(cm.Payload()))
                                cm.Ack(cm.Message)
                        }
                }
        }()
   
        testPayload := []byte(`{"test": "1234565"}`)
        testPayload2 := []byte(`{"test": "246810"}`)
   
        ctx := context.Background()
   
        _, err = psr.Send(ctx, &pulsar.ProducerMessage{
                Key:     "test-msg-1",
                Payload: testPayload,
        })
        if err != nil {
                t.Fatal(err)
        }
   
        _, err = psr.Send(ctx, &pulsar.ProducerMessage{
                Key:     "test-msg-2",
                Payload: testPayload2,
        })
        if err != nil {
                t.Fatal(err)
        }
   
        time.Sleep(2 * time.Second)
   
   }
   
   ```
   
   How can we reproduce the issue
   
   the output log shows
   
   ```sh
   
   csr2 received {"test": "1234565"}
   csr1 received {"test": "1234565"}
   csr2 received {"test": "246810"}
   csr1 received {"test": "246810"}
   
   ```
   
   #### System configuration
   **Pulsar version**: 2.6.0 docker standalone
   


----------------------------------------------------------------
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.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to