Share
Embed
Fuse Service Works Best Practices
Fuse Service Works : Integration Recipes, Best Practices, and Cheat Codes
Kenneth Peeples
August 19, 2014
Transcript
84 slides
-
Red Hat JBoss Fuse Service Works Integration Recipes, Best Practices
& Cheat Codes Keith Babo SwitchYard Project Lead, Red Hat Tuesday, April 22, 14 -
There is Still Time To Leave • We will be
talking integration and SOA If your company has more than one application, this is likely relevant • Some background and overview Quick and painless • Main focus is using technology to solve problems Practitioner’s rejoice! • Lots of live demo Increased odds of crash and burn. Exciting! Tuesday, April 22, 14 -
Key • Integration Recipe Using features of the platform to
get things done • Best Practice The right way to use a feature • Cheat Code Maybe not right, but fun Tuesday, April 22, 14 -
Format 10 OVERVIEW 20 RECIPE 30 BEST PRACTICE 40 CHEAT
CODE 50 GOTO 20 Tuesday, April 22, 14 -
Recipes • Application Development • Implementation strategy • Testing •
Connectivity • Dealing with data • Deployment & Packaging • Debugging Tuesday, April 22, 14 -
Fuse Service Works 7 Enterprise Messaging JMS/STOMP/NMS/MQTT JBoss HornetQ &
Apache Active-MQ Overlord RTGov Integration & Connectivity Transformation, Mediation, Enterprise Integration Patterns Apache Camel Drools Decision Management Declarative, inference rule execution JBoss EAP/Karaf Enterprise Container Secure and manageable jBPM & Riftsaw Service Orchestration Orchestrate service calls and automate processing JBoss SwitchYard Service and Integration Framework (SCA) lightweight framework to simplify development of service-oriented applications JBoss Overlord - DTGov Design Time Governance Lifecycle management, Release workflow & Repository Runtime Governance SLA Management Synchronous & Asynchronous Policy Enforcement Transaction & Service Monitoring Development Tooling Develop, test, debug, refine and deploy. Operational Management Performance & Availability Monitoring Alerting Inventory Management JBoss Developer Studio JBoss Operations Network Tuesday, April 22, 14 -
SwitchYard Structured development framework for integration applications Built on Apache
Camel and Java EE Using service-oriented principles to build scalable, maintainable applications Tuesday, April 22, 14 -
Integration is Complex Message Content Based Router Message Translator Content
FIlter Aggregator Messaging Gateway Message Store @WebService public class MyFancyBean { @Resource(mappedName = "jms/ConnectionFactory") private static ConnectionFactory cf; @WebMethod public void send(String msg) { } } Message Endpoint Message Endpoint Message Endpoint Tuesday, April 22, 14 -
SOA Brings Structure Message Content Based Router Message Translator Content
FIlter Aggregator Messaging Gateway Message Store @WebService public class MyFancyBean { @Resource(mappedName = "jms/ConnectionFactory") private static Message Endpoint Message Endpoint Message Endpoint Tuesday, April 22, 14 -
Recipe : Application Development • Best Practices • Let the
editor do its thing • Stick to your development style • Service partitioning • Cheat Codes • The button bar Tuesday, April 22, 14 -
Best Practice: Let the Editor Do Its Thing • Manages
application metadata so you don’t have to • It’s not evil • Suitable for beginners and experts alike Tuesday, April 22, 14 -
Best Practice: Service Partitioning • Number of services per application
• Heuristics Lifecycle Change management Distribution Reason Tuesday, April 22, 14 -
Cheat Code: The Button Bar • Context-sensitive action • Available
on all nodes • Fast • Great way to learn what’s possible Tuesday, April 22, 14 -
Recipe : Implementation Strategy • Best Practices • Right tool
for the right job • Use service abstraction to your advantage • Beans, beans the magical fruit • Cheat Codes • Fungible implementations Tuesday, April 22, 14 -
Best Practice: Right Tool for the Job CDI Bean
POJO, Java EE, easy to implement Camel Routing, pipeline orchestration, EIPs Rules Declarative, decision-oriented Tuesday, April 22, 14 -
Best Practice: Right Tool for the Job BPMN 2
Understandable to business users, stateful, long-lived BPEL Web service orchestration, existing BPEL experience Tuesday, April 22, 14 -
Best Practice: Use Service Abstraction to Your Advantage • Invoke
services by contract using a service reference • Loose coupling • Binding abstraction • Implementation hiding Tuesday, April 22, 14 -
Service Abstraction - CDI @WebService public class OrderService { @Resource(mappedName
= "jms/ConnectionFactory") private static ConnectionFactory cf; @WebMethod public void submit(String msg) { // create JMS session, lookup destination, // etc., etc. } } Tuesday, April 22, 14 -
Service Abstraction - CDI @Service(OrderService.class) public class OrderServiceBean implements OrderService
{ @Inject @Reference private InventoryService inventory; public void submit(Order order) { // check inventory level Item item = inventory.getItem(order.getItemId()); } } Tuesday, April 22, 14 -
Service Abstraction - Camel <route xmlns="http://camel.apache.org/schema/spring"> <from uri="file://tmp/inbound"/> <to uri="direct://DestinationService"/>
<choice> <when> <simple>${body.destination} == 'Red'</simple> <to uri="jms://queue:RedQueue"/> </when> <when> <simple>${body.destination} == 'Green'</simple> <to uri="vm://GreenService"/> </when> <when> <simple>${body.destination} == 'Blue'</simple> <to uri="cxf:bean:BlueWebService"/> </when> <otherwise> <log message="Unknown Destination!"/> </otherwise> </choice> </route> Tuesday, April 22, 14 -
Service Abstraction - Camel <route xmlns="http://camel.apache.org/schema/spring"> <from uri="switchyard://RoutingService"/> <to uri="switchyard://DestinationService"/>
<choice> <when> <simple>${body.destination} == 'Red'</simple> <to uri="switchyard://RedService"/> </when> <when> <simple>${body.destination} == 'Green'</simple> <to uri="switchyard://GreenService"/> </when> <when> <simple>${body.destination} == 'Blue'</simple> <to uri="switchyard://BlueService"/> </when> <otherwise> <log message="Unknown Destination!"/> </otherwise> </choice> </route> Tuesday, April 22, 14 -
Camel Beans • Invoke CDI Beans directly from Camel when
Logic is small and localized to the service implementation Access to Camel APIs or features is desirable Camel-specific configuration is required (e.g. Netty encoder) Tuesday, April 22, 14 -
Bean Services • Use Bean Services when Logic may be
exposed as a service now or in the future Access to Java EE facilities is desirable (e.g. resource injection) Bean will invoke other services (local or remote) Tuesday, April 22, 14 -
Recipe : Testing • Best Practices • Test every service
• Isolate dependencies • Test application boundaries • Cheat Codes • Test kit spelunking Tuesday, April 22, 14 -
Cheat Code: Test Kit Spelunking • SwitchYardTestKit • Invoker •
MixIns • SwitchYardTestCaseConfig Tuesday, April 22, 14 -
Recipe : Connectivity • Best Practices • Don’t couple contract
and binding • Promotion is *:1 • Cheat Codes • Extensions Tuesday, April 22, 14 -
Best Practice: Promotion is 1:* • Component services can be
promoted multiple times • Only needed when the contracts are different • Multiple bindings per composite service Tuesday, April 22, 14 -
Cheat Code: Extensions • Camel components not included directly in
SwitchYard • Fuse • Custom • Using extensions • Create module(s) • Runtime registration • Configure via Camel URI gateway Tuesday, April 22, 14 -
Recipe : Dealing with Data • Best Practices • Address
cross-cutting concerns declaratively • Leverage multi-hop transformation Tuesday, April 22, 14 -
Best Practice: Address Cross-Cutting Concerns Declaratively • Favor declarative over
procedural transformation • Procedural transformation is still legit Tuesday, April 22, 14 -
Procedural in Camel public class ExampleRoute extends RouteBuilder { public
void configure() { from("switchyard://OrderIntake") // validate against XSD .to("validator:orderSchema.xsd") .choice() .when(header("service").equals("ABC")) // data format XML -> Java .unmarshal("JAXBOrderBinding") .to("switchyard://ABCService") .otherwise() // invoke XSL transformation on content .to("xslt:formatRegion.xsl") .to("switchyard://XYZService"); } } Tuesday, April 22, 14 -
Camel with Declarative public class ExampleRoute extends RouteBuilder { public
void configure() { from("switchyard://OrderIntake") .choice() .when(header("service").equals("ABC")) .to(switchyard://ABCService") .otherwise() .to("switchyard://XYZService"); } } Tuesday, April 22, 14 -
Declarative Transformation @Transformer(from = "{urn:switchyard-example:orders:1.0}submitOrder") public Order transform(Element from) {
return new Order() .setOrderId(getElementValue(from, "orderId”)) .setItemId(getElementValue(from, "itemId”)) .setQuantity(Integer.valueOf(getElementValue(from, "quantity”))); } Tuesday, April 22, 14 -
Best Practice: Leverage Multi-Hop Transformation A B C transform1 transform2
A C Tuesday, April 22, 14 -
Recipe : Deployment & Packaging • Best Practices • JAR
deployment • WAR deployment • EAR deployment Tuesday, April 22, 14 -
Best Practice: JAR Deployment • Default and easy • No
embedded libraries • No embedded resources Tuesday, April 22, 14 -
Best Practice: WAR Deployment • Embedded libraries • Embedded resources
• Isolated class loading • Web stuff • Packaging can bite you Tuesday, April 22, 14 -
Best Practice: EAR Deployment • Multiple applications • Inter-application communication
with SCA binding • Embedded resources • Coordinated lifecycle • Assembly outside of SY tooling Tuesday, April 22, 14 -
Recipe : Debugging • Best Practices • Message Tracing •
ExchangeInterceptors • Auditing • Choosing the right tool • Cheat Codes • SwitchYard Debugger Tuesday, April 22, 14 -
Exchange Interceptors @Named("UpdateStatus") public class OrderInterceptor implements ExchangeInterceptor { @Override
public void before(String target, Exchange exchange) throws HandlerException { // do something before the invocation } @Override public void after(String target, Exchange exchange) throws HandlerException { // do something after the invocation } @Override public List<String> getTargets() { return Arrays.asList(PROVIDER); } } Tuesday, April 22, 14 -
Exchange Interceptors 1 2 3 4 1. CONSUMER.before() 2. PROVIDER.before()
3. PROVIDER.after() 4. CONSUMER.after() Tuesday, April 22, 14 -
Auditors @Audit @Named("custom auditor") public class SimpleAuditor implements Auditor {
@Override public void beforeCall( Processors processor, Exchange exchange) { } @Override public void afterCall( Processors processor, Exchange exchange) { } } Tuesday, April 22, 14 -
Choosing the Right Tool • MessageTrace Suitable for dev and
runtime Convenient Static • ExchangeInterceptor Useful for more than just debugging Customizable Requires coding Tuesday, April 22, 14 -
Choosing the Right Tool • Auditors Suitable for dev only!
Super low-level • Debugger Suitable for dev and runtime Isolation Interruption Tuesday, April 22, 14