0% found this document useful (0 votes)
95 views80 pages

Apache ServiceMix 4.2.0

ServiceMix 4 consists of Overview and architecture Planning Overview and architecture Getting started Camel Normalized Message Router Java Business Integration Getting started Apache Software License Commercial support available OSGi-based support for JBI 1.

Uploaded by

nandakumarkn
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
95 views80 pages

Apache ServiceMix 4.2.0

ServiceMix 4 consists of Overview and architecture Planning Overview and architecture Getting started Camel Normalized Message Router Java Business Integration Getting started Apache Software License Commercial support available OSGi-based support for JBI 1.

Uploaded by

nandakumarkn
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 80

Apache ServiceMix

2010 anova r&d bvba

1/80

(c) 2010 anova r&d bvba

This work is licensed under the Creative Commons Attribution 2.0 Belgium License. To view a copy of this license, visit http://creativecommons.org/licenses/by/2.0/be/ or send a letter to Creative Commons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

2010 anova r&d bvba

Planning

Overview and architecture Getting started Camel Normalized Message Router Java Business Integration

2010 anova r&d bvba

3/80

Planning

Overview and architecture Getting started Camel Normalized Message Router Java Business Integration

2010 anova r&d bvba

4/80

Overview and architecture

ServiceMix 4

Open-source ESB

Apache Software License Commercial support available

OSGi-based Support for JBI 1.0

2010 anova r&d bvba

5/80

Overview and architecture

ServiceMix 4 consists of

Apache Felix Karaf Apache Camel Apache ActiveMQ NMR implementation JBI implementation

2010 anova r&d bvba

6/80

Overview and architecture

2010 anova r&d bvba

7/80

Planning

Overview and architecture Getting started Camel Normalized Message Router Java Business Integration

2010 anova r&d bvba

8/80

Getting started

Download Installation Running the container


interactive background as a service

2010 anova r&d bvba

9/80

Getting started

Download

from http://servicemix.apache.org two archive formats


.tar.gz for Linux, Unix, Solaris and MacOS .zip for Windows

2010 anova r&d bvba

10/80

Installation

Requirements

100 MB free disk space JDK 1.5 or higher unzip the archive to the local disk

Installation

2010 anova r&d bvba

11/80

Running the container

interactive

bin/servicemix starts ServiceMix access the command shell console

2010 anova r&d bvba

12/80

Running the container

in the background

bin/start script starts ServiceMix bin/stop scripts stops ServiceMix access the console

using ssh using the webconsole (when installed)

2010 anova r&d bvba

13/80

Running the container

as a service

uses Tanuki Java Software Wrapper start ServiceMix interactively in the console

features:install wrapper wrapper:install

follow instructions to complete installation

2010 anova r&d bvba

14/80

Running the container

2010 anova r&d bvba

15/80

Planning

Overview and architecture Getting started Camel Normalized Message Router Java Business Integration

2010 anova r&d bvba

16/80

Camel

Introduction Installing Camel Components Deploying Camel Routes

2010 anova r&d bvba

17/80

Camel

2010 anova r&d bvba

18/80

Introduction

What is Apache Camel?


open-source mediation and routing based on Enterprise Integration Patterns routes are defined in

Java DSL Spring XML DSL Scala DSL

2010 anova r&d bvba

19/80

Installing Camel Components


Camel itself is installed by default Additional Camel Components

can be installed through features


| ] ] ] ] ] ] grep camel camel camel-core camel-spring-osgi camel-cxf camel-mina camel-jetty repo-0 repo-0 repo-0 repo-0 repo-0 repo-0

karaf@root> features:list [installed ] [2.2.0 [installed ] [2.2.0 [installed ] [2.2.0 [uninstalled] [2.2.0 [uninstalled] [2.2.0 [uninstalled] [2.2.0

karaf@root> features:install camel-scala karaf@root> features:install camel-tagsoup 2.2.0


2010 anova r&d bvba

20/80

Deploying Camel Routes

3 options for deployment


Plain Spring XML DSL deployment Spring XML DSL in a bundle Java/Scala DSL in a bundle

2010 anova r&d bvba

21/80

Deploying Camel Routes

Plain Spring XML DSL deployment


<?xml version="1.0"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <camelContext xmlns="http://camel.apache.org/schema/spring"> <route> <from uri="timer:camel-on-smx4?period=3000" /> <to uri="log:camel-on-smx4"/> </route> </camelContext> </beans>
2010 anova r&d bvba

22/80

Deploying Camel Routes

Create a bundle with

Spring XML file in META-INF/spring in the Spring XML file itself in Java/Scala DSL RouteBuilders

Routes can be defined


2010 anova r&d bvba

23/80

Deploying Camel Routes

Spring XML file with RouteBuilder classes


<?xml version="1.0"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:camel="http://camel.apache.org/schema/spring" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd"> <camelContext xmlns="http://camel.apache.org/schema/spring"> <packageScan> <!-- refer to package that contains RouteBuilders --> <package>be.anova.course.servicemix.camel</package> <excludes>**.Base*</excludes> <includes>**.*</includes> </packageScan> </camelContext> </beans>
2010 anova r&d bvba

24/80

When to use Camel?

Default choice for integration


easy to use feature-rich lots of components available add other technology when necessary

ActiveMQ for reliable, async messaging CXF for web services support NMR JBI
25/80

2010 anova r&d bvba

Planning

Overview and architecture Getting started Camel Normalized Message Router Java Business Integration

2010 anova r&d bvba

26/80

NMR

Introduction NMR API Camel NMR component When to use? Exercise

2010 anova r&d bvba

27/80

NMR

2010 anova r&d bvba

28/80

Introduction

Normalized Message Router

Used for

foundation for JBI support Camel NMR messaging CXF NMR messaging

Messaging API with OSGi-based implementation Ensure ServiceMix' independence of different messaging technologies
29/80

2010 anova r&d bvba

Introduction

Other features

Endpoint wiring Listener interfaces


ExchangeListener EndpointListener

Shell for managing the NMR

2010 anova r&d bvba

30/80

NMR API

Exchange

used for exchanging messages between endpoints contains


ID MEP properties in, out and fault Message

2010 anova r&d bvba

31/80

NMR API

Message

body support for both XML and Object payloads headers attachments

2010 anova r&d bvba

32/80

NMR API

Example: Exchange and Message


public void process(Exchange exchange) { String id = exchange.getId(); Pattern pattern = exchange.getPattern(); String property = exchange.getProperty("property.key", String.class); Message in = exchange.getIn(); Object object = in.getBody(); String body = in.getBody(String.class); Object attached = in.getAttachment("attachment.name"); Object header = in.getHeader("header.key");

2010 anova r&d bvba

33/80

NMR API

Listener interfaces

ExchangeListener EndpointListener register Listener interfaces in OSGi Service Registry NMR will invoke methods on all registered instances

Use OSGi whiteboard pattern

2010 anova r&d bvba

34/80

NMR API

Example: ExchangeListener
private class MyExchangeListener implements ExchangeListener { public void exchangeDelivered(Exchange exchange) { } public void exchangeFailed(Exchange exchange) { } public void exchangeSent(Exchange exchange) { } }

2010 anova r&d bvba

35/80

NMR API

Example: EndpointListener
public class MyEndpointListener implements EndpointListener { public void endpointRegistered(InternalEndpoint endpoint) { } public void endpointUnregistered(InternalEndpoint endpoint) { } }

2010 anova r&d bvba

36/80

NMR API

Example: Blueprint service registration


<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"> <bean id="MyEndpointListener" class="listener.MyEndpointListener" /> <service ref="MyEndpointListener"> <interfaces> <value> org.apache.servicemix.nmr.api.event.EndpointListener </value> <value>org.apache.servicemix.nmr.api.event.Listener</value> </interfaces> </service> </blueprint>

2010 anova r&d bvba

37/80

Camel NMR component

Camel Component

URI to interact with NMR


sending exchanges to NMR endpoint register NMR endpoint to receive exchanges

URI syntax: nmr:EndpointName

Add to Spring XML file with import


<import resource="classpath:org/apache/servicemix/camel/nmr/camel-nmr.xml" />

2010 anova r&d bvba

38/80

Camel NMR component

Example: Using the Camel NMR component


// route with provider endpoint // to send NMR Exchange from("direct:endpoint") .to("nmr:Orders"); // route with consumer endpoint // registers NMR Endpoint to receive // Exchanges from("nmr:Orders") .beanRef("OrderService", "processOrder");

2010 anova r&d bvba

39/80

When to use the NMR?

Use the NMR

for linking Camel routes across bundles (with the Camel NMR component) for linking CXF endpoints across bundles (with the CXF NMR transport) if you require support for pluggable ExchangeListener/EndpointListener (e.g. auditing or BAM)

2010 anova r&d bvba

40/80

Exercise

Connect the sender and receiver Camel router bundles


Add import to Spring XML Add NMR endpoints to connect two routes Log exchange IDs and properties Ensure that the listener can be dynamically (de)activated by stopping/starting the bundle

Implement an ExchangeListener bundle


2010 anova r&d bvba

41/80

Planning

Overview and architecture Getting started Camel Normalized Message Router Java Business Integration

2010 anova r&d bvba

42/80

JBI

Introduction JBI 1.0 in depth Packaging options ServiceMix JBI Components When to use JBI? Exercise

2010 anova r&d bvba

43/80

JBI

2010 anova r&d bvba

44/80

Introduction

Java Business Integration (JSR-208)

Pluggable architecture for integration systems Components interoperate through mediated message exchange

based on the WSDL message exchange model

Implementations: ServiceMix, OpenESB, Petals ESB

2010 anova r&d bvba

45/80

Introduction

Java Business Integration (JSR-208)

ServiceMix JBI Container


version 3.x is a pure JBI container version 4.x is OSGi-based implementation version 2010.01 is latest compatible with both versions

ServiceMix JBI Components


2010 anova r&d bvba

46/80

JBI 1.0 in depth

JBI 1.0 API defines


SPI for JBI Component developers Messaging API Mechanism for exchanges to flow between components Standard for packaging components and for packaging the services deployed on them Administration and management hooks to allow for standard tools
47/80

2010 anova r&d bvba

JBI 1.0 in depth

2 kinds of components

Service Engine (SE) Allow implementing business logic or services on the ESB e.g. servicemix-drools or servicemix-bean Binding Components Provide connectivity to external services (transport, normalization, ...) e.g. servicemix-ftp or servicemix-http

2010 anova r&d bvba

48/80

JBI 1.0 in depth

Messaging API

MessageExchange contains

in, out and fault NormalizedMessage exchange properties metadata for routing

exchange id exchange pattern error service, endpoint, operation, interface role and status

2010 anova r&d bvba

49/80

JBI 1.0 in depth

Messaging API

NormalizedMessage contains

XML message content headers attachments security subject

2010 anova r&d bvba

50/80

JBI 1.0 in depth

Example: Messaging API


public void process(MessageExchange exchange) { if (exchange.getStatus() == ExchangeStatus.ACTIVE) { String id = exchange.getExchangeId(); Object property = exchange.getProperty("property.key"); NormalizedMessage in = exchange.getMessage("in"); Source content = in.getContent(); DataHandler attachment = in.getAttachment("attachment.name"); Object header = in.getProperty("header.key");

2010 anova r&d bvba

51/80

JBI 1.0 in depth

Endpoints

Internal endpoints

exposed within the JBI environment examples: file sender endpoint bean endpoint endpoints 'outside' of JBI environment examples: file poller endpoint jms consumer endpoint
52/80

External endpoints

2010 anova r&d bvba

JBI 1.0 in depth

MessageExchange routing

static with service (and endpoint) name static with interface name dynamic with endpoint reference (EPR)

2010 anova r&d bvba

53/80

JBI 1.0 in depth

MEPs

MEPs start in ACTIVE status


InOnly : in message InOut : in message and out (or fault) message RobustInOnly : in message, optionally fault message on in InOptionalOut : in message, optionally out (or fault), optionally fault message on out

All MEPs end with a DONE or ERROR Message

2010 anova r&d bvba

54/80

JBI 1.0 in depth

Example : InOnly MEP

2010 anova r&d bvba

55/80

JBI 1.0 in depth

Example : InOut MEP

2010 anova r&d bvba

56/80

Packaging options

Options for deploying endpoints on ServiceMix 4


JBI Packaging (Service Assembly) Spring XML deployment


deploy plain XML file deploy XML file in bundle

2010 anova r&d bvba

57/80

Packaging options

JBI Packaging - Service Assembly (SA)

ZIP archive that contains


META-INF/jbi.xml Service Units

Deployment descriptor specifies target components for every SU

2010 anova r&d bvba

58/80

Packaging options

JBI Packaging Service Unit (SU)

ZIP archive that contains


META-INF/jbi.xml component-specific endpoint descriptions extra classes, JARs, ... used by SU

2010 anova r&d bvba

59/80

Packaging options

JBI Packaging

jbi-maven-plugin to create JBI packages

2010 anova r&d bvba

60/80

Packaging options

Single Spring XML file


add all endpoints in a single Spring XML add o.a.s.common.osgi.EndpointExporter to register JBI endpoints add XML file to META-INF/spring folder

OSGi Bundle with Spring XML File

2010 anova r&d bvba

61/80

Packaging options

Example: single XML file for JBI endpoints


<beans xmlns:amq="http://activemq.apache.org/schema/core" xmlns:file="http://servicemix.apache.org/file/1.0" xmlns:jms="http://servicemix.apache.org/jms/1.0" xmlns:course="urn:be:anova:course:servicemix:jbi"> <file:poller service="course:poller" endpoint="orders" targetService="course:orders" file="file:/home/orders" /> <jms:producer service="course:orders" endpoint="endpoint" connectionFactory="#connectionFactory" destinationName="queue.orders" /> <amq:connectionFactory id="connectionFactory" brokerURL="tcp://localhost:61616"/> <bean class="org.apache.servicemix.common.osgi.EndpointExporter" /> </beans>
2010 anova r&d bvba

62/80

ServiceMix JBI Components

Binding Components
servicemix-cxf-bc servicemix-file servicemix-ftp servicemix-http servicemix-jms servicemix-mail servicemix-smpp servicemix-snmp servicemix-truezip servicemix-vfs servicemix-xmpp

2010 anova r&d bvba

63/80

ServiceMix JBI Components

servicemix-file

namespace uri http://servicemix.apache.org/file/1.0 <file:poller/> for reading files <file:sender/> for writing files

2010 anova r&d bvba

64/80

ServiceMix JBI Components

Example: File SU xbean.xml


file poller reads from orders/input file sender writes to orders/output

<beans xmlns:file="http://servicemix.apache.org/file/1.0" xmlns:course="urn:be:anova:course:servicemix:jbi"> <file:poller service="course:poller" endpoint="poller" targetService="course:sender" file="file:orders/input" /> <file:sender service="course:sender" endpoint="sender" directory="file:orders/output"/> </beans>
2010 anova r&d bvba

65/80

ServiceMix JBI Components

Sidetrack: Marshalers

convert transport specific data format into XML (and back again) default implementations available for XML, implement your own for other data formats

2010 anova r&d bvba

66/80

ServiceMix JBI Components

Sidetrack: Marshalers

Example: CSV extends DefaultFileMarshaler

String getOutputName(MessageExchange, NormalizedMessage) { //TODO: determine file name } void writeMessage(MessageExchange, NormalizedMessage, OutputStream, String) { //TODO: write NormalizedMessage content to OutputStream as CSV } void readMessage(MessageExchange, NormalizedMessage, InputStream, String) { //TODO: read CSV from InputStream and convert to // NormalizedMessage content (Source) }
2010 anova r&d bvba

67/80

ServiceMix JBI Components

servicemix-jms

namespace URI http://servicemix.apache.org/jms/1.0 endpoints


jms:consumer, jms:soap-consumer and jms:jcaconsumer for receiving JMS messages jms:provider and jms:soap-provider for sending JMS messages

support plain XML and SOAP/JMS payloads

2010 anova r&d bvba

68/80

ServiceMix JBI Components

Example: JMS SU xbean.xml


<beans xmlns:amq="http://activemq.apache.org/schema/core" xmlns:jms="http://servicemix.apache.org/jms/1.0" xmlns:course="urn:be:anova:course:servicemix:jbi"> <jms:consumer service="course:consumer" endpoint="endpoint" connectionFactory="#connectionFactory" destinationName="input.orders" targetService="course:producer" /> <jms:producer service="course:producer" endpoint="endpoint" connectionFactory="#connectionFactory" destinationName="output.orders" /> <amq:connectionFactory id="connectionFactory" brokerURL="tcp://localhost:61616"/> </beans>
2010 anova r&d bvba

69/80

ServiceMix JBI Components

Service Engines
servicemix-bean servicemix-camel servicemix-cxf-se servicemix-drools servicemix-eip servicemix-exec servicemix-osworkflow servicemix-quartz servicemix-saxon servicemix-scripting servicemix-validation servicemix-wsn2005

2010 anova r&d bvba

70/80

ServiceMix JBI Components

servicemix-bean

allows processing MessageExchange with Java beans endpoints:


<bean:endpoint /> to define POJO endpoint auto-deployed endpoints using @Endpoint annotation

provides a set of annotations e.g. @Resource for injecting DeliveryChannel

2010 anova r&d bvba

71/80

ServiceMix JBI Components

Example: the bean code


public class ProcessingBean implements MessageExchangeListener { @Resource private DeliveryChannel channel; public void onMessageExchange(MessageExchange exchange) throws MessagingException { if (exchange.getStatus() == ExchangeStatus.ACTIVE) { Source content = exchange.getMessage("in").getContent(); // processing the XML Source here... exchange.setStatus(ExchangeStatus.DONE); channel.send(exchange);

}
2010 anova r&d bvba

72/80

ServiceMix JBI Components

Example: Bean SU xbean.xml


<beans xmlns:bean="http://servicemix.apache.org/bean/1.0" xmlns:course="urn:be:anova:course:servicemix:jbi"> <!-- this is a Spring bean --> <bean id="processingBean" class="be.anova.course.servicemix.jbi.ProcessingBean" /> <bean:endpoint service="course:bean" endpoint="processing" bean="#processingBean" /> </beans>

2010 anova r&d bvba

73/80

ServiceMix JBI Components

servicemix-camel

use Camel for routing inside JBI container Spring CamelContext for deployment URI for interacting with JBI

jbi:service:<namespace><service> jbi:endpoint:<namespace><service><endpoint> use : or / as separator

2010 anova r&d bvba

74/80

ServiceMix JBI Components

servicemix-camel

from(jbi:...)

exposes an internal endpoint can be used as target service for other endpoints send to another JBI endpoint from within your Camel route

to(jbi:...)

2010 anova r&d bvba

75/80

ServiceMix JBI Components

Example: Java DSL RouteBuilder


public class MyRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { from("timer:events?period=5000") .setBody().constant("<hello/>") .to("jbi:service:urn:be:anova:servicemix:jbi:forwarder"); from("jbi:service:urn:be:anova:servicemix:jbi:forwarder") .to("jbi:endpoint:urn:be:anova:servicemix:jbi:target:endpoint"); from("jbi:endpoint:urn:be:anova:servicemix:jbi:target:endpoint") .to("log:events"); } }

2010 anova r&d bvba

76/80

ServiceMix JBI Components

Example: Spring camelContext.xml file


<beans xmlns:camel="http://camel.apache.org/schema/spring"> <camelContext xmlns="http://camel.apache.org/schema/spring"> <packageScan> <!-- Use Java/Scala DSL classes for defining routes... --> <package>be.anova.course.servicemix.jbi</package> </packageScan> <!-- ... or use the Spring XML DSL --> <route> <from uri="jbi:endpoint:urn:be:anova:servicemix:jbi:target:endpoint" /> <to uri="log:target-received"/> </route> </camelContext> </beans>
2010 anova r&d bvba

77/80

When to use JBI?

When to use JBI in ServiceMix 4?


When use of external standards is required To leverage existing investments in JBI To leverage third-party JBI components For building WSDL-oriented SOA applications Support for BPEL using ODE's JBI deployment

2010 anova r&d bvba

78/80

Exercise

In the JBI packaging example

create a Camel route to link the two file endpoints and do the XSL transformation

Define the endpoints in bridge.xml to create a HTTP to JMS bridge In the file-to-bean project

add the file endpoint display the exchange id and properties from bean endpoint
79/80

2010 anova r&d bvba

Planning

Overview and architecture Getting started Camel Normalized Message Router Java Business Integration

2010 anova r&d bvba

80/80

You might also like