Create OSGI Configuration Listener

Create a OSGI Configuration Listener in AEM 6.1

 

Following article demonstrate business scenario where you need to execute a job, call a method or simply log when there in change in XYZ OSGI configuration. Taking forward the OSGI Configuration Management and Reading of OSGI Configuration, I will show you how you can create a OSGI Configuration listener. Before that’s take a look at below…

ConfigurationListener[Interface] objects are registered with the Framework service registry and are notified with a ConfigurationEvent object when an event is fired. ConfigurationListener objects can inspect the received ConfigurationEvent object to determine its type, the pid of the Configuration object with which it is associated, and the Configuration Admin service that fired the event.

I have used com.day.cq.wcm.notification.email.impl.EmailChannel service but you can use any service based on your requirements and will read property email.from when their is a change. Let’s get started..

1. Create a Service which Implement ConfigurationListener interface

2. Override ConfigurationEvent method and its implementation

3. Invoke a custom define method to read required property

4. Change the email.from property in service com.day.cq.wcm.notification.email.impl.EmailChannel

Change OSGI config

5. See the updated log file snippet

Updated Log File

6. Here is complete code you can use

Let me know if you need any help in Implementation

2 thoughts on “Create a OSGI Configuration Listener in AEM 6.1

Leave a Reply

Your email address will not be published. Required fields are marked *