Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
When Camel meets CDI  Łukasz Dywicki
Goals●   Determine state of DI support in Camel●   Possible extension points to use●   Transition from Spring to CDI●   Sh...
Who am I?●   Łukasz Dywicki    –   Independent software contractor●   ServiceMix user since 2008●   Commiter of Apache Kar...
Camel + Red Hat
Brief introduction – CDI, JSR-299
Brief introduction – CDI●   Built on top of JSR-330●   Package javax.inject    –   @Inject    –   @Named    –   @Qualifier...
Brief introduction – CDI cont.
Brief introduction – CDI cont.●   CDI contains more elements specific to full    featured DI container    –   Stereotypes ...
Brief introduction – CDI cont.●   Discovery of beans rely on presence of    beans.xml file in META-INF or WEB-INF●   Conta...
Support for Dependency Injection in Camel
Support for DI in Camel●   XML based    –   Spring    –   Blueprint●   Annotation based    –   Guice    –   Spring JavaCon...
Support for DI in Camel●   XML based    –   Spring    –   Blueprint●   Annotation based    –   Guice    –   Spring JavaCon...
Some pictures for fun
Back to Camel
Support for DI in Camel cont.●   Registry●   Injector
Registry
Core Registries●   CompositeRegistry●   SimpleRegistry●   JndiRegistry●   PropertyPlaceholderDelegateRegistry
rd3 Party Registries●   ApplicationContextRegistry●   BlueprintContainerRegistry●   OsgiServiceRegistry●   CdiBeanRegistry
Injector
Core Injectors●   ReflectionInjector●   DefaultInjector
rd3 party injectors●   SpringInjector●   GuiceInjector●   CdiInjector
Transition from Spring to CDI
Transition from Spring to CDI●   No ApplicationContext instance    –   How do I get bean from it?●   No pre/post processor...
How do I get bean●   Use Apache DeltaSpike BeanProvider class:    –   getContextualReference(String) = Object    –   getCo...
CamelContextAware
Events●   BeforeBeanDiscovery●   AfterBeanDisovery●   ProcessBean●   ProcessInjectionTarget●   ProcessObserverMethod●   Af...
Linking beans
Demo application
Common problems
Problems ...●   Domination of Spring style DI●   Multiple contexts vs simplicity of extension●   Magic done inside Camel● ...
TODO●   Support for discovering    –   Intercept Strategies    –   Event Notifiers    –   Executors    –   Resolvers●   Tr...
Any questions?
Thank you for coming!
Upcoming SlideShare
Loading in …5
×

When Camel meets CDI

3,017 views

Published on

Published in: Technology
  • Be the first to comment

When Camel meets CDI

  1. 1. When Camel meets CDI Łukasz Dywicki
  2. 2. Goals● Determine state of DI support in Camel● Possible extension points to use● Transition from Spring to CDI● Show running CDI + Camel application
  3. 3. Who am I?● Łukasz Dywicki – Independent software contractor● ServiceMix user since 2008● Commiter of Apache Karaf● Camel contributor
  4. 4. Camel + Red Hat
  5. 5. Brief introduction – CDI, JSR-299
  6. 6. Brief introduction – CDI● Built on top of JSR-330● Package javax.inject – @Inject – @Named – @Qualifier – @Scope – @Singleton – Provider<T>
  7. 7. Brief introduction – CDI cont.
  8. 8. Brief introduction – CDI cont.● CDI contains more elements specific to full featured DI container – Stereotypes – Application/Session/Request Scope – Bean Registry*● Possibility to implement own scopes● Its type safe by definition● Handles dependent beans creation● Lifecycle management with JSR-250
  9. 9. Brief introduction – CDI cont.● Discovery of beans rely on presence of beans.xml file in META-INF or WEB-INF● Container discovers beans automatically● CDI is extensible – Extension interface – META-INF/services entry
  10. 10. Support for Dependency Injection in Camel
  11. 11. Support for DI in Camel● XML based – Spring – Blueprint● Annotation based – Guice – Spring JavaConfig
  12. 12. Support for DI in Camel● XML based – Spring – Blueprint● Annotation based – Guice – Spring JavaConfig – CDI
  13. 13. Some pictures for fun
  14. 14. Back to Camel
  15. 15. Support for DI in Camel cont.● Registry● Injector
  16. 16. Registry
  17. 17. Core Registries● CompositeRegistry● SimpleRegistry● JndiRegistry● PropertyPlaceholderDelegateRegistry
  18. 18. rd3 Party Registries● ApplicationContextRegistry● BlueprintContainerRegistry● OsgiServiceRegistry● CdiBeanRegistry
  19. 19. Injector
  20. 20. Core Injectors● ReflectionInjector● DefaultInjector
  21. 21. rd3 party injectors● SpringInjector● GuiceInjector● CdiInjector
  22. 22. Transition from Spring to CDI
  23. 23. Transition from Spring to CDI● No ApplicationContext instance – How do I get bean from it?● No pre/post processors – CamelContextAware● Multiple camel contexts – Linking beans with camel contexts● No domain specific namespaces
  24. 24. How do I get bean● Use Apache DeltaSpike BeanProvider class: – getContextualReference(String) = Object – getContextualReference(Class<T>) = T – getBeanDefinition(Class<T>) = Set<Bean<T>> – getContextualReferences(Class<T>) = List<T>
  25. 25. CamelContextAware
  26. 26. Events● BeforeBeanDiscovery● AfterBeanDisovery● ProcessBean● ProcessInjectionTarget● ProcessObserverMethod● AfterDeploymentValidation● BeforeShutdown
  27. 27. Linking beans
  28. 28. Demo application
  29. 29. Common problems
  30. 30. Problems ...● Domination of Spring style DI● Multiple contexts vs simplicity of extension● Magic done inside Camel● Configuring Camel Context bean
  31. 31. TODO● Support for discovering – Intercept Strategies – Event Notifiers – Executors – Resolvers● Transactional services without spring-tx
  32. 32. Any questions?
  33. 33. Thank you for coming!

×