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 2020/08/03 09:06:05 UTC

[GitHub] [pulsar-client-go] syklevin opened a new issue #340: Multi Subscriptions with KeyShared type, received both messages, not to only one consumer

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



[GitHub] [pulsar-client-go] syklevin commented on issue #340: Multi Subscriptions with KeyShared type, received both messages, not to only one consumer

Posted by GitBox <gi...@apache.org>.
syklevin commented on issue #340:
URL: https://github.com/apache/pulsar-client-go/issues/340#issuecomment-668357511


   Just tested and it work as expected. Thanks for pointing out this magic part. It would be great if we could have more examples for different cases.


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



[GitHub] [pulsar-client-go] wolfstudy closed issue #340: Multi Subscriptions with KeyShared type, received both messages, not to only one consumer

Posted by GitBox <gi...@apache.org>.
wolfstudy closed issue #340:
URL: https://github.com/apache/pulsar-client-go/issues/340


   


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



[GitHub] [pulsar-client-go] syklevin commented on issue #340: Multi Subscriptions with KeyShared type, received both messages, not to only one consumer

Posted by GitBox <gi...@apache.org>.
syklevin commented on issue #340:
URL: https://github.com/apache/pulsar-client-go/issues/340#issuecomment-668386091


   @sijie BTW, how could we achieve Key_Shared with sticky hash range like java client?


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



[GitHub] [pulsar-client-go] sijie commented on issue #340: Multi Subscriptions with KeyShared type, received both messages, not to only one consumer

Posted by GitBox <gi...@apache.org>.
sijie commented on issue #340:
URL: https://github.com/apache/pulsar-client-go/issues/340#issuecomment-668406877


   @syklevin I don't think go client supports sticky hash range yet. Feel free to create a github issue for this feature. We can follow up on it. 


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



[GitHub] [pulsar-client-go] sijie commented on issue #340: Multi Subscriptions with KeyShared type, received both messages, not to only one consumer

Posted by GitBox <gi...@apache.org>.
sijie commented on issue #340:
URL: https://github.com/apache/pulsar-client-go/issues/340#issuecomment-668329458


   @syklevin It seems like that you are using two different subscription names. Each subscription will receive a full copy of the messages. You need to use one same subscription name for your test.


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



[GitHub] [pulsar-client-go] wolfstudy commented on issue #340: Multi Subscriptions with KeyShared type, received both messages, not to only one consumer

Posted by GitBox <gi...@apache.org>.
wolfstudy commented on issue #340:
URL: https://github.com/apache/pulsar-client-go/issues/340#issuecomment-668615781


   Close this issue, and https://github.com/apache/pulsar-client-go/issues/342 will track this task. Thanks @srkukarni feedback.


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