Thursday 9 March 2017

Managing multiple instances of the same Adobe Experience Manager OSGi service

When developing custom services for Adobe Experience Manager, you can define a service that can be configured using the Felix Configuration screen.


You define configuration fields that show up in the Felix configuration screen by using a @Property annotations. For example: 

@Property(description="adress to whom email is sent",value=DEFAULT_ADDRESS)
    private static final String ADDRESS = "mailservice.address";
    private String address;

You can configure your AEM service to use different configuration values. For example, you can configure 1 to many different instances of the same service. 

Assume you want to develop a custom email service that contain the following configuration values. 
  • the email address to which an email is sent
  • the email address from which the email is sent
You can configure the custom email service so that each service instance has a different value for these configuration settings. You can enter an AEM configuration value into an AEM configuration dialog, as shown here. 


In this configuration dialog, the to and from email addresses are configurable. You can configure additional configuration settings for the same service.  

When you use the custom Service within AEM, you can create a reference to the exact configuration service that you want to reference. To do this, you use the @Reference annotation and additional metadata such as: 


 @Reference(target = "(mailservice.label=InternetA)")
     MailService mailServiceA; 
     
     @Reference(target = "(mailservice.label=InternetB)")
     MailService mailServiceB;      


In the above dialog, there is a additional field named emailservice.label. You can reference the value in this field with the target value when using the @Reference annotation. 

This development article guides you through how to create an OSGi service where there are multiple configured services and how to use the  @Reference(target = "(mailservice.label=InternetA)") annotation properly.  


Join the Experience League

To become an Experience Business, you need more than just great tools and online help. You need a partner. Experience League is a new enablement program with guided learning to help you get the most out of Adobe Experience Cloud. With training materials, one-to-one expert support, and a thriving community of fellow professionals, Experience League is a comprehensive program designed to help you become your best.

Join the Adobe Experience League by clicking this banner.




I (Scott Macdonald) am a Senior Experience League Community Manager at Adobe Systems with 20 years in the high tech industry. I am also a programmer with knowledge in Java, JavaScript, C#,C++, HTML, XML and ActionScript. If  you would like to see more AEM or other end to end articles like this, then leave a comment and let me know what content you would like to see.


Twitter: Follow the Digital Marketing Customer Care team on Twitter @AdobeExpCare.