Download as pdf or txt
Download as pdf or txt
You are on page 1of 49

SWITCHYARD

S Y S T E M I N T E G R AT I O N W I T H
JBOSS

Tomáš Rohovský = trohovsk@redhat.com


Tomáš Turek - tturek@redhat.com
AGENDA
What is SwitchYard?
Service Component Architecture
Cross cutting concerns
Component implementations
Clustering
Testing
SWITCHYARD
"A lightweight service delivery framework providing
full lifecycle support for developing, deploying, and
managing service-oriented applications."

Integration framework based on Camel


Supports various protocols and implementations
Implements Service Component Architecture specification
Can run in WildFly/EAP (J2EE) or Karaf/Fuse (OSGi)
SYSTEM INTEGRATION
Inventory check

Shop sending
purchase order

Shipping

Account process
SERVICE
Is a logical representation of a repeatable business activity
Is self-contained
May be composed of other services
Is a "black box" to consumers of the service
Service
policy

operation
implementation
operation

contract
SERVICE CONTRACTS
Agreement between consumer and provider
Contract-based development
Service Interface
Implementation Hiding
Service
policy

operation
implementation
operation

contract
SCA
S E RVI C E CO M PO N E N T ARC H I T ECT U R E

A Set of specifications which describe a model for building


applications and systems using a Service-Oriented
Architecture (SOA).

OASIS standard for creating service-oriented applications


vendor neutral
language neutral
technology neutral
SCA
B A S E A R T E FA C T S
Composite
Components
Services
References
Wires
Properties
COMPOSITE
Define the application boundary
Application name (documentation)
Application namespace (important)
One per application
COMPONENT
Container for application logic
Worthless without an implementation
0 ... 1 services
0 ... * references
1 implementation
IMPLEMENTATION
Adds intelligence/action to a component
Private to an application
First step in bottom-up
approach
Implementations
Bean
Camel
BPMN
BPEL
Rules
COMPONENT SERVICE

Exposes functionality of a component as a service


Application private
Name
Contract
SERVICE CONTRACT

Agreement between consumer and provider


Collection of operations
Each operation defines exchange pattern and message
types

Java, WSDL, ESB


EXAMPLE CONTRACTS
public interface OrderService {
J AVA }
OrderAck submitOrder(Order order);

<por tType name="OrderService">


<operation name="submitOrder">
<input name="tns:submitOrder"/>
<output name="tns:submitOrderRresponse"/> WSDL
</operation>
</por tType>

<interface.esb
inputType="json:orders:Order"
ESB outputType="java:org.example.OrderAck"
faultType="{urn:example}error"/>
COMPOSITE SERVICE

Service available outside an application


“Promotes” a component service
Name
Contract
SERVICE BINDINGS
How external consumers communicate with a
service
A composite service can have multiple
bindings
A component service never has bindings
Conforms to service contract

Camel, Ftp, File, Http, JCA, JMS, JPA, Mail,


TCP, UDP, REST, SOAP, SQL, ...
COMPONENT REFERENCE
Allow a component to consume other services
Can be wired to services inside and outside an application
Implementation dependency
Name
Contract
COMPOSITE REFERENCE
Wires to services outside an application
“Promotes” a component reference
Application dependency
Name
Contract
REFERENCE BINDING
Defines how external services are accessed
Composite reference can have only one binding
Component reference never has bindings
Conforms to reference contract

Camel, Ftp, File, Http, JCA, JMS, JPA, Mail, TCP, UDP,
REST, SOAP, SQL, ...
APPLICATION DESCRIPTOR
< c o m p o s i t e x m l n s = " h t t p : / /d o c s .o a s i s - o p e n .o rg /n s /o p e n c s a /s c a / 2 0 0 9 1 2 " n a m e = " o rd e r s "
t a rg e t N a m e s p a c e = " u r n : s w i t c h y a rd - q u i c k s t a r t - d e m o : o rd e r s : 0 . 1 . 0 " >
< s e r v i c e n a m e = " O rd e r S e r v i c e " p ro m o t e = " O rd e r S e r v i c e " >
< i n t e r f a c e .w s d l i n t e r f a c e = " w s d l / O rd e r S e r v i c e .w s d l # w s d l . p o r t t y p e ( O rd e r S e r v i c e ) " / >
< b i n d i n g . s o a p x m l n s = " u r n : s w i t c h y a rd - c o m p o n e n t - s o a p : c o n fig : 1 . 0 " >
< w s d l > w s d l / O rd e r S e r v i c e .w s d l < / w s d l >
< s o c ke t A d d r > : 1 8 0 0 1 < / s o c ke t A d d r >
< c o n t ex t Pa t h > d e m o - o rd e r s < / c o n t ex t Pa t h >
</binding.soap>
</service>
<component name="InventoryService">
< i m p l e m e n t a t i o n . b e a n c l a s s = " o rg .exa m p l e . I n v e n t o r y S e r v i c e B e a n " / >
<service name="InventoryService">
< i n t e r f a c e . j a v a i n t e r f a c e = " o rg .exa m p l e . I n v e n t o r y S e r v i c e " / >
</service>
</component>
< c o m p o n e n t n a m e = " O rd e r " >
< i m p l e m e n t a t i o n . b e a n c l a s s = " o rg .exa m p l e .O rd e r " / >
< re fe re n c e n a m e = " O rd e r S e r v i c e " >
< i n t e r f a c e . j a v a i n t e r f a c e = " o rg .exa m p l e .O rd e r S e r v i c e " / >
< / re fe re n c e >
</component>
< c o m p o n e n t n a m e = " O rd e r S e r v i c e " >
< i m p l e m e n t a t i o n . b e a n c l a s s = " o rg .exa m p l e .O rd e r S e r v i c e B e a n " / >
< s e r v i c e n a m e = " O rd e r S e r v i c e " >
< i n t e r f a c e . j a v a i n t e r f a c e = " o rg .exa m p l e .O rd e r S e r v i c e " / >
</service>
< re fe re n c e n a m e = " I n v e n t o r y S e r v i c e " >
< i n t e r f a c e . j a v a i n t e r f a c e = " o rg .exa m p l e . I n v e n t o r y S e r v i c e " / >
< / re fe re n c e >
</component>
</composite>
APPLICATION MODEL
KEY BENEFITS OF SCA
Loose Coupling: components integrate without need to know how othe
rs are implemented

Flexibility: components can easily be replaced by other components

Composition of solutions: clearly described

Productivity: easier to integrate components to form composite applic


ation

Heterogeneity: multiple implementation languages, communication m


echanisms

Declarative application of infrastructure services

Simplification for all developers, integrators and application deployers


COMPONENT
IMPLEMENTATIONS

BEAN
CAMEL
BPEL
BPM
RULES
BEAN IMPLEMENTATION

Standard CDI beans with a few extra annotations

@S e r v i c e ( G re e t i n g S e r v i c e .c l a s s )
p u b l i c c l a s s G re e t i n g S e r v i c e B e a n i m p l e m e n t s G re e t i n g S e r v i c e {

@Inject
@ Re fe re n c e
p r i va t e L a n g u a g e S e r v i c e l a n g u a g e S e r v i c e ;
/ / p r i va t e Re fe re n c e I nvo ke r l a n g u a g e S e r v i c e ;

p u b l i c vo i d g re e t ( S t r i n g n a m e ) {
S t r i n g g re e t i n g = l a n g u a g e S e r v i c e .g e t G re e t i n g ( " E N " ) ;
/ / l a n g u a g e S e r v i c e . n e w I nvo c a t i o n ( " g e t G re e t i n g " ) . s e t P ro p e r t y ( " t y p e " , " i n fo r m a l " ) . i nvo ke ( " E N " ) ;
re t u r n g re e t i n g + " " + n a m e ;
}
}
BEAN IMPLEMENTATION
@ We b S e r v i c e
p u b l i c c l a s s O rd e r S e r v i c e B e a n {

@ Re s o u rc e ( m a p p e d N a m e = " j m s / C o n n e c t i o n Fa c t o r y " )
BASIC p r i va t e s t a t i c C o n n e c t i o n Fa c t o r y c f ;

@ We b M e t h o d
p u b l i c O rd e rA c k s u b m i t O rd e r ( O rd e r o rd e r ) {
...
}
}

@S e r v i c e ( O rd e r S e r v i c e .c l a s s )
p u b l i c c l a s s O rd e r S e r v i c e B e a n i m p l e m e n t s O rd e r S e r v i c e {

@ I n j e ct @ Re fe re n c e
p r i va te I nve n to r yS e r v i c e _ i nve n to r y ;

S W I T C H YA R D @ Ove r r i d e
p u b l i c O rd e rAc k su b m i t O rd e r ( O rd e r o rd e r ) {
...
}
}
CAMEL IMPLEMETATION
A route can be created in JAVA or XML DSL
Camel provides
Routing engine
Languages (Simple, XPath, scripting languages)
Loads of EIP
EXAMPLE CAMEL ROUTE
<route>
<from uri="file://orders/in"/>
<log message="Order Received : ${body}"/>
<to uri="OrderValidator”/>
CAMEL ROUTE <filter>
<xpath>/order[@priority='high']</xpath>
<to uri="file://shipping/in"/>
</filter>
</route>

<route>
<from uri="switchyard//OrderService"/>
<log message="Order Received : ${body}"/>
CAMEL IN <to uri="OrderValidator”/>
<filter>
S W I T C H YA R D <xpath>/order[@priority='high']</xpath>
<to uri="switchyard://ShippingService?operationName=shipO
</filter>
</route>
WORKFLOW SERVICES
BPMN 2

Integrated with BPMN 2


modeler

Expose workflow as a service

Invoke services as part of a


workflow

Flexible mapping between


process and message
SERVICE ORCHESTRATION
BPEL

Orchestrate web services

WSDL contract

Multiple bindings
DEMO
CROSS CUTTING CONCERNS
Transformation
Validation
Policy
Specified declaratively
Isolation from application logic
Reuse
Clear view
TRANSFORMATION
Ubiquitous challenge in application integration and SOA
Three flavors of transformation
Change in data representation
Conversion
Change in data format
Translation
Change in data itself
Enrichment
TRANSFORMATION OF
REPRESENTATION
Change in representation
Representation = Java type
Transformation is simply a type conversion
No semantic knowledge required

< o rd e r > < o rd e r > < o rd e r >


< i t e m > XY Z 1 2 3 < / i t e m >
<quantity>5</quantity>
< / o rd e r >
= < i t e m > XY Z 1 2 3 < / i t e m >
<quantity>5</quantity>
< / o rd e r >
= < i t e m > XY Z 1 2 3 < / i t e m >
<quantity>5</quantity>
< / o rd e r >

java.lang.String java.io.InputStream org.w3c.dom.Node


TRANSFORMATION OF DATA
FORMAT
Requires semantic understanding of data types
Machines cannot do this on their own
p u b l i c c l a s s O rd e r {
p r i va t e H e a d e r h e a d e r ;
p r i va t e L i s t < O rd e r I t e m > o rd e r I t e m ;
}
HR;1;ISSUED;
public class Header {
CUS;user1;Herry;
p r i va t e S t r i n g o rd e r I d ;
ORD;1;Pulp Fiction;
p r i va t e S t r i n g s t a t u s ;
O R D ; 5 ; Pe n c i l ;
}

p u b l i c c l a s s O rd e r I t e m {
p r i va t e i n q u a n t i t y ;
p r i va t e S t r i n g p ro d u c t I d ;
}
WHERE TO TRANSFORM
In the provider?
xml->Java

consume provide
xml Java

In the consumer?
xml->Java

consume provide
xml Java

Add a routing service?

consume provide
xml->Java
xml Java
DECLARATIVE
TRANSFORMATION
consume provide
xml->Java
xml Java

Transformation is wired into SwitchYard core


Types declared via service contract
Transformer resolved dynamically at runtime
Declarative, not procedural

Dozer, Java, JAXB, JSON, XSLT, Smooks


JAVA TRANSFORMER
Implement transformation directly in Java
Two options
Implement org.switchyard.transform.Transformer
​A nnotate one or more methods with @Transformer
Provides greatest flexibility, but least implementation help

@Transformer(from = "{urn:switchyard-example:orders:1.0}submitOrder",
to = "java:com.example.Order")
public Order transform(Element from) {
return new Order()
.setOrderId(getElementValue(from, "orderId”))
.setItemId(getElementValue(from, "itemId”))
.setQuantity(Integer.valueOf(getElementValue(from, "quantity”)));
}
VALIDATION
Declarative validation
Supports XML Schema and Java validation
Executes pre and post transformation

order.xsd
<validate.xml schemaType="XMLSCHEMA"
name="{urn:example:purchasing}order"
schemaFile="xsd/order.xsd"/> consume xml provide
POLICY

Declare the ‘what’, defer the ‘how’


Common service policies
Transactional behavior
Security
TRANSACTION POLICY
<service name="WorkService" promote="WorkService">
<camel:binding.camel configURI="jms://policyQSTransacted?connectionFactory=%23JmsXA
</service>
<component name="WorkService">
<implementation.bean class="org.example.WorkServiceBean"
requires="managedTransaction.Global"/>
<service name="WorkService" requires="propagatesTransaction">
...
</service>
</component>

Transaction
policy

consume provide
JMS Queue
SECURITY POLICY
<sca:component name="OrderService">
<sy:implementation.bean class="org.example.OrderServiceBean"
requires="authorization"/>
<sca:service name="OrderService"
requires="confidentiality clientAuthentication" sy:security="default">
<sca:interface. java interface="org.example.OrderService"/>
</sca:service>
</sca:component>

Security
Policy

consume provide
https://
TESTING
Develop and test your project iteratively
Service, transformation, binding, etc.
SwitchYardRunner
Bootstraps runtime, components, and application
MixIns
Enriches test case via composition vs. extension
CDI, HTTP, Smooks, BPM, HornetQ, Transaction, JCA
SERVICE TEST
@RunWith(SwitchYardRunner.class)
@SwitchYardTestCaseConfig(mixins = CDIMixIn.class)
public class InventoryServiceTest {

@ServiceOperation("InventoryService.lookupItem")
private Invoker lookupItem;

@Test
public void testItemLookupExists() throws Exception {
final String ITEM_ID = "BUTTER";
Item item = lookupItem
.sendInOut(ITEM_ID)
.getContent(Item.class);

Asser t.asser tNotNull(item);


Asser t.asser tEquals(ITEM_ID, item.getItemId());
}
}
TRANSFORMATION TEST

@RunWith(SwitchYardRunner.class)
@SwitchYardTestCaseConfig(mixins = SmooksMixIn.class)
public class SmooksTransformationTest {

private SmooksMixIn smooksMixIn;

@Test
public void testOrderTransform() throws Exception {
// Verif y the Order_XML.xml Smooks Java->XML binding
smooksMixIn.testJavaXMLReadWrite(
Order.class,
"/smooks/Order_XML.xml",
"/xml/order.xml");
}
}
BINDING TEST
@RunWith(SwitchYardRunner.class)
@SwitchYardTestCaseConfig(
config = SwitchYardTestCaseConfig.SWITCHYARD_XML,
mixins = {CDIMixIn.class, HTTPMixIn.class})
public class WebServiceTest {

private HTTPMixIn httpMixIn;

@Test
public void invokeOrderWebService() throws Exception {
httpMixIn.postResourceAndTestXML(
"http://localhost:18001/OrderService",
"/xml/soap-request.xml",
"/xml/soap-response.xml");
}
}
CLUSTERING
SHARED RUNTIME
REGISTRY
distributed Infinispan cache
published remote service
endpoints

REMOTE COMMUNICATION
CHANNELS
internal communication
protocol (HTTP)
SCA binding
CLUSTERING
EXAMPLE

<sca:service name="Goodbye" promote="GoodbyeBean/Goodbye">


<sca:interface.java interface="com.example.Goodbye"/>
<sca:binding.sca sy:clustered="true"/>
</sca:service>

<sca:reference name="Goodbye" multiplicity="0..1"


promote="GreetingBean/Goodbye">
<sca:interface.java interface="com.example.Goodbye"/>
<sca:binding.sca sy:clustered="true"
</sca:reference>
MORE INFO
SWITCHYARD
http://switchyard.jboss.org/

GITHUB
https://github.com/jboss-switchyard

REDHAT
https://access.redhat.com/products/red-hat-jboss-fuse-service-works/

SCA
http://osasis-open.org/committees/sca-assembly
THANK YOU!

You might also like