Information coming from units is remodeled in Hono to a uniform message format by protocol adapters (e.g. there are some for MQTT, HTTP, and CoAp) and handed to a messaging system. Enterprise functions learn these messages, that are both telemetry messages or occasions, straight from the messaging system (they will additionally use Command and Management to ship messages to units and obtain responses). For messaging, which isn’t a part of Hono however should be supplied externally, the AMQP 1.0 protocol has been used to this point.
Since model 1.7, Hono helps Apache Kafka for messaging as a technical preview. A key function of Hono is the definition and implementation of APIs for forwarding messages to and from a messaging system. Because the API definitions are based mostly on messaging and rely straight on its properties, supporting a brand new messaging system is a elementary innovation for Hono. For all messaging APIs in Hono (telemetry, occasion, and command and management), new specs based mostly on Kafka had been created, each dealing with the protocol adapter in addition to the enterprise software. Care was taken to make sure that they behave as equally as potential to the AMQP-based APIs.
Apache Kafka is a distributed event-streaming platform designed for very excessive throughput whereas offering sure ensures within the order of messages. It’s a nice match for Hono’s necessities concerning messaging for a number of causes. Key advantages are:
- Scaling: A number of Kafka servers are operated concurrently as a cluster that may be expanded as wanted. Kafka is optimized to permit many processes to write down and browse information concurrently. With AMQP 1.0, a number of processes may also eat messages from the identical handle in parallel. Nevertheless, meaning they lose their order.
- Message ordering: Certainly one of Kafka’s core options is the partitioning of information via a partition key, which can be utilized to pick out information for which the order should be maintained and information which may be processed in parallel. In Hono, this permits us to simply be sure that all occasions from a tool are supplied to the enterprise software within the right order. The telemetry information of the system may be processed in parallel, and its order can be assured. Messages from all different units may be consumed in parallel, fully independently, even in a number of cases of the enterprise software getting used concurrently.
- Broad-scale adoption: Kafka is utilized by a lot of corporations and is supported by many different applied sciences. A number of corporations supply Kafka as a service that may be booked on varied cloud platforms. This makes it simple to supply Hono with a professionally operated messaging system. Vendor lock-in can be prevented.
AMQP 1.0 is a communication protocol the place friends join with one another to trade messages. In distinction, a Kafka cluster consists of brokers that coordinate the writing (and studying) of information to everlasting storage. This distinction has two penalties: First, a message is on the market for retrieval for some time earlier than it’s finally deleted. To attain this impact in Hono with AMQP, you sometimes present a separate message dealer the place occasions are saved to keep away from message loss ought to the enterprise software be quickly unavailable. With Kafka, each message is saved. This contains telemetry messages (the storage time, nonetheless, will depend on the configuration of the telemetry matters within the Kafka cluster). Secondly, speaking by way of everlasting storage decouples the ship and obtain operations from one another: The protocol adapter can now not report again to the system if there may be presently no client related. As an alternative, it merely shops the messages with out “realizing” if or when a enterprise software will learn them.
Making an attempt it out
When putting in Hono, it is advisable to deploy both an AMQP messaging community or a Kafka cluster. There may be additionally the opportunity of configuring Hono to make use of each messaging methods. Then, every tenant (a subset of units and configuration) may be configured to make use of both AMQP or Kafka. The Hono venture gives a publicly accessible sandbox environment on the Web the place you may experiment with Hono utilizing AMQP or Kafka-based messaging.
Within the following, we stroll you thru a small instance of how one can use Apache Kafka-based messaging within the Hono sandbox. You’ll ship a telemetry message to the HTTP protocol adapter after which learn it from the Kafka cluster.
We simulate an Web-enabled system by sending HTTP instructions from the command line. For this, we use the favored open-source software curl. If presently not put in in your laptop, please discuss with the set up directions on the curl homepage. To simulate the enterprise software, we use Hono’s command-line consumer, which may be downloaded from the Hono download page. Please notice that Java should be put in in not less than model 11 as a way to run it.
If any of the instructions proven beneath don’t work (which might all the time occur with such directions), please discuss with the Kafka Messaging Guide the place the reasons cowl extra particulars.
Registering a tool
First, it is advisable to create a brand new tenant within the sandbox to keep away from interfering with different customers. The next command creates a tenant with a random ID and configures it to make use of Kafka for messaging.