Sunday, July 10, 2022

MQTT 筆記

MQTT (MQ Telemetry Transport) MQ stands for IBM product series, but now also stands for Message Queues.

To publish or receive messages, publishers and subscribers only need to know the hostname/IP and port of the broker. (Space Decoupling)

Although most MQTT use cases deliver messages in near-real time, if desired, the broker can store messages for clients that are not online. (Time Decoupling) => In our case, if client is not online, message is dismissed.

Because most client libraries work asynchronously and are based on callbacks or a similar model, tasks are not blocked while waiting for a message or publishing a message. (Synchronization Decoupling)

An MQTT works as a broker which filters message between server and client with (1) subject based filter (hierarchical structurized topics such as navi/itinerary/uuid) (2) content based filter (probably not a good idea) (3) type based filter (OO thinking).

A message queue stores message until they are consumed When you use a message queue, each incoming message is stored in the queue until it is picked up by a client (often called a consumer). => If no suscriber exists, broker could destroy the message and acknowledge to server.

A message is only consumed by one client Another big difference is that in a traditional message queue a message can be processed by one consumer only. => In MQTT, every subscriber that subscribes to the topic gets the message.

Queues are named and must be created explicitly Only after the queue is named and created is it possible to publish or consume messages. => In MQTT, topics are extremely flexible and can be created on the fly. (Not quite sure how on the fly can they be created. Shouldn't publisher and suscriber know the topics beforehead?)

An MQTT client is any device (from a micro controller up to a full-fledged server) that runs an MQTT library and connects to an MQTT broker over a network. => so everyone is client, everyone can be publisher / suscriber, the roll changes according to behavior at the moment.

The broker is responsible for receiving all messages, filtering the messages, determining who is subscribed to each message, and sending the message to these subscribed clients. => seems convenient that broker does it all.

The MQTT protocol is based on TCP/IP.To initiate a connection, the client sends a CONNECT message to the broker. The broker responds with a CONNACK message and a status code. In many common use cases, the MQTT client is located behind a router that uses network address translation (NAT) to translate from a private network address (like 192.168.x.x, 10.0.x.x) to a public facing address. => No problem regarding connection.






No comments: