MQTT in a Nutshell

Posted on Updated on

What is it ?

  • A lightweight, resource-optimized networking protocol targeting device communication
  • uses TCP/IP for connectivity
  • Minimalistic

Why is it cool ?

  • One-to-many message distribution
  • Agnostic to payload content
  • Fixed length header is just 2 bytes
  • Ideal for IOT device-communication

Other Extras

  • Notify disconnections with “Last will and Testament” features
  • Keep-alive message
  • “Will” sent to clients on sudden unexpected disconnect
  • Last known good messages are retained by broker and given to new subscribers
  • Supports durable subscribers
  • Supports hierarchical topics

QoS Parameters

  • At most once – Reliability only ensured through TCP/IP
  • At least once – messages will arrive but can duplicate
  • Exactly once – messages should arrive only once and once. (Most reliable)


  • SSL/TLS for security (over TCP)
  • Username/Password in connect message
  • Encrypted payloads



Hierarchical token matcher for Strings

Posted on

This code was inspired by the following concern :

A message broker needs a way to find all subscribers listening to a destination (including hierarchical subscriptions). A client should be able to subscribe to multiple topics relevant to a given context with a single subscription using this pattern. e.g. To capture all news for all categories for today - can subscribe like "". This sample provides an efficient, abstract way to manage such subscriptions. (inspired by moquette subscription logic) Hierarchy definitions : dest.* - captures all immediate child elements to "dest". dest.# - captures all immediate child elements + parent (e:g: "dest" and "") - captures exactly "" destination - captures "" and ""

Still working on optimizations, so your comments are much valued :)

MongoDB in a Nutshell

Posted on Updated on

*This article does not dive into finer details of mongodb or document databases. that might come in another post ๐Ÿ™‚

Experience and Learning Curve :

Pretty easy to get something running. Flexible. No structure implied in databases other than “collections” and “documents” concepts.

A collection is similar to a table and a document can be defined as a data row in a collection.

Once the database is created from the shell, collections (similar to tables in relational DBs) can be created when entering data itself.

Syntax is intuitive and if you’ve used any kind of databases , simple queries will just work on mongodb ( i tried WHERE clauses with even arrays and it worked on the first attempt. maybe sheer luck :P)

Install on Ubuntu :

Using mongodb with Java :
The functions are almost the same as mongo shell commands. (e:g: db.customer.find() will give u all customers)

Java Objects (even arrays) can be passed straight into mongo queries. They are converted to JSON and used.

I used a set of Object Mapping(OM) classes to communicate with the db and noticed that if the OM class has an “_id” property, it is populated when passing that object as a new “document” to the db.

How to store data :

Basically , theres the two extremes in mongodb where you either can

1. associate objects using only their IDs
2. associate full objects within each other (this causes repetition, but might give u query performance)

Both patterns are used in balance in different scenarios. However, its important to not get addited towards foreign key like associations all the time if you’ve used relational schemas before. it should always be an objective decision.

Basic Security :ย ย

Access MongoDB in Ubuntu with authentication:

First, a user must be created and given admin privileges on the mongo server :

use orderdb
  user: "orderAdmin",
  pwd: "hasd",
    role: "userAdmin",
    db: "orderdb"

Then, that user must be used to open the session :

mongo --port 27017 -u hasd -p hasd --authenticationDatabase admin

This solved my confusion with how to use mongodb with the user permissions. basically , if u just use “mongo”, you might not be able to do somethings u expect u can do. with the default privileges.

Creating an Axis2 Helloworld Service with Maven

Posted on Updated on

What is Axis2 ?

  • A super-cool Java web service container and enabler.
  • Provides extensive support for configuring messaging patterns, deployment, and code generation features like WSDL2Java and Java2WSDL.
  • Takes care of Message parsing with a super-fast Object model (AXIOM)
  • More info : (Axis2 in a Nutshell post – coming soon)

How to create a HelloWorld Service :

Maven has and will be my favourite build manager in Java.ย  And when it comes to Setting up a simple Axis2 Web Service, it doesnโ€™t disappoint .

Pre-requisites :

  • Java
  • Maven
  • A Servelet Container – Tomcat7 (Optional)

Steps to generate from maven archetype :

1. Choose where you want to create the project and navigate to that directory. (If in windows -> CMD. If in Linux -> Terminal)

2. Call for the maven axis2 archetype with following command.

mvn archetype:generate -DarchetypeCatalog=

2. Fill out the information required by maven to create your project as follows. The values are totally up to you. (e:g: project name, package containing the axis2 services)

Screenshot from 2014-04-29 13:08:07

Confirm with “Y” and Voila!! You have an axis2 service that by default runs on an in-built jetty server. (port:8080)

Maven will at this point create a complete project for you with all required axis2 dependencies as well as extra libraries needed for hosting the service in something like Jetty. Refer the generated “pom.xml” file to realize the different components that make the service work.

All hail archetypes.


So, okay. You have the service and its runnable in a jetty server. But to deploy it in an existing axis2 container, you need to generate the .aar (Axis2 archive) file from the project. The following maven command will create it at the “target” folder.

mvn axis2-aar:aar



There you go. Axis2 Web Services : check ๐Ÿ™‚