[Issue 304][Reader] fixed panic in CreateReader API using custom MessageID for ReaderOptions #305
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #304
Motivation
User of the client's client's CreateReader API can use a custom type satisfying the MessageID interface, when using it as a value for
StartMessageID
in ReaderOptions argument for the mentioned API.The current reader creation does an untested type assertion here, when preparing the
consumerOptions
needed for creating apartitionConsumer
.https://github.com/apache/pulsar-client-go/blob/master/pulsar/reader_impl.go#L64
This assertion of
MessageID
as*messageID
will fail unless an instance ofMessageID
is created from one of these exported APIs becausemessageID
is unexportedhttps://github.com/apache/pulsar-client-go/blob/master/pulsar/message.go#L114-#L126
Note:
newMessageID
returns*messageID
which satisfiesMessageID
interface as well.Modifications
Test the type assertion of
MessageID
as*messageID
, if it fails, re-create a newMessageID
using thispulsar-client-go/pulsar/impl_message.go
Line 97 in 975eb37
This will ensure that the custom type can be re-created as a
*messageID
which can be used bypartitionConsumerOpts
Verifying this change
This change added tests and can be verified as follows:
Added unit test
TestReaderOnSpecificMessageWithCustomMessageID
ingithub.com/apache/pulsar-client-go/pulsar
package.Test uses a custom StartMessageID in ReaderOptions while creating a new reader to read from a specific message ID, rather than the pre-canned earliest/latest options.
CI script test result snippet below.
Does this pull request potentially affect one of the following parts:
Documentation