简体   繁体   中英

OSGI service versioning practices?

I'm familiar with OSGI Semantic Versioning - technical whitepaper. However, I don't see any versioning concept proposed for OSGI services.

Simple situation: I'm providing service registerd as com.services.payments.PaymentService, which impelemnts method void makePayment(Integer amount, String accountNo), I'm packing as a bundle version 1.0. Then, I update service with modified interface. I remove this method and add new method: makePaymentInDifferentWay (Integer amount, String accountNo) and package new service as a bundle version 2.0. after first bundle is stopped, client will have second service wired, and CRASH on service invocation, because method signature is not binary compatible. Such situations are perfectly solved while you deal with java packages, however I do not see any versioning capabilities out of the box with OSGI services. Am I missing something? (I know I could design versioning scheme upfront by setting service property like 'service.version' and filter provided services by this property on client side, or simply rename a API package or class name, but why no versioning is provided of the box? Maybe there is some other more stadard way solution? Maybe there is some concept related to services that I simply didn't grasp?)

The client should have versions on its Import-Package statements (or Require-Bundle) statements, like:

Import-Package: com.services.payments;version="[1.0,2.0)"

And the service will export package as:

Export-Package:  com.services.payments;version="1.0.0"

After you stop the first bundle and install second one, the client will not be resolved resolve (since the required constraint, com.services.payments;version="[1.0,2.0)" will not be satisfied.

Furthermore, if you have two API packages, one with package versioned as "1.0.0" and second one with version "2.0.0", and client importing "1.0.0" API, the client will not "see" service implementing API version "2.0.0" at all.

Services are types and types are in packages. So the version of a service is the version of the package containing the service type. The OSGi framework makes sure only to expose services to clients when the client is using the same package for the service type as the provider of the service.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM