Discussing the article: "Developing an MQTT client for MetaTrader 5: a TDD approach — Part 2"

 

Check out the new article: Developing an MQTT client for MetaTrader 5: a TDD approach — Part 2.

This article is part of a series describing our development steps of a native MQL5 client for the MQTT protocol. In this part we describe our code organization, the first header files and classes, and how we are writing our tests. This article also includes brief notes about the Test-Driven-Development practice and how we are applying it to this project.

Building conformant MQTT packets is only the first step in the process of writing a robust and maintainable client. The easiest part, as to say. When it comes to the Operational behavior specification all the complexities of the protocol will emerge. This complexity will demand more of our job as developers. Besides sending good packets, we will be required to deal with a large number of different server responses and different application states. At this point, hardcoded byte arrays – or anything hardcoded for this matter – will not be enough.

Fortunately, MQL5 is an object-oriented programming language and we are not working in the memory/CPU-constrained environment for which MQTT was originally designed. So we can leverage all the benefits of the object-oriented (OOP) paradigm in order to have:

  • Easy reasoning about the protocol by choosing the right abstraction level
  • Easy code reading (remember that code is read many more times than it is written)
  • Easy code maintenance,
  • And easy testing


Now we can run our Mosquitto local broker on WSL to check if our MQTT connection was successful.

If you have followed the default installation, Mosquito should be running as a Service on Linux. Thus you only need to ‘redir’ the ports (80 → 1883) and include the hostname on allowed URLs in your Metatrader 5 options.

Fig. 03 - WSL Mosquitto Log Connected/Disconnected Success

    Author: Jocimar Lopes