| res ipsa loquitur

~ Latest Posts ~

Looking back at the past five years, there are some lessons that I’ve found vital in growing myself as a software engineer. I wanted to share my experience in hope that this will help someone who is beginning their career as a software engineer as well.

Following are the five lessons that helped me grow as a software engineer.

  • Goals
  • Learn to learn
  • Keep the tool-set sharp and relevant
  • Work under a great mentor and gain experience
  • Manage your personal finances

Let us go through each item on the list. I don’t intend to go into details on each point bombarding you with details. Rather, I will give you some pointers so that you can do your own research.

Set your Goals

You should have a purpose, an end goal to start with. This will keep you on course. Otherwise you will be wandering here and there without any true purpose or reasoning for why you are doing all this. Your goals can change as your perception about the world change. But at any given time, you should have a set of goals in your life. This will help you make the rational decisions when it comes to all the lessons I’m gonna mention and to be a happy and content person.

Learn to learn

You won’t be able to learn everything through your formal education to achieve your end goal. Time you can spend on learning is limited. Time is a limited resource. You have to prioritize, and pick and choose things to learn and not to learn. Hence you have to learn to learn.

Most important aspect of learning is having the motivation to learn something new. A purpose that backs the learning outcome. Motivational factors can be different from person to person, but the key is to find yours. It would be best if you can identify why you should learn it and how it affects you to achieve your purpose of life. Learning things for the sake of learning is a gamble, few will succeed and most will fail.

When learning you will go through planned and unplanned learning opportunities. Planned learning is where you have assigned a specific time for learning and engage in improving your knowledge.

Unplanned learning is where you will stumble upon something new and you dig deep on the subject and learn something new out of it. If you want to improve yourself you have to do both planned and unplanned learning, even after getting out of the university. There can be instances where you are debugging the code you have written and you observe a strange behavior. If you don’t find out the exact reason for that, you are skipping an unplanned learning opportunity. You will only gain some experience on the behavior but not the proper reason.

Following are some pointers on the subject

  • Identify what you need to learn by answering yourself why you want to learn it, and what you gain out of it.
  • Concentrate on the core concepts when learning
  • Try to learn ins and out of what you are currently working on
  • Expand your knowledge without restricting your self to a particular subject area. More diverse the more valuable you will be.
  • Learn from the industry gurus. Read blogs, books, listen to talks done by them. Learn from another’s experiences.
  • Keep aside a time for learning (planned learning).
  • Manage your time and establish work routines to avoid procrastination.

Keep the tool-set sharp and relevant

Think of a carpenter, if he doesn’t have the proper tool set he wouldn’t be able to do a proper job. Same applies to a software engineer or any other professional as well.

Lets have a look at a set of tools that a software engineer should have in their tool set.

  • IDE - you should have an IDE that you are familiar with. Learn the IDE shortcut keys. Learn how you can do refactoring with it. You should have these shortcuts engraved into your muscle memory.
  • Terminal - you should be able to familiarize yourself to using a shell (on Linux machines you can use bash). GUI tools are less productive compared to a shell. By learning a small subset of shell commands and combining them we can get more done with less. You can put the commands in a script file and use it later as well. Possibilities are endless to improve your productivity.

For instance say you want to create hundred directories with names d1 to d100. Here’s a bash script to do the job.

$ for i in {1…100} do; mkdir d${i}; done

Think of the steps you have to go through to do it with a GUI.

  • Have a primary language - you should have a programming language that you know inside out. Having a sound knowledge on data structure implementations, programming concepts and paradigms in that language will help you. I’m not saying you should learn only one programming language. You will definitely come across more that one programming language in your career.
  • Data structures - In most cases, nobody will ask you about the data structures, unless you are going for an interview. But you will be using maps, lists, sets, queues etc in your programs. You should know when to use what. Some idea on the time and space complexity (Big-O notations) of those data structures, is a must.

Following are some good books that I would recommend for improving your skill set.

Work under a great mentor and gain experience

In any kind of discipline you need good guidance to excel in that field. Same goes with software engineering as well.

In my opinion, you should work under a good mentor for at least two years. They will set you up for the troubled waters you have to wade through in the coming years. If you feel like you are not getting the guidance you need from your mentor you have to be clever and get yourself a great mentor. It doesn’t have to be a formal assignment. There is always something that you can learn from a mentor. Your mentor can be your boss, a senior member in the company, or someone outside the company.

When you select a work place try to get into a place where people have the learning attitude and avoids shortcuts to success. At least in the initial years of your career give priority to learn things rather than to follow trends. Play smart keeping you end goal in mind.

Gain experience

In the first few years (3–4 years) the most important factor should be the work exposure and the experience you gain. I’ve seen people take there career decisions solely based on the salary or the perks they get. Although, this can be a factor. If you gain industry experience, you’ll be able to cover up those initial years in no time.

In some situations, in the initial years you’ll be earning less than your friends. Remember when the time comes you will get your rewards. Earning money is a different game that you have to tackle separately. So that’s the final lesson, personal finance!

Manage your personal finances

Even though this is the last point on the list, that doesn’t mean this is the least important item. Surprisingly, a very few will get proper personal financing related education from school or from their parents. Money management is a topic people usually try to avoid.

If you don’t manage your finances properly that affects all the other lessons mentioned above. If you are tight on a budget you’ll try to earn a quick buck rather than hone your skills for the long run. All in all, if you are living from paycheck to paycheck your decision making will get affected. So we must learn to manage our personal finances.

Managing personal finances doesn’t mean collecting money for the sake of it. You should give a purpose for the money you earn. For instance If you like to travel the world what’s the purpose of collecting loads of money if you haven’t traveled the world when you are young and able.

Likewise, you will have different goals in your life. List them down and prioritize. Have a sub goal to get enough financing within a particular period by saving monthly. In essence, you will have a purpose for your savings. And your priorities will change and so will your savings. Always make the rational decision.

By the way, remember to set aside a part of your money for

  • Emergency - Savings that can make you stay afloat for at least two to three months without a job.
  • Giving - For helping others, charity etc. Otherwise you’ll become a cheapskate! Trust me on this! :) By the way this doesn’t have to be a lot.

Following are some pointers that will get you started on the subject.

  • Envelop method - you can follow this using a spreadsheet.
  • YNAB- its a personal budgeting method. Learn it!
  • Save at least 10% of the salary for one of your investment plans

Following are some good books on the subject.

  • YNAB book by Jesse Mecham - the book that explains the YNAB principles in detail.
  • Richest man in Babylon by George S. Clason
  • Think and Grow Rich by Napoleon Hill
  • Rich Dad Poor Dad - One of the famous books on becoming financially free. I don’t agree with all the things Kiyosaki states. Take his advice with a grain of salt. Keep your morality intact.

All the above lessons revolves around one thing, your purpose of life. Try to align all the lessons with your purpose, your end goal!

So that’s my five lessons. Those five lessons played a major role in the first five years of my career. Hope this will help yours too.

Cheers!

Written by Asitha Nanayakkara

There are several ways to retrieve query parameters from an HTTP request using WSO2 ESB.

  • Using Synapse XPath $url variable
  • Using get-property(‘query.param.xxx’)

We can use the following curl GET request for the following sample API

$ curl “http://localhost:8280/store/view?name=john&age=29” -v

Using Synapse $url XPath variable

There is an XPath variable $url which we can use to retrieve query parameters from an HTTP request.

<property name=”name” expression=”$url:name” type=”STRING”/>

Following is an example using the $url. Note that you don’t have to mention the query params in the uri-template

Using get-property(‘query.param.xxx’)

Another option is to use the get-property function with argument as query.param. where **value** is the relevant name of the query parameter

get-property(‘query.param.name’)

Example API with get-property function

Sample curl rquest and response

$ curl “http://localhost:8280/store/view?name=john&age=29” -v

*   Trying 127.0.0.1...
* Connected to localhost (127.0.0.1) port 8280 (#0)
> GET /store/view?name=john&age=29 HTTP/1.1
> Host: localhost:8280
> User-Agent: curl/7.50.1
> Accept: */*
> 
< HTTP/1.1 200 OK
< Accept: */*
< Host: localhost:8280
< Content-Type: application/x-www-form-urlencoded; charset=UTF-8
< Date: Sun, 13 Aug 2017 14:40:01 GMT
< Transfer-Encoding: chunked
< 
* Connection #0 to host localhost left intact
<user><name>john</name><age>29</age></user>

You can test this out with WSO2 Integrator which is the WSO2 ESB product packaged with other integration products like WSO2 Message Broker, WSO2 Business Process Engine and WSO2 Data Services Server.

Cheers!

Written by Asitha Nanayakkara

This post describes how to check whether the current node is the leader node of an ESB cluster. An example use-case of using this property is to write a cluster aware scheduled task in WSO2 ESB.

While writing a proxy service or a sequence, there might be an instance where you want only one ESB node to do a particular task. In that case, we can use the leader node in the cluster or try to get hold of a cluster-wide lock (using a DB based solution or Hazelcast). This blog post explains how to achieve this using Hazelcast leader node.

Hazelcast Leader node

WSO2 carbon server which WSO2 ESB is built upon uses Hazelcast as the cluster coordination implementation. In Hazelcast, there is a mechanism to reliably get the leader node of a cluster. Only one node in a cluster at a given time becomes the leader node. We can use this property of Hazelcast within WSO2 ESB using either a script mediator or a class mediator to get the leader node.

Retrieving leader with a Class mediator

Following is a Java code snippet to get the leader node of a Hazelcast cluster. We can use this within a class mediator to get the leader node of the ESB cluster.

You can follow this guide to write your own class mediator.

Retrieving leader with a Script Mediator

We can use the same Java code with some modifications within the script mediator as well. This option is much easier to implement and deploy in an ESB cluster.

Use case

One of the use cases of this property is to create a cluster aware scheduled task in WSO2 ESB.

Up to ESB 4.8.1 scheduled tasks cannot be controlled to be scheduled only in a single node at a time. The only option is to use pinned servers, but this has a single point of failure.

Even though the scheduled tasks deployed in the cluster injects a message to each proxy or sequence in the cluster, we can make only one proxy service to mediate the message by evaluating the leader node property as mentioned above.

Hope this is useful to someone.

Cheers!

Written by Asitha Nanayakkara

With ESB 4.9.0 release we can achieve this directly using the property mediators registry scope.

In WSO2 ESB 4.8.1 there is no direct way to save content to registry through stock synapse mediators. This post describes two possible options we have with ESB 4.8.1 to save content to the registry. Those are by using either the Script Mediator or the Class Mediator.

Following examples shows how to store the value of property myProperty of type String in message context into the registry path conf:/store/myStore

Script Mediator

Achieving this with script mediator is relatively easy. Note that using the script mediator will have some performance impact on your mediation logic.

Here is a sample code snippet of a script mediator to save the value stored under myProperty in message context to the registry.

Class Mediator

First of all, you need to create a class mediator. You can follow this guide to write your own class mediator. After that what you need is to write some Java code similar to following to store the content into the registry.

Retrieve content

To retrieve the stored content you can simply use the get-property XPath function with registry scope as follows.

<property name="regContent"
          expression="get-property('registry', 'conf:/store/myStore')"/>

Cheers!

Written by Asitha Nanayakkara

There are lot of architectural changes in WSO2 Message Broker (MB) 3.0.0. We can fairly say its totally different in terms of the architecture compared to WSO2 MB 2.2.0. All these changes were done to improve performance and give more flexibility to the end user.

One of the key features that’s introduced with MB 3.0.0 is its RDBMS support. Previously it was all about Cassandra. Whether you like it or not If you are using MB you had to stick with Cassandra. With MB 3.0.0 you can connect MB to either Cassandra (Either with Hector or CQL), MySQL, MS-SQL, Oracle, PostgresSQL or H2 data store.

Design

In MB, core functionality is handled by Andes. Andes is protocol independent and is cluster aware. MQTT and AMQP protocol implementations talks to Andes to get its work done. Andes mainly uses two data stores for data persistence. They are AndesContextStore and MessageStore.

Note:

  • MessageStore is an interface in MB. All messages related persistence tasks (message storing/retrival/deletion) are handled by classes implementing this interface.
  • AndesContextStore is an interface in MB. Tasks that are not directly related to messages (create/retrieve/delete queues, exchanges etc) but need to be persisted are handled by classes implementing this interface.

By way of AndesContextStore and MessageStore interfaces, in MB 3.0.0, tight coupling between specific Database Management System (DBMS) and Andes is removed. Therefore supporting a new DBMS is a matter of implementing a class with specific DBMS related implementation and configuring MB to use that implementation at start-up.

Following is the class diagram of MB 3.0.0 that comes with specific implementation for several DBMS types

UML class diagram of DBMS design

RDBMS related implementations are written using ANSI SQL so that it can be used with many RDBMS’s. This includes MS-SQL, Oracle, MySQL, PostgresSQL, H2.

Extension points

With this new design there is an option to write custom RDBMS or any DBMS specific store and plug it to MB. For instance you can write custom classes implementing AndesContextStore and MessageStore interfaces to harness performance gaines by using specific SQL statements supported by a given database.

Written by Asitha Nanayakkara