Rc140 Update Mule3.3 0

download Rc140 Update Mule3.3 0

of 7

Transcript of Rc140 Update Mule3.3 0

  • 7/29/2019 Rc140 Update Mule3.3 0

    1/7

    DZone, Inc. | www.dzone.com

    By Mike Keith

    G

    e

    ngSaredw

    h

    PA 2.0

    GetMoreRefcardzVs

    refcardz.com

    7

    CONTENTS INCLUDE:n Whats New in JPA 2.0n JDBC Propertiesn Access Moden Mappingsn Shared Cachen Additional API and more...

    Getting Started with JPA 2.0

    http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://www.refcardz.com/http://www.dzone.com/http://www.refcardz.com/
  • 7/29/2019 Rc140 Update Mule3.3 0

    2/7

    DZone, Inc. | www.dzone.com

    GetMoreRefcardz!Visitrefcardz.com

    40

    EssentaMue3.3

    By John D'Em

    ABOUT MULE

    Mule is the worlds most widely used open source integration platformand Enterprise Services Bus (ESB). Inspired by the seminal EnterpriseIntegration Patterns , Mule is designed to support high-performance, multi-protocol transactions between heterogeneous systems and services. Itprovides the basis for service-oriented architecture.

    This Refcard covers the use of Mule 3.3. For new users it will serve as ahandy reference when building your integration flows in Mule. For existingusers of Mule, especially users of previous versions of Mule 3, it willhighlight the new features available in Mule 3.3.

    WHAT'S NEW IN MULE 3.3?

    Graphical data transformation with DataMapper

    Mule Expression Language, an MVEL based, uni ed expressionlanguage

    Pattern-based exception handling

    Simpli ed iteration over data structures in message payloads

    BUILDING INTEGRATION APPLICATIONS WITH MULE

    Mule 3.3 provides a powerful, Eclipse-based authoring environment for

    developing integration applications.

    Mule studio allows you to round-trip between the graphical view of yourapplication and the corresponding con guration XML.

    A: The Message Processor pallet displays the available MessageProcessors for you to use in your flows. They are grouped by function. Youcan use the lter at the top of the pallet to search for message processorsby name.

    B: Mule integration flows are built by dragging message processors fromthe pallet view to the flow view. You can switch between the Message Flowand the Con guration XML at the bottom of this pane.. In this area you canalso see Global Elements, like JMS connector con gurations.

    C: These tabs display various status about your Mule project,including any errors, the embedded Mule instances console log, accessto Javadoc and JUnit test results. Its also the place where you cande ne and edit your transformations for DataMapper.

    D: This pane displays the Mule projects directory structure, including theXML con guration les and any Java classes required by your application.

    E: You can run and debug your application from here.

    FlowsFlows provide a free-form method of orchestrating message processing inMule. A flow consists of a message source, typically an inbound-endpoint,followed by a sequence of message processors. Message processors, like

    lters, transformers, or Java components, process a message as it passesthrough the flow.

    An exception strategy can be added to a flow to handle errors that occurduring the flows execution.

    CONTENTS INCLUDE:n Building Integration Applicationsn Messagesn Connectivityn Modulesn Message Processorsn

    and More!

    Essential Mule 3.3Simplifying SO

    HotTip

    End a ow with a router or endpoint to send the message to anoow or external service.

    Brought to you by

    Updated forMule 3.3!

    http://www.dzone.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/http://www.eaipatterns.com/http://www.eaipatterns.com/http://www.eaipatterns.com/http://answerhub.com/http://answerhub.com/http://answerhub.com/http://www.eaipatterns.com/http://www.eaipatterns.com/http://www.refcardz.com/http://www.dzone.com/http://www.refcardz.com/http://www.refcardz.com/
  • 7/29/2019 Rc140 Update Mule3.3 0

    3/7

    2 Essential Mule 3.3

    DZone, Inc. | www.dzone.com

    Sending a JMS Message with a FlowSending a JMS message is easy with a flow. Heres how you can use a flowto read les from a directory and send their payload to a JMS queue.

    < ow name=FileToJMS doc:name=FileToJMS>< le:inbound-endpoint path=/opt/ les/in

    responseTimeout=10000 doc:name=File/>

    This flow uses a le inbound-endpoint to read les from the speci eddirectory path. Each le is then converted to a string by the byte-array-to-string-transformer. The string is then used as the payload of the JMSmessage to the les queue by the JMS outbound-endpoint.

    Transforming Payloads with DataMapperMule 3.3s DataMapper functionality allows you to easily transformmessages from one format to another. To use DataMapper, select theDataMapper message processor from the pallet and drag it onto yourflow. Then select the DataMapper and launch the DataMapper FlowWizard to de ne your transformation.

    Transforming CSV to XMLTransforming from CSV to XML is simple with DataMapper. After launchingthe DataMapper Flow Wizard the Input Type is set to CSV and the OutputType is set to XML. The CSV Example and XML Schema specify the formatof the input and output to the DataMapper.

    In addition to XML and CSV, DataMapper also supports POJO, JSON, Mapsand Excel spreadsheets.

    MESSAGES

    Messages encapsulate data entering and leaving Mule. The content of amessage is called its payload. The payload is typically a Serializable Javaclass, an InputStream or an array of bytes.

    AttachmentsA message can have zero or more MIME attachments in addition to thepayload. These can be used to associate les, documents and images withthe message.

    PropertiesProperties, also called headers, are metadata associated with a message.Mule, the various transports, and you, the developer, can add properties tomessages. Examples of message properties are JMS message headers,HTTP response headers, or Mule-speci c headers like MULE_MESSAGE_ID.The following table contains examples of message properties set by Mule.

    Property DescriptionMULE_MESSAGE_ID A GUID assigned to the message.

    MULE_CORRELATION_ID A GUID assigned to a group of messages.

    MULE_CORRELATION_GROUP_SIZE The amount of messages expectedin the correlation group.

    MULE_CORRELATION_SEQUENCE The order of a correlation group.

    MULE_SESSION A GUID indicating the session themessage belongs to

    ScopesProperties are scoped differently depending on when theyre set oraccessed during message processing. The following table contains theavailable scopes.

    Scope Descriptioninbound Set by message sources, typically an inbound-endpoint.

    outbound Set on messages leaving a message processor.Properties set by the message-properties-transformerdefault to the outbound scope.

    session Properties in the session scope are available betweenprocessors and services without explicit propagation.

    invocation nvocation properties, or flow variables, contain data thatis accessible to a message as it passes through a flow.

    HotTip

    Message properties leaving a processor on the outbound scope areavailable in the inbound scope on the subsequent processor.

    HotTip

    The felds rom the source ormat can be clicked on and dragged tothe output ormat.

    http://www.dzone.com/http://answerhub.com/http://www.dzone.com/http://www.refcardz.com/http://www.refcardz.com/
  • 7/29/2019 Rc140 Update Mule3.3 0

    4/7

    3 Essential Mule 3.3

    DZone, Inc. | www.dzone.com

    CONNECTIVITY

    Mule connects to more than 100 applications, protocols and APIs . Muleendpoints enable connectivity to protocols, such as JMS, HTTP and JDBC.Cloud Connectors enable connectivity to applications and social media likeSalesForce and Twitter.

    EndpointsMessages can be received with an inbound endpoint and sent with anoutbound endpoint.

    ConnectorsA connector is used to con gure connection properties for an endpoint.Most endpoints dont require a connector, but some like JDBC or JMS, dorequire connector con guration, as well see next.

    Configuring an SMTP connectorThe following example illustrates how an SMTP connector is con gured inMule Studio as well as in XML.

    The SMTP connector allows you to specify properties that will be sharedacross SMTP endpoints. In this case, the connector sets the Content-Typeand from address as well as the subject of the messages. A connector isreferenced by its name, allowing you to de ne multiple connectors for thesame transport.

    The following table contains some common endpoints supplied by Mule.Endpoint Description

    HTTP http:// [host]:[port] :[path]?[query] Send and receive dataover HTTP.

    AJAX ajax://[channel] Pub / Sub to browserapps using CometD.

    File File://[path] Read and write files.

    S/FTP ftp:// [user]@[host]:[port]/[path] Read and write files overFTP or SFTP.

    JMS jms:// [ type]:[destination]?[options] Full support for JMStopics and queues.

    SMTP smtp://[user]@[host]:[port] Send email over SMTP.

    IMAP Imap:// [user]@[host]:[port]/[folder] Receive email via IMAP

    Endpoint DescriptionJDBC jdbc://[sql query] Send and receive data

    from a SQL database.

    VM vm://[path] Uses memory-basedqueues to sendmessages betweenservices and flows.

    The full list of transports is available in the Mule documentation.

    Cloud ConnectorsIntroduced in Mule 3, cloud connectors enable easy access to SaaS, socialmedia and infrastructure services, such as Twilio and Facebook.Cloud Connectors can be used anywhere in a flow to invoke a remoteservice. A cloud connector usually has a con g element where servicecredentials are set and one or more elements that invoke a service method.The following will make it possible to publish a tweet using curl: http://localhost?status=gomule!

    < ow name=updateStatus doc:name=updateStatus>

    PollingMule has a poll tag that allows data from a remote service of a CloudConnector to be received periodically. To get updates from a Twittertimeline every minute:

    < ow name=pollTwitter doc:name=pollTwitter>

    MODULES

    Modules extend Mules functionality by providing namespace support fora certain set of message processors. The following table contains some of the modules provided by Mule.

    HotTip

    Endpoints can be generically re erenced using an endpoint URI.

    HotTip

    Use exchange patterns to defne how a message is received by anendpoint. For endpoints that generate a response (synchronous),use the request-response. For asynchronous endpoints, use theone-way exchange pattern.

    http://www.dzone.com/http://localhost/?status=gomule!http://localhost/?status=gomule!http://answerhub.com/http://localhost/?status=gomule!http://localhost/?status=gomule!http://www.dzone.com/http://www.refcardz.com/http://www.refcardz.com/
  • 7/29/2019 Rc140 Update Mule3.3 0

    5/7

    4 Essential Mule 3.3

    DZone, Inc. | www.dzone.com

    Module DescriptionJSON JSON support, including marshalling,

    transformation and filtering.

    CXF SOAP support via Apache CXF.

    Jersey JAX-RS support for publishing RESTfulservices.

    Scripting Support for JSR-223 compliant scriptinglanguage, like Groovy or Rhino.

    XML XML support, including XML marshalling,XPath and XSLT support.

    The full list of available modules is in the of cial Mule documentation.Additional modules are available on MuleForge.

    Hosting a JAX-RS Web ServiceThe following demonstrates how the Jersey module can be used to host aJAX-RS annotation service classusing Mule.

    < ow name=JAXRSService doc:name=JAXRSService>

    MESSAGE PROCESSORS

    Message Processors are used in flows to route, transform, lter andperform business logic on messages.

    Flow ControlFlow Control Message Processors, or routers, implement the popularEnterprise Integration patterns (EIP) and determine how messages aredirected in a flow.

    The following table contains commonly used routers.

    Router Descriptionall JSON support, including marshalling,

    transformation and filtering.

    choice Send the message to the first endpoint thatmatches.

    round-robin Each message received by the router is sentto alternating endpoints.

    wire-tap Sends a copy of the message to the suppliedendpoint, then passes the original message tothe next processor in the chain.

    Router Descriptionfirst-successful Sends the message to the first endpoint that

    doesnt throw an exception or evaluates thefailureExpression to true.

    until- successful Redelivers a message until its successfullydelivered or gives up after a certain amountof attempts.

    foreach Iterates over a collection in the payload of a

    message.

    The following flow demonstrates how the Foreach processor can iterateover a collection present in a message payload. This flow accepts a Listof LineItem objects and sends each to an outbound HTTP endpoint forprocessing.

    < ow name=LineItemProcessing doc:name=LineItemProcessing>

    TransformersTransformers modify the message and pass it to the next message in thechain. The following table contains commonly used transformers.

    Name Descriptionmessage-properties-transformer

    Add and remove properties from a message,optionally specifying their scope whendifferent from the default outbound scope.

    byte-array-to-string-transformer

    Transforms a byte array to a String.

    byte-array-to-object-transformer Transforms a byte array to an Object.

    xml:object-to-xml Using XStream, this transforms messagepayloads to and from XML.

    xml:xslt-transformer Transforms a message using the givenstylesheet.

    json:object-to-json-transformer

    Using Jackson, this transforms messagepayloads to and from JSON.

    ComponentsComponents allow business logic to be executed in a flow. Any Java objector script can be used as a component. Components are con gured byeither identifying the class or providing a reference to a Spring bean fordependency injection.

    The following snippet shows how a class called MyService can becon gured as a component using a class and via dependency injection viaSpring.

    < ow name=test>

    HotTip

    Endpoints o ten include their own trans ormers. JMS, or instance,provides trans ormers to convert message payloads to and romJMS messages automatically.

    HotTip

    Use MuleForge to locate community written extensions.

    http://www.dzone.com/http://answerhub.com/http://www.dzone.com/http://www.refcardz.com/http://www.refcardz.com/http://www.refcardz.com/
  • 7/29/2019 Rc140 Update Mule3.3 0

    6/7

    5 Essential Mule 3.3

    DZone, Inc. | www.dzone.com

    Mule will use the type of payload that is in the message being processedto determine what method to invoke. Its often necessary, however, toexplicitly specify the method to invoke. Entry point resolvers are used forthis purpose. The following table contains a list of available resolvers.

    Resolver Descriptionmethod-entry-point-resolver

    Resolves the method using the specified name.

    property-entry-

    point-resolver

    Resolves the method using the specified message

    property.custom-entry-point-resolver

    A Java class that implements org.mule.api.model.EntryPointResolver or extends org.mule.model.resolvers.AbstractEntryPointResolver.

    The use of entry point resolvers allows you to use POJOs as components,decoupling your code from Mule.

    Sometimes, though, you will need to operate on more then just amessages payload. Mules annotations give your components runtimeaccess to a MuleMessage without coupling your component code atcompile time to Mules API. The following table contains a list of commonlyused annotations.

    Name Type Description@Payload Parameter Can be specified on the

    component entry point and

    transformer method parametersto show the parameter thatindicates the message payload.

    @InboundHeaders Parameter Specifies the component-entry-point or transformer-methodparameter that the inboundheaders should be mapped to.

    @OutboundHeaders Parameter Specifies the component-entry-point or transformer-methodparameter that the outboundheaders should be mapped to.

    @InboundAttachments Parameter Specifies the component-entry-point or transformer-methodparameter that the inboundattachments should be mappedto.

    @OutboundAttachments Parameter Specifies the component-entry-point or transformer-methodparameter thatthe outboundattachments should be mappedto.

    Implementing a Component with AnnotationsHeres an example of a component that accesses the messages payloadand an inbound header with annotations:

    public class LineItemService {public void process(@Payload Object lineItem,

    @InboundHeaders(LINE_ITEM_PRIORITY)String priority) {

    // perform processing}

    }

    MULE EXPRESSION LANGUAGE

    Mule provides a rich expression language based on MVEL to evaluate dataat runtime using the message currently being processed.

    Context ObjectsThe following are commonly used variables on context objects available inMEL expressions.

    Name Descriptionmessage The MuleMessage that gives you access to the payload,

    the i.d., and the various properties.

    flowVars The flow variables, or invocation properties, available onthe flow.

    Name DescriptionsessionVars The session variables, or session properties, available on

    the flow.

    server Information about the server Mule is running on,including its FQDN.

    mule Information about the current Mule instance, includingits home.

    app Information about the currently running Mule application,including its name.

    Here are some examples of Mule Expressions

    Name Descriptionmessage.inboundProperties['filename'].endsWith('.jpg')

    Check if the inbound propertyfilename ends with jpg.

    Embed an expression in aloggers message.

    xpath('/order/@type) == 'book' Evaluate an XPathexpression.

    regex('^(To|From|Cc):') Evaluate a regularexpression.

    Content Based Routing and FilteringThe Mule Expression Language enables Mule to perform content-basedrouting and ltering.

    The following illustrates how a message is dynamically routed to aJMS queue by using MEL to evaluate a regular expression against themessages payload.

    < ow name=ContentBasedRouting doc:name=ContentBasedRouting>

    Using Filters with XPathThe following example demonstrates how the expression lter can beused to only pass certain XML documents. In this case, only ordered XMLdocuments containing a certain ZIP code are allowed to pass.

    http://www.dzone.com/http://answerhub.com/http://www.dzone.com/http://www.refcardz.com/http://www.refcardz.com/
  • 7/29/2019 Rc140 Update Mule3.3 0

    7/7

    Browse our collection of over 150 Free Cheat SheetsUpcoming Refcardz

    Free PDF

    6 Essential Mule 3.3

    DZone, Inc.150 Preston Executive Dr.Suite 201Cary, NC 27513

    888.678.0399919.678.0300

    Refcardz Feedback Welcome

    [email protected]

    Sponsorship Opportunities

    [email protected]

    Copyright 2012 DZone, Inc. 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 priorwritten permission of the publisher. Version 1.0

    DZone communities deliver over 6 million pages each month tomore than 3.3 million software developers, architects and decisionmakers. DZone offers something for everyone, including news,tutorials, cheat sheets, blogs, feature articles, source code and more."DZone is a developer's dream" ,says PC Magazine.

    RECOMMENDED BOOK

    < ow name=XPathFiltering doc:name=XPathFiltering>

    HANDLING ERRORS

    Exceptions thrown during message processing are handled by exceptionstrategies. Exception handling has been revamped for Mule 3.3. Theavailable exception strategies are enumerated below.

    default-exception-strategy

    The default exception strategy used by allflows when an explicit exception strategy isn'tdefined.

    catch-exception-strategy Selectively handles exceptions based on type.

    choice-exception-strategy

    Selectively handles exceptions based on anMEL evaluation.

    reference-exception-strategy

    References an externally defined globalexception strategy.

    rollback-exception-strategy Attempts to roll back a message when anexception is thrown.

    Catching an ExceptionThe following example will catch exceptions of the com.acmesoft.LineItemException type and will route them to a JMS queue.

    < ow name=XPathFiltering doc:name=XPathFiltering>

    CONCLUSION

    This RefCard is just a glimpse at the capabilities of Mule 3.3. The completedocumentation for Mule 3.3 is available in the Mule User Guide.

    John DEmic is a software developer and author.He is the co-author of both editions of Mule inAction and is currently a Solutions Architect atMuleSoft, Inc. You can see what Johns up to byfollowing his Twitter account: @johndemic

    Mule in Action, Second Edition is a totally-revised guidecovering Mule 3 fundamentals and best practices. Its tarts with a quick ESB overview and then dives into richexamples covering core concepts like sending, receiving,routing, and transforming data. Youll get a close lookat Mules standard components and how to roll outcustom ones. Youll also pick up techniques for testing,performance tuning, BPM orchestration, and explore cloudAPI integration for SaaS applications.

    ABOUT THE AUTHORS

    Scala CollectionsJavaFX 2.0AndroidData Warehousing

    HotTip

    Exceptions routed by an exception strategy are instances o org.mule.api.message.ExceptionMessage, which gives you access tothe Exception that was thrown with the payload o the message.

    http://www.dzone.com/mailto:[email protected]:[email protected]://www.mulesoft.org/documentation/login.action?os_destination=%2Fdisplay%2FMULE3USER%2FHomehttp://twitter.com/johndemichttp://www.manning.com/dossot2/http://www.manning.com/dossot2/http://www.manning.com/dossot2/http://www.manning.com/dossot2/http://www.manning.com/dossot2/http://www.manning.com/dossot2/http://www.manning.com/dossot2/http://www.manning.com/dossot2/http://answerhub.com/http://www.manning.com/dossot2/http://twitter.com/johndemichttp://www.mulesoft.org/documentation/login.action?os_destination=%2Fdisplay%2FMULE3USER%2FHomehttp://sematext.com/spm/hbase-performance-monitoringmailto:[email protected]:[email protected]://www.dzone.com/http://www.dzone.com/http://www.refcardz.com/http://www.refcardz.com/