spring-projects / spring-pulsar

Spring Friendly Abstractions for Apache Pulsar
Apache License 2.0
183 stars 58 forks source link

Non-shaded protobuf-java causing class mismatch issues #876

Closed onobc closed 2 weeks ago

onobc commented 1 month ago

The Pulsar client lib does not shade com.google.protobuf:protobuf-java and it is causing user's problems as described in original post by @nandorholozsnyak in https://github.com/spring-projects/spring-pulsar/issues/114#issuecomment-2399976242_

Workaround 1

Upgrade to Pulsar client 3.3.2 as he protobuf-java has been updated to 3.25.5.

If you plan on updating to the upcoming spring-pulsar 1.2.0-RC1release (Spring Boot 3.4.0-RC1 / week of Oct 18) you will get this update automatically. If you don't plan on updating Spring Pulsar then, you can override the version of Pulsar as described here.

This will bring the protobuf-java up to a recent version, solving the original author's issue, but will not fix future version mismatches.

Workaround 2

You can exclude protobuf-java from the current pulsar-client-alland provide the more recent dependency (example here. Something like:

api ("org.apache.pulsar:pulsar-client-all") {
    exclude group: 'com.google.protobuf:protobuf-java'
}
api "com.google.protobuf:protobuf-java:3.25.5"

Improvement 1

We already exclude some other unwanted dependencies from the Pulsar lib (here. We should likely exclude protobuf-java as well as we do include it explicitly already as optional dependency (here.

We will try to get the above improvement into the upcoming 1.2.0-RC1release as well.

Improvement 2

We should also see about shading the protobuf-java lib in the Pulsar client libs to avoid this downstream required massaging.

nandorholozsnyak commented 4 weeks ago

Hello @onobc Thank you for the issue here too, just a quick question for clarity: The Pulsar client lib does not shade com.google.protobuf:protobuf-java and it is causing user's problems as described in original post Indeed the pulsar-client lib is not shading it, but is it the real issue? If it would it may break others as well isnt it?

onobc commented 4 weeks ago

Hi @nandorholozsnyak

pulsar-client lib is not shading it, but is it the real issue? If it would it may break others as well isnt it? Indeed the pulsar-client lib is not shading it, but is it the real issue?

If one were to pull spring-pulsar out of the equation and consume the pulsar-client lib directly, they would transitively consume the older version of protobuf-java which could cause problems.

nandorholozsnyak commented 4 weeks ago

Hi @onobc Thank you so much for the info.

onobc commented 3 weeks ago

Looks like this may get fixed in Pulsar proper as well: https://github.com/apache/pulsar/pull/23468

nandorholozsnyak commented 3 weeks ago

Hehe, it is happening :D What a coincidence.