Monday 1 October 2018

Scatter-Gather behavior.



sends the same message to multiple message processors or multiple end points.
The routing message processor Scatter-Gather sends a request message to multiple targets concurrently. It collects the responses from all routes, and aggregates them into a single message, All payloads are combined to gather.

This follow Aggregator strategy && Multicast pattern





The Scatter-Gather router sends a message for concurrent processing to all configured routes. The thread executing the flow that owns the router waits until all routes complete or time out.
If there are no failures, Mule aggregates the results from each of the routes into a message collection (MessageCollection class). Failure in one route does not stop the Scatter-Gather from sending messages to its other configured routes, so it is possible that many, or all routes may fail concurrently.
By default, if any route fails, Scatter-Gather performs the following actions:
·         sets the exception payload accordingly for each route
·         throws a CompositeRoutingException, which maps each exception to its corresponding route using a sequential route ID.
By default, if any route fails, Scatter-Gather performs the following actions: sets the exception payload accordingly for each route throws a CompositeRoutingException, which maps each exception to its corresponding route using a sequential route ID Catching the CompositeRoutingException allows you to gather information on all failed routes.

MEL on Payloads

[!(payload is org.mule.transport.NullPayload)] For null check.     
#[payload != null && ((payload instanceof org.mule.transport.NullPayload) == false)]
This NullPayLoad class returning always false even payload is null.

 



Mule Object Stores


An object store is a facility for storing objects in Mule. Mule uses object stores whenever it needs data to persist for later retrieval. Internally, Mule uses object stores in various filters, routers, and other message processors that need to store state between messages. In most cases, Mule creates and manages object stores automatically, so no user configuration is necessary.

Use Cases

In most cases, Mule creates and manages object stores for you, so no configuration is necessary. However, you may explicitly configure an object store in the following cases:
·         When configuring an idempotent message filter or until a successful scope occurs.
·         When configuring a custom component that must use an object store to persist information.
·         When storing or retrieving information from a Mule flow through the Object Store module, available as an extension.
Mule provides two types of object stores:
·         In-memory store – Prior to Mule 3.5.0, in-memory store was the default. As of Mule 3.5.0, persistent store is the default. For more information, see "Object Stores and Clustering" in the Cache Scope document.
·         Persistent store – Mule persists data when an object store is explicitly configured to be persistent. Mule creates a default persistent store in the file system.

Adding Object Store Components

1.     Install the Object Store component available in Anypoint Exchange

This starts an installation Wizard. Select "ObjectStore Connector (Mule 3.6+)", click "Next", then "Next" again. Accept the terms of the license agreement and click "Finish".

Operation
Description
All keys
Returns a list of all the keys in the object store.
Contains
Checks whether the object store contains the given key.
Dual store
Stores a value using key, and also store key using value.
Remove
Remove the object for the respective key.
Retrieve
Retrieve an object from the object store and make it available in the specified property scope of a Mule Message.
Retrieve store
Retrieve and Store in the same operation.
Retrieve with lock
Retrieve the given object with lock from the object store and make it available in the specified property scope of a Mule Message.
Store
Stores an object in the object store.


 

Cloudhub: In application data we can see object store in bellow.


Tuesday 4 July 2017

Mule esb custom connector (Anypointstudio-devkit)

Hi Guys, today i am going to discuss how to create a custom connector in mule esb.

MuleSoft Anypoint DevKit:
              The MuleSoft Anypoint DevKit, or simply DevKit, enables the development of MuleSoft Anypoint Connectors.
To develop the custom connector we have to setup following things.
          1. java - java 6 or 7 required to compile and build the Java code.
          2. Maven. - for managing connector build.
          3. Anypoint DevKit - Plugin in Anypoint DevKit Update Site -                                http://studio.mulesoft.org/r5/devkit.

Maven setup:

Maven Tools for Mule ESB is a plugin for Maven that allows you to develop Mule applications using Maven tooling. The kit provided by the plugin includes archetypes for building regular Mule applications, Mule domains and Mule domain bundles.

       Setup MAVEN_HOME:


       Update PATH variable.

Open setting.xml in apache-maven-3.2.5\conf folder and check bellow.


Add pluginGroup in pluginGroups section.

Specifies a further group identifier to use for plugin lookup. Now maven look for maven repository for all dependent jars. 


Adding the Maven Dependency for the Plugin.

you need to add some entries in your settings.xml file, as shown below.
Add the following to the profiles activeProfiles section:
<profile>

    <id>Mule</id>
    <activation>
        <activeByDefault>true</activeByDefault>
    </activation>
    <repositories>
        <repository>
            <id>MuleRepository</id>
            <name>MuleRepository</name>
            <url>https://repository.mulesoft.org/nexus-ee/content/repositories/releases-ee/</url>
            <layout>default</layout>
            <releases>
                <enabled>true</enabled>
            </releases>
            <snapshots>
                <enabled>true</enabled>
            </snapshots>
        </repository>
    </repositories>

  </profile>
  <profile>
        <id>mule-extra-repos</id>
        <activation>
            <activeByDefault>true</activeByDefault>
        </activation>
        <repositories>
            <repository>
                <id>mule-public</id>
                <url> https://repository.mulesoft.org/nexus/content/repositories/public </url>
            </repository>
        </repositories>
        <pluginRepositories>
            <pluginRepository>
                <id>mule-public</id>
                <url> https://repository.mulesoft.org/nexus/content/repositories/public </url>
            </pluginRepository>
        </pluginRepositories>
   </profile>

DevKit Features:

  • Visual design and implementation using Anypoint Studio with an Eclipse-based interface that simplifies and speeds up development.
  • Maven support.
  • Connector packaging tools.
  • Authentication support for multiple types of authentication, including OAuth and username and password authentication.
  • DataSense support to acquire remote metadata.
  • Extensive testing capability.
  • Examples, training, and support to simplify development startup.
  • Batch, Query Pagination, and DataSense Query Language support.
Install DevKit Plugin and check for bellow things.

We can able to see Anypoint connector project and Anypoint connector component.

Connector:

An Anypoint connector is an extension module that eases the interaction between a Mule application and external resources, such as a databases or APIs, through REST, SOAP, or the Java SDK.

Connector Architecture:

Connectors operate within Mule applications, which are built up from Mule Flows, and external resources, which are the targeted resources.

                                DevKitOverviewArchitecture

Connector Project:

Create new project
                                        File --> New ---> Anypoint Connector Project.




Define the attributes as needed:
  • Connector Name: Define a unique name for the Anypoint Connector project.
  • Run time: Select the compatible Mule runtime for the connector. This information in the page applies to all Mule versions from 3.5.0 and later
  • Type: Select the way connector can access a resource with the Type field:
    REST/GENERIC (Java): For Implementing a REST Connector or Creating a Connector using a Java Client Library
    SOAP: For implementing SOAP Connector and specify WSDL location
  • Authentication: Choose an authentication of how the connector accesses its resource: custom or OAuth V2 or select None is no security want to provide.
  • WSDL location: (Only appears if Type is SOAP)
  • From WSDL file or URL: Type in a location or click the browse (…) button to locate the WSDL file on computer. A URL for the WSDL file’s location can be typed or even pasted
  • From folder: Type in a location or click the browse (…) button to locate a folder containing the WSDL file.
    (Note: The first WSDL file in the folder is used)
  • DataSense:
    Add DataSense methods: Provides methods to display metadata on the resource’s entities
    Add DataSense Query Method: The method for DataSense Query Language is added.
Configure Maven and GitHub. (Place default details)


 Select Background and Logo information and click finish.




Now Mule download the all required Jar's (Takes long time for first time) and create the project into current workspace.

pom.xml:

pom.xml contain all information regarding mule project dependency's list.


A default connector class will be generated after which the below annotations need to be configured.
  • @Connector — For defining the connector details like name schema version
  • @Connect — For providing the authentication using username and password
  • @Configurable –To define the properties that are required to connect to the Connector
  • @ValidateConnection — To check the connection status
  • @Disconnect –For closing the connection
  • @Processor – Actual operation is being defined here
  • @RestCall –In case of connecting to rest implemented services using the attributes uri,method
ConnectorConfig.java contains all information reg. connection and security details.


We have to update following url's from api privided by client.
authorizationUrl = "https://devapi.olacabs.com/oauth2/authorize?response_type=token&client_id=<client_id>&redirect_uri=<partner's redirect_uri>&scope=profile%20booking",

accessTokenUrl = "https://api.myconnector.com/uas/oauth/accessToken" looks like this.

We have to update the @RestCallUrl in connector class as shown bellow.


After all the necessary changes are done, we have to build connector. and it must be success.



Now we have install connector by clicking Install or Update option.


Once connector is installed successfully we can access the connector from palette .



Create new project and build flow that can access the custom connector.
In this project we have to build two flows.
           1. OAuth Access Flow
           2. Call Service(bookId by passing id's)



Thanks,
Maheswarareddy.