Hi All,
I want to know difference between Sling Component and Service.What are the use cases to be considered to use and implement these two features.
Please help me in understanding both of these.
Thanks,
Kishore
Solved! Go to Solution.
Views
Replies
Total Likes
Hi
I have found a very good article, covering everything with example:
Link:- http://www.computepatterns.com/76/osgi-component-vs-service-in-aem/
AEM ships with an OSGi container Apache felix that implements Declarative Services (DS) component model. Most of the developers who are new to AEM often gets confused between OSGi components and services.
OSGi Component
If you want the life of your object to be managed by the OSGi container, you should declare it as a component. Using DS annotations, you could make a POJO a OSGi component by annotating it with@Component With this, you will get the ability to start, stop and configure the component using the felix web console.
OSGi Service
OSGi components can be made as OSGi service by marking it with @service annotation. All it mandates is that an interface Services should implement an interface (1 or more). When you mark a component as service, you could refer (call) this service from other osgi components.
OSGi Component Vs Service
Go through the examples....
and in the last,
OSGi Component Use cases
Now, you must be wondering, why you shouldnt be marking every component as service. Yes, you want your objects to be usable outside its body. However, in certain use-cases modeling your object as component (not marking it as service) makes sense. Here are few of them.
I hope this would be of some help.
Thanks and Regards
Kautuk Sahni
This is explained in this doc:
http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html
Hope this helps.
Views
Replies
Total Likes
Hi Kishore,
In addition with that link given by scott, look into this thread which answers your question.
Also, there are so many number of articles which creates custom OSGI bundle(contains components and services) in this link: https://helpx.adobe.com/marketing-cloud/experience-manager.html
Thanks,
Ratna Kumar.
Views
Replies
Total Likes
Hi
I have found a very good article, covering everything with example:
Link:- http://www.computepatterns.com/76/osgi-component-vs-service-in-aem/
AEM ships with an OSGi container Apache felix that implements Declarative Services (DS) component model. Most of the developers who are new to AEM often gets confused between OSGi components and services.
OSGi Component
If you want the life of your object to be managed by the OSGi container, you should declare it as a component. Using DS annotations, you could make a POJO a OSGi component by annotating it with@Component With this, you will get the ability to start, stop and configure the component using the felix web console.
OSGi Service
OSGi components can be made as OSGi service by marking it with @service annotation. All it mandates is that an interface Services should implement an interface (1 or more). When you mark a component as service, you could refer (call) this service from other osgi components.
OSGi Component Vs Service
Go through the examples....
and in the last,
OSGi Component Use cases
Now, you must be wondering, why you shouldnt be marking every component as service. Yes, you want your objects to be usable outside its body. However, in certain use-cases modeling your object as component (not marking it as service) makes sense. Here are few of them.
I hope this would be of some help.
Thanks and Regards
Kautuk Sahni
Views
Likes
Replies