Tuesday, November 28, 2023

What is Mule Runtime in simple terms..?

What is a Runtime Manager?

Runtime manager is used to deploy/undeploy and manage Mule application on Mule runtime engine(application server), where Mule runtime is running on Cloudhub or on-premise or on RTF. You can change the runtime version at any time and can increase/decrease the worker size

What is vCore?

It's unit of compute capacity for processing on Cloudhub. In 1 vCore, we can deploy upto 10 applications (max), here 0.1 vCore will be consumed by each mule application.

0.1 vCores is the Minimum
16 vCores is the maximum on CloudHub(CH)

What is a worker?

Worker is a dedicated Instance of Mule, which is hosted on AWS and is used to run your integration application
Features of workers:
  • Capacity: Each worker has a specific amount of capacity to process data.
  • Isolation: Each worker run in a separate container from every other application
  • Manageability: Each worker is deployed and Managed independently
  • Locality: Each worker runs in specific worker cloud such as US,EU or Asia-Pacific
What is vertical scaling?
Vertical scaling is to increase the worker size, when you want to process the CPU Intensive API’s or process large payload with small number of request increase the vCore size.

What is horizontal scaling?
Horizontal scaling is to increase the number of workers, if you want to increase the throughput of high frequency small payload.

How to achieve clustering in MuleSoft?
You can achieve this by adding multiple workers to your application to make it horizontally scaling, Cloudhub automatically distribute multiple workers for same application across 2 or more data centres for maximum reliability When deploying your application to two or more workers, the HTTP load balancing service distributes requests across these workers, allowing you to scale your services horizontally. Requests are distributed on a round-robin basis.


  1. Integration Applications: Applications that you create and deploy to CloudHub to perform integration logic for your business
  2. Runtime Manager: User interface that enables you to deploy and monitor integrations, and configure your account
  3. Platform Services: Shared CloudHub platform services and APIs, which includes CloudHub Insight, alerting, logging, account management, virtual private cloud/secure data gateway, and load balancing
  4. Global Worker Clouds: An elastic cloud of workers, Mule instances that run integration applications



Source: MuleSoft Documentation, mulesy.com

Thanks for Reading :-)


Sunday, November 19, 2023

Stateless Vs Stateful Protocol

Network Protocols for client(web browser) and servers are divided into two types: 
1. Stateless Protocol
2. Stateful protocol. 

1. Stateless Protocol: 
In which, Client send request to the server and server response back according to current state. It does not require the server to retain session information or a status about each communicating partner for multiple request. 

Eg:
  • HTTP (Hypertext Transfer Protocol)
  • DNS (Domain Name System) 
  • UDP (User Datagram Protocol)
2. Stateful Protocol: 
In which, Client send a request to the server then it expects some kind of response, if client does not get any response then it resend the request. 

Eg:
  • TCP
  • FTP (File Transfer Protocol)
  • Telnet 


Source: geeksforgeeks.org

Saturday, November 11, 2023

Transaction Management in Mule-4.x

What is Transaction Management?

Transaction management refers to the ability to manage the flow and consistency of data across multiple systems or services involved in an organization. It ensures that all operations within a transaction are executed as a single unit, where either all operations are successful or none of them are executed. 

This guarantees data integrity and reliability, preventing inconsistencies or data corruption.

MuleSoft provides strong transaction management features for - database operations, web service invocations, or message queuing systems (VM, JMS).

Transaction Types
Local Transactions
Local transactions are known as single resource transactions operates on a single type of resources (JDBC, JMS) and it doesn’t support nested transactions.

Eg: If you develop an application that connects to only one specific database and all grouped operations which are part of that single unit use same JDBC connection, then you can use Local Transaction  management

XA Transactions
XA Transactions (Extended Architecture) are known as global transactions which use two Phase Commit (2PC) protocol for managing transactions. XA transactions are used, when you deal with transactions spanning across multiple systems with separate connections and it supports nested transactions. 

Transactional Actions
Transactional Action (transactionalAction) defines the type of action that operations take regarding transactions.
  1. ALWAYS_BEGIN
  2. ALWAYS_JOIN
  3. BEGIN_OR_JOIN
  4. JOIN_IF_POSSIBLE
  5. INDIFFERENT
  6. NONE
  7. NOT_SUPPORTED
Where to configure Transaction.?
Event Source: We can configure in event source like VM Listener, JMS etc.
Go to Advanced Tab: set Transaction Type and Transactional action.
Try Scope: Open the Try scope - General Tab and set Transaction Type and Transactional action.

How Transactions Affect the Scopes?
Async
When running within a transaction, it will run in another thread (asychronous). Which means, all the processors within the scope are out of transactional scope. If any error produced inside an Async scope will not rollback.

Parallel ForEach: It will not execute in parallel. Works as a simple ForEach. This does not affect the way this scope handle the errors

Batch Processing: It works as parallel and the batch execution is not part of the transaction

Scatter-Gather: It will not execute in parallel.

Source Code: Import it in your local studio and make changes as per your DB connection and DB table.


Source: MuleSoft Documentation.
Thanks for reading :-)

Thursday, November 9, 2023

Idempotent Message Validator in Mule 4

Here, we will see how to use Idempotent Message Validator in Mule 4

Idempotent Filter is a powerful tool, can be used to prevent duplicate messages. 

Typically, MuleSoft will receive duplicate data..when processing orders, financial transactions, end user may click the submit button twice etc. :-) 

We can use any incoming attribute of the Mule message as an ID, or you can compute the ID by configuring a DataWeave expression.

The Idempotent filter depends on an Object Store, so we need to setup an Object Store connector (No persistent) and configure TTL and Expiration parameters.

In this example, Entry TTL : 10 seconds. Which means, the ID will be stored in Object Store for 10 seconds. During this time if any request comes with same id, that particular request will be considered as "DUPLICATE" and flow will be routed to exception flow. Else, request will be considered as new and flow continues as a happy path.


HTTP - Request Properties:


Set Variable Properties:



Idempotent Properties:

%dw 2.0
import dw::Crypto
output application/octet-stream
---
Crypto::hashWith(vars.tid as String,'MD5')


Transform Message Properties:




Transform Message (On Propagate) Properties:


Object Store Properties:



Testing:
http://localhost:8081/test?transactionId=101
First time, we can get positive response


Next time (within 10 seconds), we will get negative response as "Duplicate Message found"


Source code: 


Ref: MuleSoft documentation

Sunday, November 5, 2023

Unicast Cluster vs Multicast Cluster

Unicast:

  • It sends data from one source to single target device.i.e one to to mapping
  • It follows Single Node Topology, so Network traffic is high.
    • Eg: Web surfing, file transfer 
  • IP address of same sub-net is used for identifying server/s
  • Except IP address, no other network configuration is required. If IP Address changed due to some reason, you need to add new IP address manually.

Multicast:

  • It sends data from one device to multiple devices.i.e one to many mapping
  • It works on star, mesh, tree and hybrid topology, so Network traffic is low.
    • Eg: Video Streaming, Online gaming 
  • Nodes are automatically detect each other and those are dynamically join the cluster when the node is started
  • The server status doesn’t need to be Running to configure it as a node in a cluster.
  • we can add nodes to the cluster dynamically without restarting the cluster.