How to share a configuration across multiple bundles in AEM6.4 | Community
Skip to main content
Level 2
Feb 1, 2020 4:13 PM UTC
Solved

How to share a configuration across multiple bundles in AEM6.4

Hello,

 

I have multiples OSGi bundles that use the same configuration properties.  Now I create a below service for each bundle:

@ObjectClassDefinition(name = "My configuration service", description = "Configuration for bundle")
public @interface MyConfig {
           @AttributeDefinition(name = "My API:", description = "API endpoint for project", type = AttributeType.STRING)
           String myPropAPI() default "....";
...
}
@580286
protected void activate(final MyConfig config) {
         this.api_endpoint = this.config.myPropAPI();
}

 

Is it possible for other bundles to share this configuration service? Or  should I create a property file accessed directly by all bundles?  

 

Thanks for any input

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
user05162Accepted solution
Employee
Feb 3, 2020 1:50 PM UTC

You can try to create a factory configuration.

 

OSGi provides a way to configure services and modify those configurations on the run-time. But apart from this there is a another powerful feature that OSGi provides that is : ability to create Factory Configurations. Factory Configurations is a way to create a single service, and bind multiple configurations to it  & then consume those configurations from different classes/Services. 

 

Check [1] for more details.

 

[1] https://www.tothenew.com/blog/creating-osgi-factory-configurations-in-aem/#

https://helpx.adobe.com/experience-manager/6-3/sites/deploying/using/configuring-osgi.html

4 replies

joerghoh
Employee
Feb 3, 2020 10:47 PM UTC

In case you have multiple services which share the same configuration (for whatever reason), I don't think that service factories are the right solution. Because service factories solve the issue of the same service with multiple configurations. Your problem seems to be the other way 'round.

 

In your case you should create a proper abstraction (e.g. "Endpoint Connection"), which can be configured centrally. All the other services use this "Endpoint Connection" service and do something like "myEndPointConnection.executeCommand(myCommand)", just to give an example.

Translate
Jam2021Author
Level 2
Feb 4, 2020 1:56 PM UTC
Yes, you are right. I did realize this problem after digging into configuration factory.
Translate
user05162Accepted solution
Employee
Feb 3, 2020 1:50 PM UTC

You can try to create a factory configuration.

 

OSGi provides a way to configure services and modify those configurations on the run-time. But apart from this there is a another powerful feature that OSGi provides that is : ability to create Factory Configurations. Factory Configurations is a way to create a single service, and bind multiple configurations to it  & then consume those configurations from different classes/Services. 

 

Check [1] for more details.

 

[1] https://www.tothenew.com/blog/creating-osgi-factory-configurations-in-aem/#

https://helpx.adobe.com/experience-manager/6-3/sites/deploying/using/configuring-osgi.html

Translate
Jam2021Author
Level 2
Feb 3, 2020 2:46 PM UTC
Thank you, Jbrar. I think this is what I need.
Translate