Mule in Action
Total Page:16
File Type:pdf, Size:1020Kb
MANNING David Dossot John D’Emic FOREWORD BY ROSS MASON Mule in Action Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> Mule in Action DAVID DOSSOT JOHN D’EMIC MANNING Greenwich (74° w. long.) Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> For online information and ordering of this and other Manning books, please visit www.manning.com. The publisher offers discounts on this book when ordered in quantity. For more information, please contact Special Sales Department Manning Publications Co. Sound View Court 3B fax: (609) 877-8256 Greenwick, CT 06830 email: [email protected] ©2010 by Manning Publications Co. All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form or by means electronic, mechanical, photocopying, or otherwise, without prior written permission of the publisher. Many of the designations used by manufacturers and sellers to distinguish their products are claimed as trademarks. Where those designations appear in the book, and Manning Publications was aware of a trademark claim, the designations have been printed in initial caps or all caps. Recognizing the importance of preserving what has been written, it is Manning’s policy to have the books we publish printed on acid-free paper, and we exert our best efforts to that end. Recognizing also our responsibility to conserve the resources of our planet, Manning books are printed on paper that is at least 15 percent recycled and processed without the use of elemental chlorine. Development editor: Jeff Bleiel Copyeditor: Benjamin Berg Manning Publications Co. Proofreader: Katie Tennant Sound View Court 3B Typesetter: Dottie Marsico Greenwich, CT 06830 Cover designer: Marija Tudor ISBN 978-1-933988-96-2 Printed in the United States of America 12345678910–MAL–141312111009 Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> We dedicate this book to those who are tired of integration donkey work. Your Mule has arrived! Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> brief contents PART 1CORE MULE..................................................................1 1 ■ Discovering Mule 3 2 ■ Configuring Mule 21 3 ■ Sending and receiving data with Mule 39 4 ■ Routing data with Mule 82 5 ■ Transforming data with Mule 108 6 ■ Working with components 139 PART 2RUNNING MULE........................................................165 7 ■ Deploying Mule 167 8 ■ Exception handling and logging 196 9 ■ Securing Mule 218 10 ■ Using transactions with Mule 233 11 ■ Monitoring with Mule 251 vii Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> viii BRIEF CONTENTS PART 3TRAVELING FURTHER WITH MULE ..............................271 12 ■ Developing and testing with Mule 273 13 ■ Using the Mule API 299 14 ■ Scripting with Mule 327 15 ■ Business process management and scheduling with Mule 342 16 ■ Tuning Mule 362 Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> contents foreword xvii preface xix acknowledgments xx about this book xxi about the authors xxv PART 1CORE MULE.........................................................1 Discovering Mule 3 1 1.1 ESB, the EAI workhorse 5 1.2 The Mule project 7 History 8 ■ Competition 9 1.3 Mule’s core concepts 10 Model 10 ■ Service 11 ■ Transports 12 ■ Routers 14 Components 15 ■ Request processing 15 1.4 Mule on your machine 18 1.5 Summary 19 Configuring Mule 21 2 2.1 First ride 22 2.2 The Spring XML configuration 25 XML element families 26 ■ Configured values 29 ■ Schema locations 32 ix Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> x CONTENTS 2.3 Configuration modularity 34 Independent configurations 34 ■ Inherited configurations 35 Imported configurations 36 ■ Heterogeneous configurations 36 2.4 Summary 37 Sending and receiving data with Mule 39 3 3.1 Understanding connectors and endpoints 40 Configuring connectors 41 ■ Configuring endpoints 43 3.2 Working with files and directories using the file transport 46 Reading and writing files with file endpoints 47 ■ Using filters on inbound file endpoints 49 ■ Using STDIO endpoints 50 3.3 Using email 51 Receiving email with the IMAP transport 51 ■ Sending mail using the SMTP transport 53 3.4 Using web services 55 Consuming and exposing SOAP services with the CXF transport 55 Sending and receiving data using the HTTP transport 61 3.5 Using the JMS transport for asynchronous messaging 64 Sending JMS messages with the JMS outbound endpoint 65 Receiving JMS messages with the JMS inbound endpoint 67 Using selector filters on JMS endpoints 68 ■ Using JMS synchronously 68 3.6 Receiving and sending files using the FTP transport 70 Receiving files with inbound FTP endpoints 71 ■ Sending files with outbound FTP endpoints 72 3.7 Working with databases 72 Using a JDBC inbound endpoint to perform queries 73 ■ Using a JDBC outbound endpoint to perform insertions 75 3.8 Using the XMPP transport 76 Sending Jabber messages on an outbound endpoint 77 ■ Receiving Jabber messages on an inbound endpoint 77 3.9 The VM transport 78 Sending and receiving messages on VM endpoints 79 ■ Using persistent queues on VM endpoints 80 3.10 Summary 81 Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> CONTENTS xi Routing data with Mule 82 4 4.1 Working with routers 83 Inbound routers 84 ■ Outbound routers 85 4.2 Using filters with routers 86 Filtering by type 86 ■ Filtering by textual content 87 ■ Filtering with expressions 87 ■ Logical filtering 89 4.3 Using inbound routers 89 Being picky with the selective-consumer router 90 ■ Altering message flow with the forwarding-consumer router 91 ■ Collecting data with the collection aggregator 92 ■ Insuring atomic delivery with the idempotent receiver 94 ■ Snooping messages with the wiretap router 96 4.4 Outbound routing 97 Being picky with the filtering router 97 ■ Sending to multiple endpoints with the static recipient list 98 ■ Broadcasting messages with the multicasting router 99 ■ Service composition with the chaining router 100 ■ Chopping up messages with the message splitter 102 ■ Using asynchronous-reply routers 104 4.5 Summary 107 Transforming data with Mule 108 5 5.1 Working with transformers 109 5.2 Configuring transformers 111 5.3 Using core transformers 114 Dealing with bytes 115 ■ Compressing data 117 ■ Modifying properties 118 ■ Leveraging expression evaluators 120 5.4 Using XML transformers 122 Transforming format with XSL 122 ■ XML object marshalling 124 5.5 Using JMS transformers 125 Producing JMS messages 125 ■ Consuming JMS messages 126 5.6 Existing transformers in action 127 5.7 Writing custom transformers 131 Transforming payloads 131 ■ Transforming messages 134 5.8 Summary 138 Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> xii CONTENTS Working with components 139 6 6.1 Massaging messages 142 Building bridges 142 ■ Echoing and logging data 144 Building messages 145 6.2 Invoking remote logic 147 Feeling good with SOAP 148 ■ Taking some REST 149 6.3 Executing business logic 151 Resolving the entry point 152 ■ Configuring the component 156 Handling workload with a pool 158 ■ Reaching out with composition 160 ■ Internal canonical data model 162 6.4 Summary 163 PART 2RUNNING MULE...............................................165 Deploying Mule 167 7 7.1 Deployment strategies 168 Standalone server 169 ■ NetBoot server 171 ■ Embedded in a Java application 172 ■ Embedded in a web application 174 Embedded as a JCA resource 177 7.2 Deployment topologies 178 Satisfying functional needs 179 ■ Dealing with the network 181 Designing for high availability 184 ■ Shooting for fault tolerance 187 7.3 Deployment management 189 Using development tools 190 ■ Hitchhiking Galaxy 192 7.4 Summary 195 Exception handling and logging 196 8 8.1 Exception strategies 197 Positioning exception strategies 197 ■ Exceptions and routing 202 8.2 Using retry policies 207 Implementing a retry policy 207 ■ Using the SimpleRetryPolicy with JMS 209 ■ Starting Mule with failed connectors using the Common Retry Policies 210 Download at Boykma.Com Licensed to Deborah Christiansen <[email protected]> CONTENTS xiii 8.3 Logging with Mule 212 Using log4j with Mule 212 ■ Using Apache Chainsaw with log4j 213 8.4 Summary 217 Securing Mule 218 9 9.1 Demonstrating Mule security 219 9.2 Using security managers and understanding security providers 220 Using Spring Security 221 ■ Using JAAS 224 9.3 Securing endpoints with security filters 225 Securing an HTTP endpoint with Spring Security 225 Performing JMS header authentication with JAAS 226 Using password-based payload encryption 228 ■ Decrypting message payloads with the PGP SecurityFilter 230 9.4 Summary 232 Using transactions with Mule 233 10 10.1 Using transactions with a single resource 235 Using JDBC endpoints transactionally 235 ■ Using JMS endpoints transactionally 237 10.2 Using multiple resource transactions 242 Spanning multiple resources with JBossTS 243 ■ Using XA transactions in a container 246 10.3 Managing transactions with exception strategies 247 Handling component exceptions 248 ■ Committing transactions with an exception strategy 249 10.4 Summary 250 Monitoring with Mule 251 11 11.1 Checking health 252 Checking health at network level 253 ■ Checking health at system and JVM levels 254 ■ Checking health at JVM