Configuring connections and forwarders

The Amlen Bridge forwards messages from a source MQTT server to a destination MQTT server. You must specify the source and destination connections and forwarders by using the connections.

You do this by creating a topic map. For more information, see Topic mapping.

Connection properties

After the admin endpoint is configured, the configuration can be changed by using REST APIs or by directly updating the configuration file.

MQTT source and MQTT destination can use the same set of properties which are contained in a "Connection" object. Each connection must have a unique name.

For a description of connection object properties, see Configuring the Bridge.

The following example shows the properties of a connection object where an MQTT connection of version 5.0 is defined with name WIoTP:

{ 
    "Connection": {
        	"WIoTP": {
            "MQTTServerList": [ "192.168.26.128:8883" ], /* IP address of the primary */
            "TLS": "TLSv1.2",
            "Version": "5.0",             /* MQTT version */
            "ClientID": "A:x:myapp:Inst", /* v5 shared subscription prefix */
            "SessionExpiry": 0,
            "MaxPacketSize": 64768
	}
    }
}
The Bridge also supports Kafka-like destination connections. It is similar to MQTT-based connections but uses EventStreamsBrokerList instead of MQTTServerList, and does not specify ClientID, SessionExpiry, and Version parameters. The following example shows the format of a Kafka-like destination connection where the destination is an Event Streams broker with the name EventStream:

{
    "Connection": {
        "EventStream": {
            "EventStreamsBrokerList": [ "192.168.26.128:9093" ],  
            "TLS": "TLSv1.2",
	}
    }
}
Note: When TLS is enabled and a self-signed remote server certificate is used, you must set up a local Certificate Authority certificate file with the suffix .pem or .crt in the /var/imabridge/truststore directory. You must also run the c_rehash program in the /var/imabridge/truststore directory to ensure that the base name of the CA file reflects the hash value of its content, which is required for basic security.

Forwarder properties

Forwarder properties use the source and destination connection definitions to specify the Bridge. Two useful features are messaging filtering and the ability to define the message topic mapping to automatically handle the topic difference between the source message and destination message. The following example shows the forwarder defined with name m2w:

{ 
    "Forwarder": {
        "m2w": {
            "Topic": ["wiotp/event/+/+/MyEvent/#"],
            "Enabled": true,
            "Source": "MyServer",
            "Destination": "WIoTP",
            "TopicMap": "iot-2/type/${Topic2}/id/${Topic3}/evt/${Topic4}/fmt/json"
        }
    }
}

For a description of forwarder object properties, see Configuring the Bridge.

In the previous section, source connection MyServer and destination connection WIoTP are defined. Forwarder m2w is defined based on the connections to filter the message and map the topic.

Using admin REST APIs

The admin REST APIs can be used to configure connections and forwarders. You can create a connection as follows:
curl  -u "admin:admin" -X POST -k --data '{"Connection": {"WIoTP": 
{ "MQTTServerList": [ "192.168.26.128:8883" ], "TLS": "TLSv1.2", "Version": "5.0", 
"ClientID": "A:x:myapp:Inst", "SessionExpiry": 0, "MaxPacketSize": 64768} }}'  
"https://localhost:9081/admin/config"

where a connection object with name WIoTP is posted to https://127.0.0.1:9961/admin/config with JSON format. The JSON data structure is the same as the structure in bridge.cfg.

The following example shows how to create a forwarder:
curl  -u "admin:admin" -X POST -k --data '{"Forwarder": 
{ "m2w": { "Topic": ["wiotp"], "Enabled": true, "Source": "MyServer", 
"Destination": "WIoTP",  "TopicMap": "iot-2"  }}}'  
"https://localhost:9081/admin/config"

where a forwarder object with name m2w is posted to https://127.0.0.1:9961/admin/config with JSON format. The JSON data structure is the same as the structure in bridge.cfg.