Rules VS command through MQTT

I use openHAB 2.1 with MQTT Bindings.
I use MQTT message to set up my ESP8266 object (I put a custom code on this) but I read there is “somethings” call rules : what is the difference?
When do I need use rules are preferred to MQTT and viceversa? Can anyone explain, maybe with an example?

Thank you very much,

From the docs:

“Rules” are used for automating processes: Each rule can be triggered, which invokes a script that performs any kinds of tasks, e.g. turn on lights by modifying your items, do mathematical calculations, start timers etcetera.

There is no “either or” with Rules. You can have Rules that interact with MQTT Items and you can have MQTT Items that work independently of Rules. It all depends on what you want to do.

For example, if you want to turn on a zwave light, raise KNX rollershutter, and start playing a song on a Sonos speaker in response to an MQTT message, you need a Rule for that.

I highly recommend the Beginner’s Tutorial.