Building Asynchronous Services With Sca

41
Building Asynchronous Services with SCA Mike Edwards Raymond Feng Luciano Resende

description

 

Transcript of Building Asynchronous Services With Sca

Page 1: Building Asynchronous Services With Sca

Building Asynchronous Services with SCA

Mike EdwardsRaymond FengLuciano Resende

Page 2: Building Asynchronous Services With Sca

Agenda

> Service Component Architecture> Why Asynchronous Services?> Facilities for Async Services> SCA support for service interactions> Example Async Service & Client> Events and Async Services compared> Demo Scenario> Summary

Page 3: Building Asynchronous Services With Sca

>> executableexecutable model for assembling services● composites provide language to compose and

configure service components

● handles service dependencies

> Simplified component programming modelcomponent programming model for implementing services

● BPEL processes, JavaTM POJOs, EJBs, COBOL, PHP scripts, C++ apps, JavaScript & AJAX, XSLT…

> Late binding of policypolicy and communicationcommunicationmethods, with distributed deploymentdistributed deployment model

What SCA is

Page 4: Building Asynchronous Services With Sca

Composite A

ComponentAService

Service BindingWeb ServiceJMSSLSBRestJSONRPCJCA…

Reference BindingWeb ServiceJMSSLSBRestJSONRPCJCA…

ComponentB

Service Interface- Java- WSDL

Reference Interface

Reference

property setting

Property

promotepromote wire

ImplementationJavaBPELPHPSCA compositespringEJB module…

- Java- WSDL

SCA Overview

Page 5: Building Asynchronous Services With Sca

> One way to look at SCA is that it takes details of ● access methods and endpoints

● implementations and configuration

● policy such as encryption, authentication

> …and moves them into middleware layer

> Application developers write business logic: code that actually builds value

● details of using services handled by SCA

● late binding: as details change, applications (and developers who wrote them) aren’t affected

● "no plumbing in the code"

Why SCA makes life simpler

Page 6: Building Asynchronous Services With Sca

> SCA gives developers single programming model for using servicessingle programming model for using servicesfor all aspects of service lifecycle:

– Construction– Assembly– Deployment

> As your SOA gets more complex, developers have to learn more and more interfaces● In JavaTM alone: EJBs, RMI, JCA, JAX-WS, JMS...

Why SCA makes life simpler

Page 7: Building Asynchronous Services With Sca

> model for:> building service components> assembling components into applications > deploying to (distributed) runtime environments

- Service components built from new or existing code using SOA principles

- vendor-neutral – supported across the industry- language-neutral – components written using any

language- technology-neutral – use any communication

protocols and infrastructure to link components

Service Component Architecture (SCA): Simplified Programming Model for SOA

Page 8: Building Asynchronous Services With Sca

Agenda

> Service Component Architecture> Why Asynchronous Services?> Facilities for Async Services> SCA support for service interactions> Example Async Service & Client> Events and Async Services compared> Demo Scenario> Summary

Page 9: Building Asynchronous Services With Sca

> Typical in business processes

> …not everything happens immediately

> …a single request can result in a sequence of responses over time

> …a client probably does not want to wait while all steps are completed

Asynchronous interactions

Page 10: Building Asynchronous Services With Sca

Synchronous Processing

Client Provider

Price of IBM stock?

IBM = $121.50

Price of AT&T stock?

AT&T = $38.72

Page 11: Building Asynchronous Services With Sca

Asynchronous Processing

Order Books X, Y, Z

Acknowledge, OrderID = 3824

OrderID = 3824 Expect dispatch = 12/06/2008

OrderID = 3824 Books X,Y dispatched 10/06/2008Package ID = 478842110

OrderID = 3824 Books Z dispatched 13/06/2008Package ID = 479567736

Client Provider

Page 12: Building Asynchronous Services With Sca

Why Asynchronous Services?

> Business processes involve long running multi-step sequences

> Clients & Services cannot afford to wait on long request/response operations● impact on processing resources,

memory, communication resources

Page 13: Building Asynchronous Services With Sca

Agenda

> Service Component Architecture> Why Asynchronous Services?> Facilities for Async Services> SCA support for service interactions> Example Async Service & Client> Events and Async Services compared> Demo Scenario> Summary

Page 14: Building Asynchronous Services With Sca

Synchronous Services

> plenty of support for synchronous programming

> call-and-return typical for most programming languages

> most service frameworks support this -for clients & service providers

SearchResponse search(SearchRequest searchRequest);

Page 15: Building Asynchronous Services With Sca

Asynchronous Services

> Facilities less common● JavaTM concurrency classes

● JAX-WS asynchronous client● JMS messaging● BPEL

Page 16: Building Asynchronous Services With Sca

JAX-WS Async Client APISearchResponse search(SearchRequest sRequest );

Future<?> searchAsync(SearchRequest oRequest,AsyncHandler<SearchResponse> responseHandler );

class SearchResponseHandler implements AsyncHandler<SearchResponse> {

public void handleResponse( Response<SearchResponse > theResponse ){

SearchResponse orderResponse = theResponse.get();}

}

+

Page 17: Building Asynchronous Services With Sca

JMS/Messaging

> Supports async clients and async services

Client Service

a.send( message1 ) message1 = x.receive( )

message2 = b.receive( ) y.send( message2 )

+ messageListener onMessage listener interface

.

.

.

.

.

.

Page 18: Building Asynchronous Services With Sca

BPEL and Async Processing

> BPEL designed to handle:● long running processes ● with asynchrony● multiple partner relationships

Page 19: Building Asynchronous Services With Sca

Agenda

> Service Component Architecture> Why Asynchronous Services?> Facilities for Async Services> SCA support for service interactions> Example Async Service & Client> Events and Async Services compared> Demo Scenario> Summary

Page 20: Building Asynchronous Services With Sca

SCA Service Interaction

TripCataclogComponent

AccountData

Service

Component

FlightComponent

Reference Service

Synchronous or Asynchronous interaction styles supported- depends on the interface definition

Callback (optional)

Page 21: Building Asynchronous Services With Sca

SCA Callbacks> SCA supports Async services using Callbacks

● service has regular forward call interface● + callback interface on which service makes calls

back to clients● clients implement the callback interface

● SCA callbacks are part of the business● Forward calls and callbacks can use different

styles such as:● Oneway + Req/Res● Req/Res + Req/Res● Req/Res + Oneway● Oneway + Oneway

Page 22: Building Asynchronous Services With Sca

Sync and Async Interfaces

public interface SyncSearchService {

public SearchResponse search( SearchRequest sReques t );

}

public interface AsyncSearchService {

public void search( SearchRequest sRequest );

}

public interface AsyncSearchCallback {

public void searchResponse( SearchResponse sResponse );

}

Page 23: Building Asynchronous Services With Sca

Callback Interfaces

> Callback interface● may have multiple operations/methods● operations may be called at any time

after initial forward call to service● number and sequence of callback

operations for given forward call is variable (0, 1, many…)

Page 24: Building Asynchronous Services With Sca

Bidirectional Service Interaction

• The reference creates a callback endpoint to receive callbacks

• The service establishes a “callback” reference to the caller

• The forward call can use different binding than the callback

FlightSearch

Callback endpoint for reference flightSearch

Callback binding

binding

Page 25: Building Asynchronous Services With Sca

Agenda

> Service Component Architecture> Why Asynchronous Services?> Facilities for Async Services> SCA support for service interactions> Example Async Service & Client> Events and Async Services compared> Demo Scenario> Summary

Page 26: Building Asynchronous Services With Sca

Bidirectional Interface• Forward Interface

• Callback Interface

@Remotable

@Callback(SearchCallback.class)

public interface Search {

TripItem[] searchSynch(TripLeg tripLeg);

@OneWay

void searchAsynch(TripLeg tripLeg);

}

@Remotable

public interface SearchCallback {

void searchResults(TripItem[] items);

}

Page 27: Building Asynchronous Services With Sca

Trip Async Search

TripCataclog

Component

AccountData

Service

Component

FlightComponent

Callback

AccountData

Service

Component

HotelComponent

AccountData

Service

Component

CarComponent

AccountData

Service

Component

PackagesComponent

Callback

Callback

Callback

Page 28: Building Asynchronous Services With Sca

Flight Service implementation

import org.osoa.sca.annotations.*;public class FlightImpl implements Search, Book {

@Callbackprotected SearchCallback searchCallback;

……….

public void searchAsynch(TripLeg tripLeg) {

……….

// return available flightssearchCallback.searchResults(searchSynch(tripLeg));

}

}

Page 29: Building Asynchronous Services With Sca

Catalog client applicationimport org.osoa.sca.annotations.*;public class TravelCatalogImpl implements TravelCat alogSearch, SearchCallback{

@Reference protected Search flightSearch;……

public TripItem[] search(TripLeg tripLeg) { flightSearch.searchAsynch(tripLeg);……

}

public void searchResults(TripItem[] items){if (items != null) {

for(int i = 0; i < items.length; i++ ){searchResults.add(items[i]);

}}……

}

}

Page 30: Building Asynchronous Services With Sca

<component name="TravelCatalogComponent"><implementation.java class="scatours.travelcatalog. TravelCatalogImpl"/><reference name="flightSearch">

<interface.java interface="scatours.common.Search" callbackInterface="scatours.common.SearchCallback"/ >

<binding.ws uri="http://localhost:8080/Flight/Searc h"/><callback>

<binding.ws uri="http://localhost:8080/Flight/Searc hCallback"/></callback>

</reference> </component>

<component name="FlightComponent"><implementation.java class="scatours.flight.FlightI mpl"/><service name="Search">

<interface.java interface="scatours.common.Search" callbackInterface="scatours.common.SearchCallback"/ >

<binding.ws uri="http://localhost:8080/Flight/Searc h"/><tuscany:binding.jsonrpc/><callback>

<binding.ws uri="http://localhost:8080/Flight/Searc hCallback"/></callback>

</service><service name="Book"/>

</component>

Composite

forward interface

callback interface

callback binding

Page 31: Building Asynchronous Services With Sca

"under the hood"

> How do the callbacks work in practice?● implemented using suitable

communication methods, such as:

● JMS messaging● Web services using WS-Addressing

Page 32: Building Asynchronous Services With Sca

Agenda

> Service Component Architecture> Why Asynchronous Services?> Facilities for Async Services> SCA support for service interactions> Example Async Service & Client> Events and Async Services compared> Demo Scenario> Summary

Page 33: Building Asynchronous Services With Sca

Asynchrony & Events

> Another way to handle asynchrony is to use events

> components communicate by producing and consuming events● these are one-way● asychronous● arbitrary sequences

> eg JMS messages

Page 34: Building Asynchronous Services With Sca

Events or Callbacks

> Both allow asynchrony> Calls target single specific service> Callbacks ensure responses go back to

original requester> Event handling is more flexible

● pub/sub, broadcasting of events● no guarantee that anyone listens

Page 35: Building Asynchronous Services With Sca

Agenda

> Service Component Architecture> Why Asynchronous Services?> Facilities for Async Services> SCA support for service interactions> Example Async Service & Client> Events and Async Services compared> Demo Scenario> Summary

Page 36: Building Asynchronous Services With Sca

36

SCA Tours Online Travel Sample Scenario

http://svn.apache.org/repos/asf/tuscany/sandbox/travelsample

Page 37: Building Asynchronous Services With Sca

SCA Tours – Asynchronous Search Services

TravelCatalog

HotelPartner

FlightPartner

CarPartner

TripPartner

Java

Java

Java

fullapp-frontend (8084)

fullapp-packagedtrip (8085)

fullapp-bespoketrip (8086)

Java

Java

binding.ws

Page 38: Building Asynchronous Services With Sca

Agenda

> Service Component Architecture> Why Asynchronous Services?> Facilities for Async Services> SCA support for service interactions> Example Async Service & Client> Events and Async Services compared> Demo Scenario> Summary

Page 39: Building Asynchronous Services With Sca

Summary

> Asynchronous services are a fact of life

> SCA makes providing async services and their clients simpler and easier

> SCA supports this on a range of communication methods

Page 40: Building Asynchronous Services With Sca

Useful links> Articles about SCA:

� http://www.infoq.com/articles/setting-out-for-sca� http://www.osoa.org/display/Main/SCA+Resources

> Apache Tuscany - Open Source implementation of SCA:� http://tuscany.apache.org/

> SCA Specifications in OASIS:� http://www.oasis-opencsa.org/