Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Issue 304][Reader] fixed panic in CreateReader API using custom Mess…
…ageID for ReaderOptions (apache#305) ### Motivation User of the client's client's [CreateReader](https://github.com/apache/pulsar-client-go/blob/master/pulsar/client.go#L109) API can use a custom type satisfying the [MessageID](https://github.com/apache/pulsar-client-go/blob/master/pulsar/message.go#L108) interface, when using it as a value for `StartMessageID` in [ReaderOptions](https://github.com/apache/pulsar-client-go/blob/master/pulsar/reader.go#L48) argument for the mentioned API. The current reader creation does an untested type assertion here, when preparing the `consumerOptions` needed for creating a `partitionConsumer`. 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 of `MessageID` is created from one of these exported APIs because `messageID` is unexported https://github.com/apache/pulsar-client-go/blob/master/pulsar/message.go#L114-#L126 Note: `newMessageID` returns `*messageID` which satisfies `MessageID` interface as well. ### Modifications Test the type assertion of `MessageID` as `*messageID`, if it fails, re-create a new `MessageID` using this https://github.com/apache/pulsar-client-go/blob/975eb3781644ebe588fc142e53eadf39fe50341a/pulsar/impl_message.go#L97 This will ensure that the custom type can be re-created as a `*messageID` which can be used by `partitionConsumerOpts`
- Loading branch information