Using the MQTT Adapters
This chapter describes the behavior of the MQTT inbound and outbound adapters, EnsLib.MQTT.Adapter.InboundOpens in a new tab and EnsLib.MQTT.Adapter.OutboundOpens in a new tab and how to use them in custom business services and operations.
MQTT Inbound Adapter
The MQTT inbound adapter is responsible for subscribing to messages on the broker and then receiving messages from the subscription. The inbound adapter does the following:
Creating a Business Service Using the MQTT Inbound Adapter
To use this adapter in your production, create a new business service class as described here. Later, compile it, add it to a production, and configure it in a similar manner as the passthrough service and operation as described in “Using the MQTT Passthrough Business Service and Operation.” If you need new custom message classes, create them as described in “Defining Messages” in Developing Productions.
The following list describes the basic requirements of the business service class:
For a description of the settings associated with the inbound adapter, see “Configuring and Using the MQTT Passthrough Business Service and Operation” and “Settings for the MQTT Adapter.”
The following example shows the overall structure of your business service class.
Class EMQTT.NewService1 Extends Ens.BusinessService
{
Parameter ADAPTER = "EnsLib.MQTT.Adapter.Inbound";
Method OnProcessInput(pInput As EnsLib.MQTT.Message, pOutput As %RegisteredObject) As %Status
{
set tsc=$$$OK
//your code here
Quit tsc
}
}
MQTT Outbound Adapter
The outbound adapter is responsible for publishing messages to the broker. When the outbound adapter is called with a message, it does the following:
-
It creates a connection to the broker if it does not already have one.
-
If its input parameter includes a value for the topic, it uses it. If the topic is not supplied, it uses the topic specified in the setting.
-
It publishes the message to the broker with the topic from its input parameter or the setting.