3.3: Message: Publish, Subscribe and Topic
Created by ppatierno on 11/11/2013 5:56:09 PM

Message:  Publish, Subscribe and Topic

MQTT protocol is based on “Publish/Subscribe” pattern and “topic” concept. A client can be a publisher, a subscriber or both. If it is a publisher, it publishes a message on a topic; if it is a subscriber, it subscribes to a specific topic so that it can receive all the messages published on that topic. The topic is the mechanism by which clients exchange messages and technically it is a message queue; the broker have to manage all subscriptions to the queues (topics) and it have to relay messages from clients publishing messages to a certain topic to those who are subscribed to it. This pattern is also known as “Observer” because a client can observe a topic for which it is interested in receiving published messages. This model allows one-to-one and one-to-many distribution and the publisher don’t need to know anything about the subscribers; all these features guarantee clients decoupling and asynchronous communication.

Fig3.3

Figure 3.3 : Topic based Publish/Subscribe pattern in MQTT

A subscription can be durable or not-durable. If it is durable, the broker relays a message to a subscribed client immediately if it is connected or it stores the message until the next time the subscriber connects. If the subscription is non-durable, the broker relays a message only if the subscriber is connected, otherwise it loses the message. This choice is made when the client connects to the broker using a “clean session flag” inside connection message : if the flag is set to true then all client’s subscriptions are removed when client disconnect (not-durable subscription); instead, if the flag is set to false then all subscriptions remain active even when the client disconnects (durable subscription). Furthermore, a publisher can mark a message as “retained” so that the broker can send the last known good message to new subscribers so that they don’t have to wait for a publisher publishes a message to receive the first message after connection to the broker. Finally, when a client connects to the server, it can specify a “will” message that the broker will have to publish to a specific topic in case of unexpected disconnection.

 

print
  Comments


Turkish porno izle video site in rokettubeporno izle