http://coldfusion.com logo
#cfml-general
Title
# cfml-general
r

Ryan Albrecht

03/22/2022, 1:40 PM
anyone have any experience in getting coldfusion to ingest MQTT messages?
r

ryan

03/22/2022, 1:55 PM
I have not done this, but it seems like you might be able to use cfwebsockets to consume MQTT messages, possibly. I think you would have to change or add a port in order for the websocket to listen.
s

sknowlton

03/22/2022, 1:58 PM
Rabbit supports MQTT via a plugin. Could use that and Ortus' Rabbit module which is really easy
although I guess if you're only ingesting, that wouldn't work if they're not coming from a Rabbit server
r

Ryan Albrecht

03/22/2022, 3:12 PM
@ryan I mean ingesting on server side.
@sknowlton thanks! i didnt know about the ortus rabbit module
looks promising
s

sknowlton

03/22/2022, 3:14 PM
We have a Commandbox task runner that uses it based on a template Brad gave me. Happy to share
Or Brad can probably share the same template, his is a little more generic and has examples of things we didn't need but you might
r

Ryan Albrecht

03/22/2022, 3:26 PM
That would be super helpful. Thanks
s

sknowlton

03/22/2022, 3:34 PM
(those should both be cfcs, not .txt)
the rabbitMQ one extends the base task. there's stuff in there you can remove that was specific to Brad's client
We chopped basetask down to what we needed and edited rabbitMQ to hit our API instead of triggering child task runners as the example does
r

Ryan Albrecht

03/22/2022, 3:37 PM
Thanks, I will check this investigate and see if I can come up with a solution
Update: I found this to be quite easy. Using eclipse Paho
Copy code
mqttUrl = '<tcp://plc.thingythongy.com:1883>';
mqttClientId = 'test_client';
mqttCallback = new com.system.mqtt.MqttMessage(application);
pClient = createObject( "java", "org.eclipse.paho.client.mqttv3.MqttClient" ).init(mqttUrl, mqttClientId);
pClient.setCallback(mqttCallback);
pClient.connect();
pClient.subscribe('iotgateway');
Copy code
MqttMessage.cfc

component implements="java:org.eclipse.paho.client.mqttv3.MqttCallback" {

	public function init(any applicationScope){
		variables.applicationScope = arguments.applicationScope;
	}

	public any function messageArrived(string topic, any message){
		var msgStruct = deserializeJSON(message.toString());
		variables.applicationScope.iotgatewayData = msgStruct;
	}

	public any function connectionLost(any cause){
	}

	public any function deliveryComplete(any token){
	}

}
2 Views