Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to read BOOLEAN value from pulsar message #1103

Open
Sonalit23 opened this issue Oct 12, 2023 · 2 comments · May be fixed by #1108
Open

Unable to read BOOLEAN value from pulsar message #1103

Sonalit23 opened this issue Oct 12, 2023 · 2 comments · May be fixed by #1108

Comments

@Sonalit23
Copy link

Sonalit23 commented Oct 12, 2023

Expected behavior

Sending pulsar message with value type Boolean (wrapper class) in java with RSA encryption enabled but unable to read it at consumer side with go client. correct boolean value should be received provided correct decryption keys.

Actual behavior

value is always empty and not sure what will be the right schema type for boolean value.

Steps to reproduce

Here I am writing producer in go (integration test) instead of JAVA.
producer code:

keyReader := crypto.NewFileKeyReader('PROVIDE PATH TO PUBLIC KEY', 'PROVIDE PATH TO PRIVATE KEY')
	producer, _ := client.CreateProducer(pulsar.ProducerOptions{
		Topic: "some-topic",
		Encryption: &pulsar.ProducerEncryptionInfo{
			KeyReader:                   keyReader,
			ProducerCryptoFailureAction: crypto.ProducerCryptoFailureActionFail,
			Keys:                        []string{"client-rsa.pem"},
		},
	})

	msgId, err := producer.Send(ctx, &pulsar.ProducerMessage{
		Key:   "abc-key",
		Value: true,
	})

Consumer code:

keyReader := crypto.NewFileKeyReader('PROVIDE PATH TO PUBLIC KEY', 'PROVIDE PATH TO PRIVATE KEY')
	options := pulsar.ConsumerOptions{
		Topic:            topic-name,
		Type:             pulsar.Shared,
		MessageChannel:              channel,
		SubscriptionInitialPosition: pulsar.SubscriptionPositionEarliest,
		Decryption: &pulsar.MessageDecryptionInfo{
			KeyReader:                   keyReader,
			ConsumerCryptoFailureAction: crypto.ConsumerCryptoFailureActionFail,
		},
	}

How to use schematype for BOOLEAN value? I checked the https://github.com/apache/pulsar-client-go/blob/master/pulsar/schema.go but it is unclear for boolean value. any help would be appreciated.

Workaround/solution: Currently I am reading payload directly, checking if it is not nil and then converting it to bool.

payload := msg.Payload()
if payload != nil {
value := payload[0] != 0
}

System configuration

Pulsar version: 3.0.x

@dao-jun
Copy link
Member

dao-jun commented Oct 21, 2023

  1. Pulsar-client-go not supports BOOLEAN schema yet

  2. You didn't set a Schema for the producer and use the Value field, the Value field needs a Schema to encode it into Payload([]byte). If the Schema not set, the message you sent will has an empty body. So you can't read the message payload when you consuming messages.
    In this condition, you can

producer.send(ctx, &ProducerMessage{
		Key:   "abc-key",
		Payload: ture ? []byte{1} : []byte{0},
})

@dao-jun dao-jun linked a pull request Oct 21, 2023 that will close this issue
1 task
@dao-jun
Copy link
Member

dao-jun commented Oct 21, 2023

I created a PR to introduce BooleanSchema: #1108

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants