1 of 25

Best practices für Services und Integration in OSGi

2 of 25

Speaker

Christian Schneider

Open Source Architect bei Talend

Committer bei

  • Apache Karaf
  • Apache CXF
  • Apache Camel

  • OPS4j pax url, pax exam

Blog:

http://www.liquid-reality.de

3 of 25

Ziele

Was möchte ich vermitteln?

  • OSGi ist einfacher als man denkt
  • Beispielapplikation als Startpunkt für eigene Versuche

4 of 25

Beispiel Voting

Idee

  • Live Voting zu einem Thema mit grafischer Auswertung der Ergebnisse

  • Votes können per Twitter oder UI und Rest Service abgegeben werden

5 of 25

Beispiel Voting - Architektur

model

Vote, Voting,�VoteService

service

VoteService impl

Rest Service

UI

jQuery

Twitter Adapter

Camel Route, Twitter Component

OSGi Service

module dependency

service dependency

Front End

Service

Model

6 of 25

OSGi Features

  • Bundle Classloader (explicit Imports / Exports)
  • Bundle Lifecycle
  • Service Registry
  • Configuration �Admin Service

7 of 25

Apache

Container ?

Framework ?

Extras ?

8 of 25

Apache

OSGI Framework (Felix / Equinox)

HTTP

JAAS

Spring

Console

Logging

Deployer

Instance

Blueprint

Core

WAR

Standard

Enterprise

OBR

JPA

JTA

Cellar

KAR

CXF

Camel

ActiveMQ

JClouds

OpenEJB

Webconsole

Management

Extern

9 of 25

OSGi Best Practices

Karaf

OSGi Applikation

Config

Services

Blueprint

Bundle creation

10 of 25

Bundles erzeugen mit maven

maven-bundle-plugin

bnd

jar Datei mit OSGi Manifest

11 of 25

Dynamic Wiring

OSGi ist dynamisch

Bundles, Services, Config

Ist das nicht kompliziert?

12 of 25

Dynamic Wiring

Ja .. wenn man dagegen arbeitet

  • Startlevel tuning
  • Services von Hand einbinden
  • Konfiguration von Hand im Code aktualisieren

13 of 25

Dependency Injection

Aries Blueprint oder Declarative Services�(Dependency injection für OSGi)

deklaratives dynamisches wiring

14 of 25

OSGi Services

S

A

register

B

get listen

Java Object

Java Interface + Properties +

priority

Bundle

Service

Bundle

15 of 25

OSGi Services in Blueprint

Provider

Consumer

mandatory: Blueprint Kontext startet nur wenn der service verfügbar ist

<bean id="voteService" class="net.lr.tutorial.karaf.vote.service.MemoryVoteService" />�<service ref="voteService" interface="net.lr.tutorial.karaf.vote.model.VoteService" />

<reference id="voteService" interface="net.lr.tutorial.karaf.vote.model.VoteService"/>

16 of 25

ConfigAdmin Service

pid=net.lr.myconfig

key1=value1

key2=value2

Configuration

update(Properties)

Service Registry

register

update()

triggert

ManagedService

Configuration getConfiguration(String pid)

Configuration[] listConfigurations(String filter)

ConfigurationAdmin

17 of 25

ConfigAdmin Service

in Blueprint

<cm:property-placeholder persistent-id="ConfigApp" update-strategy="reload">

<cm:default-properties>

<cm:property name="title" value="Default Title"/>

</cm:default-properties>

</cm:property-placeholder>

<bean id="myApp" class="net.lr...MyApp" init-method="refresh">

<property name="title" value="${title}"></property>

</bean>

Kontext Neustart bei Änderung in der Konfiguration

Konfigurationswerte sind als Variablen verfügbar

18 of 25

ConfigAdmin Servicein Apache Karaf

Felix�Fileinstall

etc

change

pid.cfg

ConfigAdmin

Update

polls

Property-Dateien

dynamische updates

Managed Service

Create /

Update

19 of 25

Deployment

Feature

Feature repo

Bundle

1..*

1..*

features:addurl mvn:net.lr.tasklist/tasklist-features/1.0.0-SNAPSHOT/xml

features:install example-tasklist

20 of 25

DEMO

21 of 25

CXF und Blueprint

<bean id="voteService" class="net.lr.tutorial.karaf.vote.service.MemoryVoteService" />

<jaxrs:server address="/vote" id="voting-jaxrs-server">

<jaxrs:serviceBeans>

<ref component-id="voteService" />

</jaxrs:serviceBeans>

</jaxrs:server>

<jaxws:endpoint implementor="#voteService" address="/votesoap"/>

22 of 25

Advanced Topics

  • CDI on OSGi (Weld-OSGi, Karaf EE, Glassfish)
  • DOSGi (CXF-DOSGi)
  • Aries JPA and JTA

23 of 25

Fragen?

24 of 25

Links

25 of 25

Konzept Verteilter ESB

Container 1

Container N

Service

Integration

Web Applikation

...

Security

Service Locator

Messaging Broker

Logging Server

Eigene Module

ESB Infrastruktur

Registry

Querschnitt

Management