Slide 1

Slide 1 text

Red Hat JBoss Fuse Service Works Integration Recipes, Best Practices & Cheat Codes Keith Babo SwitchYard Project Lead, Red Hat Tuesday, April 22, 14

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Format 10 OVERVIEW 20 RECIPE 30 BEST PRACTICE 40 CHEAT CODE 50 GOTO 20 Tuesday, April 22, 14

Slide 5

Slide 5 text

Recipes • Application Development • Implementation strategy • Testing • Connectivity • Dealing with data • Deployment & Packaging • Debugging Tuesday, April 22, 14

Slide 6

Slide 6 text

First a bit of background ... Tuesday, April 22, 14

Slide 7

Slide 7 text

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

Slide 8

Slide 8 text

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

Slide 9

Slide 9 text

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

Slide 10

Slide 10 text

SOA Brings Structure Tuesday, April 22, 14

Slide 11

Slide 11 text

Structured Development Tuesday, April 22, 14

Slide 12

Slide 12 text

Structured Development Tuesday, April 22, 14

Slide 13

Slide 13 text

Structured Development Tuesday, April 22, 14

Slide 14

Slide 14 text

Structured Development Tuesday, April 22, 14

Slide 15

Slide 15 text

Structured Development Tuesday, April 22, 14

Slide 16

Slide 16 text

Structured Development Tuesday, April 22, 14

Slide 17

Slide 17 text

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

Slide 18

Slide 18 text

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

Slide 19

Slide 19 text

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

Slide 20

Slide 20 text

SwitchYard Metadata Tuesday, April 22, 14

Slide 21

Slide 21 text

Maven Metadata Tuesday, April 22, 14

Slide 22

Slide 22 text

Best Practice: Stick To Your Development Style Top-down Tuesday, April 22, 14

Slide 23

Slide 23 text

Best Practice: Stick To Your Development Style Bottom-up Tuesday, April 22, 14

Slide 24

Slide 24 text

Best Practice: Stick To Your Development Style Meet-in-the-middle Tuesday, April 22, 14

Slide 25

Slide 25 text

Best Practice: Service Partitioning • Number of services per application • Heuristics Lifecycle Change management Distribution Reason Tuesday, April 22, 14

Slide 26

Slide 26 text

Cheat Code: The Button Bar • Context-sensitive action • Available on all nodes • Fast • Great way to learn what’s possible Tuesday, April 22, 14

Slide 27

Slide 27 text

DEMO Tuesday, April 22, 14

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

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

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

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

Slide 32

Slide 32 text

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

Slide 33

Slide 33 text

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

Slide 34

Slide 34 text

Service Abstraction - Camel ${body.destination} == 'Red' ${body.destination} == 'Green' ${body.destination} == 'Blue' Tuesday, April 22, 14

Slide 35

Slide 35 text

Service Abstraction - Camel ${body.destination} == 'Red' ${body.destination} == 'Green' ${body.destination} == 'Blue' Tuesday, April 22, 14

Slide 36

Slide 36 text

Local Reference Tuesday, April 22, 14

Slide 37

Slide 37 text

Remote Reference Tuesday, April 22, 14

Slide 38

Slide 38 text

Best Practice: Beans, Beans the Magical Fruit vs. Tuesday, April 22, 14

Slide 39

Slide 39 text

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

Slide 40

Slide 40 text

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

Slide 41

Slide 41 text

Cheat Code: Fungible Implementations Tuesday, April 22, 14

Slide 42

Slide 42 text

Cheat Code: Fungible Implementations Tuesday, April 22, 14

Slide 43

Slide 43 text

Cheat Code: Fungible Implementations Tuesday, April 22, 14

Slide 44

Slide 44 text

Cheat Code: Fungible Implementations Tuesday, April 22, 14

Slide 45

Slide 45 text

DEMO Tuesday, April 22, 14

Slide 46

Slide 46 text

Recipe : Testing • Best Practices • Test every service • Isolate dependencies • Test application boundaries • Cheat Codes • Test kit spelunking Tuesday, April 22, 14

Slide 47

Slide 47 text

Best Practice: Test Every Service Tuesday, April 22, 14

Slide 48

Slide 48 text

Best Practice: Isolate Dependencies Tuesday, April 22, 14

Slide 49

Slide 49 text

Best Practice: Test Application Boundaries Tuesday, April 22, 14

Slide 50

Slide 50 text

Cheat Code: Test Kit Spelunking • SwitchYardTestKit • Invoker • MixIns • SwitchYardTestCaseConfig Tuesday, April 22, 14

Slide 51

Slide 51 text

Recipe : Connectivity • Best Practices • Don’t couple contract and binding • Promotion is *:1 • Cheat Codes • Extensions Tuesday, April 22, 14

Slide 52

Slide 52 text

Best Practice: Don’t Couple Contract and Binding Tuesday, April 22, 14

Slide 53

Slide 53 text

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

Slide 54

Slide 54 text

Cheat Code: Extensions Tuesday, April 22, 14

Slide 55

Slide 55 text

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

Slide 56

Slide 56 text

Creating Modules • mvn dependency:tree • module.xml • jboss-eap-6.1/modules Tuesday, April 22, 14

Slide 57

Slide 57 text

Runtime Registration jboss-eap-6.1/standalone/configuration/standalone.xml Tuesday, April 22, 14

Slide 58

Slide 58 text

Camel URI Binding Tuesday, April 22, 14

Slide 59

Slide 59 text

DEMO Tuesday, April 22, 14

Slide 60

Slide 60 text

Recipe : Dealing with Data • Best Practices • Address cross-cutting concerns declaratively • Leverage multi-hop transformation Tuesday, April 22, 14

Slide 61

Slide 61 text

Best Practice: Address Cross-Cutting Concerns Declaratively • Favor declarative over procedural transformation • Procedural transformation is still legit Tuesday, April 22, 14

Slide 62

Slide 62 text

Procedural Tuesday, April 22, 14

Slide 63

Slide 63 text

Procedural in BPM Tuesday, April 22, 14

Slide 64

Slide 64 text

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

Slide 65

Slide 65 text

Declarative Tuesday, April 22, 14

Slide 66

Slide 66 text

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

Slide 67

Slide 67 text

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

Slide 68

Slide 68 text

Declarative Validation Tuesday, April 22, 14

Slide 69

Slide 69 text

Hybrid Tuesday, April 22, 14

Slide 70

Slide 70 text

Best Practice: Leverage Multi-Hop Transformation A B C transform1 transform2 A C Tuesday, April 22, 14

Slide 71

Slide 71 text

Recipe : Deployment & Packaging • Best Practices • JAR deployment • WAR deployment • EAR deployment Tuesday, April 22, 14

Slide 72

Slide 72 text

Best Practice: JAR Deployment • Default and easy • No embedded libraries • No embedded resources Tuesday, April 22, 14

Slide 73

Slide 73 text

Best Practice: WAR Deployment • Embedded libraries • Embedded resources • Isolated class loading • Web stuff • Packaging can bite you Tuesday, April 22, 14

Slide 74

Slide 74 text

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

Slide 75

Slide 75 text

Recipe : Debugging • Best Practices • Message Tracing • ExchangeInterceptors • Auditing • Choosing the right tool • Cheat Codes • SwitchYard Debugger Tuesday, April 22, 14

Slide 76

Slide 76 text

Message Tracing Tuesday, April 22, 14

Slide 77

Slide 77 text

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 getTargets() { return Arrays.asList(PROVIDER); } } Tuesday, April 22, 14

Slide 78

Slide 78 text

Exchange Interceptors 1 2 3 4 1. CONSUMER.before() 2. PROVIDER.before() 3. PROVIDER.after() 4. CONSUMER.after() Tuesday, April 22, 14

Slide 79

Slide 79 text

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

Slide 80

Slide 80 text

Debugger Tuesday, April 22, 14

Slide 81

Slide 81 text

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

Slide 82

Slide 82 text

Choosing the Right Tool • Auditors Suitable for dev only! Super low-level • Debugger Suitable for dev and runtime Isolation Interruption Tuesday, April 22, 14

Slide 83

Slide 83 text

DEMO Tuesday, April 22, 14

Slide 84

Slide 84 text

Questions? Tuesday, April 22, 14