Adsense

February 06, 2020

How to write Attributes from XML to Json - DW2

In project development sometimes we needed to convert the payload from xml to json. We also need to write the xml attributes after transformation. 

For this purpose we can use writeAttributes=true in header section of data-weave. This attribute is available from Dataweave2.


Please find the snippets below:



Sample XML Input:

<users>
<user>
<personal_information>
<first_name version="V1">Manish</first_name>
<middle_name>Kumar</middle_name>
<last_name>Sah</last_name>
</personal_information>
</user>
</users>


Dataweave Script

%dw 2.0
output application/json writeAttributes=true
---
payload

Output:

{
  "users": {
    "user": {
      "personal_information": {
        "first_name": {
          "@version": "V1",
          "__text": "Manish"
        },
        "middle_name": "Kumar",
        "last_name": "Sah"
      }
    }
  }
}

Happy Learning :)
Read More »

February 04, 2020

Five pillars of Azure DevOps

In this article I will discuss about the five pillars(components) of Azure DevOps. These pillars actually helps to build and manage development life-cycle. 
Development life-cycle consists of : 


      • Requirement gathering, 
      • Work plan, 
      • Code management, 
      • CI/CD.
      • Test plans
These components helps key stakeholders proper real time insights of the projects.
5-pillars-of-Azure-DevOps

Azure Boards

Plan, track, and discuss work across teams, deliver value to your users faster. Boards is used for agile project planning. It is a management tool that provides you the ability to link repos, work items, tasks and sub-tasks. With Azure Boards you can track backlogs and customize dashboards and create custom reporting. It easily helps to monitor progress throughout the lifecycle of your project. Moreover you can integrate boards with tools like Microsoft Teams and Slack to sync up with members.
azure-boards

Azure Repos

Unlimited cloud-hosted private Git repos. Collaborative pull requests, advanced file management, and more.
Azure Repos functionality differs between choosing your Git or Team Foundation Source Control. The most common choice is Git. Git is there with the added benefit of linking commits and pull requests to Work Items and CI. you can customise your branch policies to maintain your team’s high standards. It provides you to protect your code quality with branch policies. you can add code reviewer signoff to keep code quality high.
azure-repos



Azure Pipelines

CI/CD that works with any language, platform, and cloud. Connect to GitHub or any Git provider and deploy continuously to any cloud. It allows the building, testing and deployment of code using DevOps practices.
azure-pipeline

Azure Test Plans

The test management and exploratory testing toolkit that lets you ship with confidence. 
azure-test-plans

Azure Artifacts

Create, host, and share packages. Easily add artifacts to CI/CD pipeline. You can share code effortlessly by storing Maven, npm, NuGet and Python packages together and add artifacts to your CI/CD pipelines with a single click.

Azure Overview  gives you real time insights of the project.
Azure-Devops-overview



Happy Learning :)
Read More »

December 05, 2019

Anypoint MQ Circuit Breaker - Mule4

In integration development there are lot of patterns that we can follow based on project requirements. Circuit Breaker is one of them.
In this article we will see how Circuit Breaker can be used and what we should consider while implementing it. 

Circuit breaker design pattern is used when:

  • To handle error scenarios and message reprocessing strategy.


Mulesoft has provided circuit breaker capability with Anypoint MQ component.
You can add dependency inside your pom as below:

<dependency>
<groupId>com.mulesoft.connectors</groupId>
<artifactId>anypoint-mq-connector</artifactId>
<version>3.1.0</version>
<classifier>mule-plugin</classifier>
</dependency>

Now, I will show you how you can design and configure your mule flows for implementing Circuit Breaker capability.


Below is the sample circuit breaker mule flow design:


flow-design-circuit-breaker

We will explain each and every part the above flow design below:


Circuit Breaker Configuration:

Go to global elements section create a Circuit breaker configuration as below:



circuit-breaker-configuration


This configuration can be shared across multiple Subscriber resources in the project.
On Error Types – Type of Errors based on which you want to Open the Circuit.
Errors Threshold – No. of Failures in Succession – Ex: 5
Trip Timeout – Duration to keep the Circuit Open once the ErrorThreshold is reached – Ex: 60 Minutes


Subscriber Configuration

Anypoint MQ Subscriber Source provides Circuit Breaking Capability.
                                                       
subscriber-circuit-breaker-config

 
1. Select the Anypoint MQ Subscriber Source.
2. Click on the Advanced tab.
3. Provide the Circuit Breaker from Global Reference.



AMQ Message Processing\Listening Strategy:


amq-subscriber-configuration


This section describes the methodology how we are going to follow to process messages from Anypoint MQ. This process helps in effectively handling reprocessing and retrying scenarios and also simplifies the process from a maintenance perspective.


Steps:

  1. Configure the Subscribe processor
  2. Subscriber Type – Prefetch
  3. Max Local Messages –  default it to 5, you can change based on requirement for further tuning.
  4. Acknowledgment Mode – Set to MANUAL, As the Acknowledgement Mode is set to MANUAL, we need to Ack the message post successful completion of the flow. So that the message doesn’t get retried/consumed.


Circuit Breaker and AMQ Listening Strategy both need to be configured in our components where we want messages to be reprocessed and retried in a configurable manner.

In case of Error Scenarios,



error-propagate-type

Based on your requirement you can catch the error and subsequent to Error Handling, Nack the message so that the message stays on the queue and will be subsequently redelivered.


nack-token-vars



You can use Ack the message so that the message is removed from the queue in case of success scenarios.


ack-token-vars

This ackToken you can store in variable which can be used for Ack/Nack of the message.


set-attributes


MQ messages stores in queue after getting Nack

mq-msg-properties-details



Please find sample Mule project in Github Error-Handling-using-Anypoint-MQ-Circuit-Breaker
Read More »

November 30, 2019

Queueable Apex - The middle way

The last post was a comparison between batch apex and @future apex. There are some advantage and disadvantage with both of them. When batch and @future needs to meet in between - queueable comes for rescue.

There are a few things that @future did not provide:
  1. @future requires the arguments be primitives, which means reconstructing a structure once the method is called.
  2. Difficult access to job ID. The executeBatch method returns a jobID, while calling an @future job does not give you the ID of the related job.
  3. No chaining - Chaining of batch apex is not allowed.
Q - Why we go for queueable Apex?
A - When the job such as extensive database operations or external Web service callouts is long running and is running asynchronously and you want to monitor the job status. It can be done via queueable apex and adding a job to the ApexJob queue. In this way, your asynchronous Apex job runs in the background in its own thread and doesn’t delay the execution of your main Apex logic.

Queueable jobs are similar to future methods in that they’re both queued for execution, but they provide you with these additional benefits.

Getting an ID for your job: When you submit your job by invoking the System.enqueueJob method, the method returns the ID of the new job. This ID corresponds to the ID of the AsyncApexJob record.
This ID helps you identify your job and monitor its progress, either through the Salesforce user interface in the Apex Jobs page, or programmatically by querying your record from AsyncApexJob.

Using non-primitive types: Your queueable class can contain member variables of non-primitive data types, such as sObjects or custom Apex types.

Chaining Jobs: In queueable you can also chain Jobs from a running job. It is very helpful if some processing needs to be done which depends on the last results.

Example:
This example is an implementation of the Queueable interface. The execute method in this example inserts a new account.

public class QueueableExample implements Queueable {

    public void execute(QueueableContext context) {
        Account acc = new Account(Name='Test Account Neeraj');
        Insert acc;     
    }
}

To add this class as a job on the queue, call this method:
ID jobID = System.enqueueJob(new QueueableExample());

After you submit your queueable class for execution, the job is added to the queue and will be processed when system resources become available. We can monitor the status of our job programmatically by querying AsyncApexJob or through the user interface Setup --> Monitor --> Jobs --> Apex Jobs.

Test class for queueable apex:

@isTest
public class AsyncExecutionExampleTest {
    static testmethod void testAccount() {
     
        Test.startTest();     
        System.enqueueJob(new QueueableExample());
        Test.stopTest();

        Account acct = [SELECT Name FROM Account WHERE Name='Test Account Neeraj' LIMIT 1];
        System.assertEquals('Test Account Neeraj', acct.Name);
    }
}

Few things can be noted here:

  • The execution of a queued job counts against the shared limit for asynchronous Apex method executions.
  • We can add up to 50 jobs to the queue with System.enqueueJob in a single transaction.
  • Use Limits.getQueueableJobs() to check how many queueable jobs have been added in one transaction.
  • No limit is enforced on the depth of chained jobs.
  • We can add only one job from an executing job with System.enqueueJob, that means only child job can exist for parent queueable job.

Read More »

November 24, 2019

Access Anypoint Platform in Anypoint Studio

Issue:

You can not access Anypoint Platform after configuring External Identity in Anypoint Studio.


Reason:

One of most common issues is the wrong Organization Domain configuration.


HowTo:

Please follow below steps to validate if the Organization domain is properly configured:

Open Anypoint Studio
Go to Window -->Preferences --> Anypoint Studio --> Authentication --> Add Button


Authentication Tab

 
Now click on Configure --> Select External Identity

Provide your valid Organisation domain --> Select OK
Please validate your Organization domain field. The value must be your valid Organization domain.



add external identity


Once validated you can login your Anypoint Account with your user-id and password. You also can configure expires days.

Finally select Apply and Close button.


Happy Learning :)
Read More »