Adsense

December 30, 2020

.NET key concepts and introduction of .NET Core

What is .NET Core? Is this the future of .NET? Is this will obsolete the existing platform? Is this backward compatible? If all this are buzzing in your mind, please take a cup of coffee and go through the below topic, I promise you when you have your last sip of coffee you will have brief idea about this booming topic.

Basic of .NET

.NET is a free, open-source development platform for building many kinds of apps. .NET is open source, using MIT and Apache 2 licenses. A .NET app is developed for and runs in one or more implementations of .NET. .NET Framework, .NET 5 (and .NET Core), and Mono are the three most important implementations of .NET. Below are the key concepts of .NET.

 

What is .NET Standard?

There are various implementations of .NET. Each implementation allows .NET code to execute in different places—Linux, macOS, Windows, iOS, Android, and many more. .NET Standard is a formal specification of the APIs that are common across all these .NET implementations.

The relationship between .NET Standard and a .NET implementation is the same as between the HTML specification and a browser. The second is an implementation of the first.

Each .NET version has an associated version of the .NET Standard. .NET Standard is defined as a single NuGet package because all .NET implementations are required to support it. Tooling becomes easier because the tools have a consistent set of APIs to use for a given version. You can also build a single library project for multiple .NET implementations.


.NET Ecosystem

.NET includes the below components for each implementations:

.NET Ecosystem



.NET Implementations

There are four .NET implementations that Microsoft supports:

.NET Implementations


 Glimpse of .NET Implementations

.NET Implementations

What to choose when? (.NET Framework and .NET 5(including .NET Core))

Microsoft maintains both runtimes for building applications with .NET, and they share many of the same APIs. This shared API is what is called the .NET Standard.

.NET 5


Pick .NET 5

ü  If there is a new application to build, and have a choice between .NET Core and .NET Framework, .NET Core is the way to go.

ü  If the application need cross platform implementation(Windows, Linux, and macOS)

ü  Microservice architecture supported, so it allows the cross platform service developed under .NET framework, Ruby, Java etc communicate within another

ü  Containers are the VMs of today. .NET Framework can be used on Windows containers but .NET core is more modular, flexible and lightweight and after containerize because of it’s cross platform nature it can deploy in various Docker(ex:- Linux Docker containers)

ü  .NET CORE is one of the best performing one among web based frameworks in terms of performance and scalability 


Pick .NET Framework

ü  If existing application is .NET framework and there is no mind to change it

ü  The old technologies are using in the project which are not yet incorporated in .NET CORE(ASP.NET webforms , Visual Basic and F#)

ü  In cases where the libraries or NuGet packages use technologies that aren't available in .NET Standard or .NET 5 then it is required the .NET framework.


Happy Learning :)

Read More »

December 27, 2020

Pattern Matching in Dataweave Using Match Case

 Bonjour!

Just like any other programming language, In Mule4, dataweave provides match function to achieve the functionality of if-else statements. 

A match expression contains a list of case statements that can optionally have an else statement. Each case statement consists of a conditional selector expression that must evaluate to either true or false.

Let's consider a scenario where you need to update certain fields of incoming payload keeping the rest of the fields as it is, you can use a match and case

for example, the following is the input JSON object:

Input:

{
    "address": {
     "houseNumber" : null,
"street" : "IOC Road",
"pincode" : "111222",
"landmark" : "Statue of unity",
"city" : "Ahmedabad",
"state" : "Gujarat",
"country" : "India"
    }
}

Dataweave Transformation:

%dw 2.0
output application/json
var flag = if (payload.address.houseNumber == null) false else true
---
{
"updateAddressRequest":
payload.address mapObject (value,key,index) ->(
key as String match {
case "pincode" -> {(key): "000000"}
case "houseNumber" -> {(key): if(flag == false) "00" else ""}
else -> {(key):(value)}
}
)
}

Output:


{
"updateAddressRequest": {
"houseNumber": "00",
"street": "IOC Road",
"pincode": "000000",
"landmark": "Statue of unity",
"city": "Ahmedabad",
"state": "Gujarat",
"country": "India"
}
}

What we did here with the input JSON object is that we matched the keys using keyword match and then based on a condition updated the value of the key. We then used the else keyword in order to keep the rest of the fields the same as the input. 

In above example we are updating houseNumer and pincode field with case and other fields are remains same with else block.

This is also an example of how we can use the match case with mapObject

Pattern matching using Match Case can be done on Literal values, on expressions, on Data Types, and on Regular Expressions. 

Adios amigos!



Read More »

December 22, 2020

How to pass payload using Get method-Mule4

Hello Friends, 

I recently worked for one of API implementation where I needed to encrypt and send/receive one or more field in queryParms/headers while calling Get operation to external system.

As per API standard Get method should not pass payload as body while calling any Apis or 3rd party systems. Get method supports Uri Params, Query Params or Header Attributes.

In this article, I will show you the technique how you can pass encrypted payload using Http Get method. This is one of tricky interview question which normally asked in Mulesoft or Api Design related interviews.

As we know the when we encrypt any value it will not be a single string. Encrypted value may be of be multiple line as given below for PGP encryption for value 123456

-----BEGIN PGP MESSAGE-----
Version: BCPG v1.58

hIwDmCS94uDDx9kBA/9NIO0Kq9+yhXBLQveoykVjbECqXnGM8DargSsBxE2xBLQP
000W7mre5YpeSRJi4dvjVkAKPaxIFJhHlUNv38i5DkGD/z53SKtbKfYdfT+3oHT4
SVnIkcqWM+i+xawrKSk8Lz+j5GaJZ+wQrrxi8TP9RVW+wZlcbBNfxZVShDYp8dJX
AX9/x+1dFyO0EtHBipB0MLOqrb+sua028HGcg7E/sptn89JAgUcNEXOurVSfN6Ws
P/KxUMQY9+KKQQKavJ6LC92a6GJhVk4S+cnY1sxDLGtqKcGd+qCd
\u003dwGi2
-----END PGP MESSAGE-----



For both scenario(send/receive) we will be using (dw::core::Binaries) module from dataweave

toBase64(Binary): String


It takes Binary as input and returns result as base64 encoded String.

encoding
base64 Encoding




fromBase64(String): Binary


It takes base64 encoded String and returns original Binary data as a result.

decoded
base64 decoding



In this article we have seen how to convert encrypted payload to base64 encoded string and vice-versa. We can do the same conversion and pass with other payload type like JSON/XML etc..
These two dataweave functions are quite useful while dealing with payload with GET method.


Happy Learning :)
Read More »

December 19, 2020

Mulesoft Interview Questions With Answers - Part 2

Bonjour!

Let's take a look at some more Mulesoft basic interview-related questions!

Which component is used for schema validation and routing incoming Mule messages against RAML?

APIkit Router. 

Mule provides APIkit Router for Schema validation and routing the incoming Mule messages, serializing responses, validating payloads, Query parameters, URI parameters against RAML


Where are the HTTP, database configurations defined?

Global.xml

What is the purpose of a domain project?

The main purpose of a domain project is to have all the globally shared configurations for the projects. All the shared resources can be configured in a domain project. Mule applications can be associated only with one domain project. However, a domain project can be associated with multiple mule applications.


Does Cloudhub support Mule domain projects?

No, Mule domain projects neither supported in Cloudhub nor in Runtime Fabric. Domain projects are supported in on-premises environments.


Which connector is used for handling SOAP requests?

Web service Consumer.

How we can invoke REST or SOAP Services?

To invoke REST we can use HTTP and the Web service Consumer connector can be used to invoke SOAP services.


What is the use of Message Enricher?

In Mule 3, Message enricher is a component used to enrich the current message with additional information from a separate resource without disturbing the current payload.

Enricher is used in scenarios where the target system needs more information than the source system can provide. It calls an external system or doing some transformation to the current payload and saving it in a target variable.


Do we have Message Enricher in Mule 4? 

In Mule 4, We don't have a message enricher anymore. 
Now, every component is embedded with a target variable which solves the purpose. 
 

How do you override application properties?

You can configure your Mule application to automatically load properties from properties files based on different environments (Production, development, testing, QA) using property placeholders. 

1.  Create a properties file for each development environment in your Mule application.
2. Configure a property placeholder in your application to look for the environment at the time of launch.
3. Set environment variable one each for the different environment.

The property placeholder will then take up an environment variable value and based on that use the properties file.


How can we store sensitive data such as Client ID and Client Secret? 

Properties in Mule 4 can be encrypted to store sensitive data such as Client ID and Client Secret. We can encrypt a .yaml or .properties file using the secure properties module. For more details about the use of  secure properties: securing-configuration-properties-in-mule


Give some examples of popular Mulesoft connectors? 

HTTP, File, FTP, SFTP, Database, Salesforce, SAP, AWS, etc.


Can you create a custom connector? 

Yes. 

When an API specification is published to Anypoint Exchangeit automatically generates a connector for it. You can find out a list of Mulesoft connectors here.


Advantages of Mulesoft Anypoint connectors? 

  • It provides integration of Mulesoft application with different 3rd party systems like Facebook, Twitter, Salesforce, etc.
  • It is easier to maintain and no need to spend time on optimization and security.
  • It provides reusability which helps in speed-up development.


Is Mulesoft PaaS or SaaS? 

Mulesoft provides iPaaS (Integration Platform as a Service). It provides connectivity across on-premises and SaaS applications.


In Mule4 how you can generate custom errors.

By using the Raise Error component


In Mule 4, how errors are handled in a mule flow?

When an error is thrown in Mule flow while processing an event first step is it stops normal flow execution and it will not go to the next components. Then depending on the error type either error will be caught and handled inside the error handling block or thrown up to its parent flow.


Where we can add an error handler in the Mule 4 application?

An error handler can only be added to

– A flow

- A private flow

– A Try scope

– An global error handler (outside of any flows) is then referenced to any of the error handling strategies.

Note: Error handler can not be added to subflows.


What is the Mule default error handler?

When there is no error handler defined for any flow or by using try scope, the Mule default error handler will be used. This default handler should be configured globally.


What if the default error handler not configured in the Mule application?

If the default error handler is not configured then Mule runtime will provide its own default behavior

– First, it stops the execution of the flow and logs information about the error.

– Implicitly and globally handles all errors thrown in Mule applications.

– It automatically rethrows the error.

– Most important we cannot configure it.


What are error scopes in mule4 to handle errors?

– On Error Continue scope

– On Error Propagate scope

 

Can you please explain the difference between these two error scopes in Mule4?


What is the use of Try scope in Mule4?

Try Scope is very useful when you need to group a set of events/ components and want to handle errors based on your specific requirements. It acts as a private flow inside the parent flow. For Unhandled errors, it propagates to its parent flow.



Read More »

December 16, 2020

RAML 1.0 Multiple Types for a Single Request

 Bonjour!

You must have come across a situation where you need to define two different Types for a particular resource in your RAML specification.

In this article, I'll show you how to do that!

you can define multiple Types using the pipe symbol ("|") as follows: 

The request Types can be defined in the header of the RAML. The examples can be specified using facet "examples" and added in the form of either files using the keyword "include" or the example itself.
 



Adios amigos!
Read More »

December 12, 2020

Mulesoft Interview Questions With Answers - Part 1

Bonjour!

What is Mulesoft?

The first and the most basic question asked in Mulesoft developer interviews. 

Mulesoft is the vendor that provides an integration platform to help businesses connect data, applications, and devices.

Mule is the runtime engine of the Anypoint Platform. It is a lightweight Java-based enterprise service bus (ESB) that allows developers to connect applications and exchange data. It can connect any systems by using different protocols like HTTP, JMS, JDBC etc.


What is Anypoint Platform?

Anypoint platform is a hybrid integration platform which is highly productive, unified and helps to create a smooth distributed systems. It helps to manage full API lifecycles. It provides unified platform to deploy, manage, monitor and rapid development of apps into single place.


What is a Mule Application?

A Mulesoft application is a package of codes and files that runs inside Mule Runtime. Mulesoft application can be triggered with set of events that can be external and inside mulesoft. It can process events and route to next components or endpoints. Endpoints can be external system, another mulesoft application or local resources like file.

A Mule Application may consists of one or more flows, subflows and private flows.


What is the difference between Flow, Subflow, and Private flow?

Flow is a message/event processing block. It can have Mule sources (e.g. an HTTP listener) to trigger the execution of a flow. It can have its own processing strategy and error handling strategy.

Subflow is a scope that enables you to process messages synchronously. It doesn't have any source or error handling block. It inherits the processing strategy and error handling strategy from parent flow. It can be used to split common logic and reusability.

Private flow is a flow without a Mule source. It can be synchronous or asynchronous based on the processing strategy selected. They can have their own error handling strategy.

All three above can be called using a flow-ref. Source will be skipped while calling using flow-ref.


How Mule Applications can be build?

Mule application can be created using online flow-designer and offline by downloading Anypointsudio. 

Link for Online flow-designer

Link to download AnypointStudio


How Mule4 Application flow executes?

Mule4 application flows executes events in multiple threads. Mule4 automatically optimizes performance and uses thread switching and parallel processing if required.


Variables in Mule 4 vs Mule 3?

In Mule 3, we had three types of variables: Session variables, Record variables, and Flow variables.

In Mule 4, we only have Flow variables. These variables can be accessed using the keyword "vars".

Example:

vars.variableName


What is API-led connectivity?

API-led connectivity is a methodical way to connect applications to data through reusable APIs. APIs are created in three distinct layers: Experience, Process, and System.




API Life Cycle?

An API life cycle consists of 3 layers:



The first step towards API development is API Specification. This phase involves designing of the API based on the requirements of business. An API Specification is a blueprint of an API.

Anypoint Platform provides Design center to design API's REST interfaces.

The next phase is API Implementation. This phase involves actual implementation of the API.

Anypoint Platform provides Flow Designer which is a web based tool to create a prototype of the API.

Anypoint Studio is the IDE for development and testing of Mule applications. 

Final phase in API life cycle is API management, uses a tool named API manager on Anypoint Platform which is used to apply policies to secure APIs and restrict access. 


What are the advantages of API-led approach?

  • Mulesoft prefers Design first approach for API development that helps non-technical stakeholders easy to understand the API specs/contracts.
  • It simplifies the interface between Client and application by hiding complex details.
  • Business validation and contracts can be defined at API specification. So, developers don't need to invest time to write code for validation and error type checks.
  • It encourages "fail fast" approach which helps in fast and parallel development.
  • It encourages reusability of assets and collaboration across teams.
  • Apis can be mocked before implementation starts which helps early feedback and parallel development.
  • Mulesoft anypoint platform provides tools to write, publish, share and manage versions of API.


What is RAML?

RAML stands for RESTful (REpresentational State Transfer) API Modeling Language. It's a way of describing a RESTful API that is readable by both human and computers. 

They use https methods such as GET, PUT, POST, DELETE, etc.


Difference between URI parameters and Query parameters.

URI parameter is used to specify a specific resource whereas Query parameter is used to filter or sort those resources.

let's say we need to filter products based on productType, we use query parameters in this case:

GET: /products?productType=electronics

Let's consider another scenario where we need to retrieve particular product details, we use URI parameters in this case:

GET: /products/{productID}

here, productID will be replaced by a value.


Error Handling in Mule 4?

Error handling in Mule 4 is redesigned. It has three mechanisms to handle errors now.

1. On-Error Propagate:  In an On-error Propagate scope, when an error occurs, it terminates the current execution of flow and then throws the error to its parent flow where it's handled.

2. On-Error Continue: In case of an error in an On-error Continue scope, the execution of the flow continues as if successful sending a 200 OK response.

3. Try Catch scope: A Try Catch scope is used to handle errors on individual components. It is especially useful when you need to separate error handling strategies for different components in a flow.


What are the Logger levels?

There are 5 logger levels namely: DEBUG, ERROR, INFO, TRACE, and WARN. 


What does scatter-gather return?

A scatter-gather returns a Mule event.


What is the use of Async scope?

Async scope can be used to trigger flows subflows or any components asynchronously from a parent flow. Async scope is very helpful while using logger component or parallel processing requires.


What is the difference between map and mapObject?

map operator is used for array. It takes an array as input and returns an array.

mapObject operator is used for object with key: value pairs. It takes an object as input and returns an object.


map invokes lambda with two parameters: value and index from the input array. 

Example:

%dw 2.0
output application/json
---
["apple", "orange", "banana"] map (value, index) -> { 
    (index) : value}

Output:

[ { "0": "apple" }, { "1": "orange" }, { "2": "banana" } ]


mapObject invokes lambda with keyvalue, or index for mapping given object.

Example:

%dw 2.0
output application/json
---
{"chandler":"bing","monica":"geller"} mapObject (value,key,index) -> { 
    (index) : { (value):key} }

Output:

{ "0": { "bing": "chandler" }, "1": { "geller": "monica" } }



What is batch processing?

Mule allows you to handle large quantities of data in batches. 

This is achieved using a Batch job scope which splits messages into individual records, performs actions on records, and reports the results. A Batch job scope processes data asynchronously.


Each batch job contains three different Processing Phases:  

1. Load and Dispatch: In this phase, Mule splits the message, creates a Batch Job Instance, a persistent queue and associates it with the Batch Job Instance.

2. Process: This phase does the actual processing of records asynchronously. 

3. On Complete: This is an optional phase where you can configure the runtime to create a report or summary of records. 


Stay tuned for more!





Read More »

December 05, 2020

splitBy and joinBy function dataweave2

 Hello friends, 

In this article I want show you the uses of two very common dataweave functions splitBy and joinBy. 

These two functions are very useful while doing transformation with Array and Strings. 

Here, we will see how we can use these dataweave functions converting data from String to Array and vice versa.

splitBy

Splits a string into a string array based on a value of input or matches part of that input string. It filters out the matching part from the returned array.

A string or a Java regular expression used to split the string. If it does not match some part of the string, the function will return the original, unsplit string in the array.

splitBy(String, Regex): Array<String>

Example 1:
------------------------------
Input
Hello World
------------------------------
Dataweave 2.0 Expression
------------------------------
%dw 2.0
output application/java
---
"Hello World" splitBy(/\s/)
------------------------------
Output
[Hello, World]

splitBy(String, String): Array<String>


Example 2:
------------------------------
Input
Manish Kumar
------------------------------
Dataweave 2.0 Expression
------------------------------
%dw 2.0
output application/java
---
payload splitBy(" ")
------------------------------
Output
[Manish, Kumar]


The regex/separator can match any character in the input. splitBy performs the opposite operation of joinBy.


joinBy

joinBy function Merges an array into a single string value and uses the provided string as a separator between each item in the list. 

You can use joinBy Dataweave 2.0 function to convert array to string.

Example 3:
------------------------------
Dataweave 2.0 Expression
------------------------------
%dw 2.0
output application/json
---
{ "joinName" : ["Manish","Kumar"] joinBy "-" }
------------------------------
Output
{
  "joinName": "Manish-Kumar"
}

joinBy performs the opposite task of splitBy.


Happy Learning :)


Read More »

December 01, 2020

Array comparison use case Dataweave2

Hello friends,

In this article we will see one of the common and challenging real-time use-case in IT industry during application development where we require to compare between arrays. These arrays could be from two different source or api responses.

Here we will see how we can compare two arrays results/payloads and get required results. Also we will see the complete example of our use-case.

To achieve this we will see how we can use the combination of some dataweave functions and how we can utilise these functions for our use-case.

  • flatMap
  • filter
  • contains
  • partation


There are many ways to achieve these functionality. Here, I have tried to show you two different methods to achieve this.


Method I:


flatMap

flatMap(Array<T>, (item: T, index: Number) -> Array<R>): Array<R>
It comes under dw::Core package from dataweave library.

Iterates over each item in an array and flattens the results. It produces output as Array. 

Instead of returning an array of arrays (as map does when you iterate over the values within an input like [ [1,2], [3,4] ]), flatMap returns a flattened array that looks like this: [1, 2, 3, 4]. flatMap is similar to flatten, but flatten only acts on the values of the arrays, while flatMap can act on values and indices of items in the array.

%dw 2.0
output application/json indent=false
---
[ ["a":1,"b":0], ["c":0.1,"d":7] ] flatMap (value, index) -> value
-------------------------------------------------------------------
Output:
[{"a": 1},{"b": 0},{"c": 0.1},{"d": 7}]


filter

filter(Array<T>, (item: T, index: Number) -> Boolean): Array<T>

It comes under dw::Core package from dataweave library. It produces output as array.

Iterates over an array and applies an expression that returns matching values. The expression must return true or false. If the expression returns true for a value or index in the array, the value gets captured in the output array. If it returns false for a value or index in the array, that item gets filtered out of the output. If there are no matches, the output array will be empty.


%dw 2.0
output application/json
---
[9,2,3,4,5] filter (value, index) -> (value > 4)

-------------------------------------------------
Output:
[
9,
5
]


Complete example below by using flatMap and filter function:



%dw 2.0
output application/json
var filterCriteria = [
{
"IDENTITY": "D40000",
"NM": "Delta",
"CODE": "D12"
},
{
"IDENTITY": "C30000",
"NM": "Charlie",
"CODE": "C11"
}
]
var responsePayload= [
{
"CODE": "A11",
"NAME": "Alpha",
"ID": "C10000"
},
{
"CODE": "B12",
"NAME": "Bravo",
"ID": "B20000"
},
{
"CODE": "C11",
"NAME": "Charlie",
"ID": "C30000"
},
{
"CODE": "D12",
"NAME": "Delta",
"ID": "D40000"
},
{
"CODE": "E12",
"NAME": "Echo",
"ID": "E50000"
}
]
---
filterCriteria flatMap(v) -> (
responsePayload filter (v.IDENTITY == $.ID and v.NM == $.NAME and v.CODE == $.CODE)
)
---------------------------------------------------------------------------------------------------------------
Output:
[
{
"CODE": "D12",
"NAME": "Delta",
"ID": "D40000"
},
{
"CODE": "C11",
"NAME": "Charlie",
"ID": "C30000"
}
]

----------------------------------------------------------------------------------------------------------------------

Method II:


Now, let use see the 2nd way to compare array by using contains and partition function. Here the input arrays can be from two different source or api responses. Let's see how we can compare and filter the incoming arrays by using these two useful function.

contains

contains(Array<T>, Any): Boolean

It comes under dw::Core package from dataweave library. It returns true if an input contains a given value, false if not.

This version of contains accepts an array as input. Other versions accept a string and can use another string or regular expression to determine whether there is a match.


partation

partition(Array<T>, (item: T) -> Boolean): { success: Array<T>, failure: Array<T> }


It comes under dw::core::Arrays package from dataweave library.

It separates the array into the elements that satisfy the condition from those that do not.
Elements that satisfies conditions will come under "success" array partation and which it don't satisfy comes "failure" array partation. So, you can retrieve the matching results under "success" partation node.


Note: Introduced in DataWeave 2.2.0. Supported by Mule 4.2 and later.


%dw 2.0
import partition from dw::core::Arrays
output application/json
var responsePayload = [
{
"CODE": "A11",
"NAME": "Alpha",
"ID": "C10000"
},
{
"CODE": "B12",
"NAME": "Bravo",
"ID": "B20000"
},
{
"CODE": "C11",
"NAME": "Charlie",
"ID": "C30000"
},
{
"CODE": "D12",
"NAME": "Delta",
"ID": "D40000"
},
{
"CODE": "E12",
"NAME": "Echo",
"ID": "E50000"
}
]

var filterCriteria = [
{
"IDENTITY": "D40000",
"NM": "Delta",
"CODE": "D12"
},
{
"IDENTITY": "C30000",
"NM": "Charlie",
"CODE": "C11"
}
]
---
responsePayload partition (e) -> filterCriteria contains {IDENTITY:e.ID,NM:e.NAME,CODE:e.CODE}
--------------------------------------------------------------------------------------------------------------------------

Output
{
"success": [
{
"CODE": "C11",
"NAME": "Charlie",
"ID": "C30000"
},
{
"CODE": "D12",
"NAME": "Delta",
"ID": "D40000"
}
],
"failure": [
{
"CODE": "A11",
"NAME": "Alpha",
"ID": "C10000"
},
{
"CODE": "B12",
"NAME": "Bravo",
"ID": "B20000"
},
{
"CODE": "E12",
"NAME": "Echo",
"ID": "E50000"
}
]
}

You can choose any of these methods while doing comparison of arrays for your use-cases.

Happy Learning :)
Read More »