anyone have any experience in getting coldfusion t...
# cfml-general
r
anyone have any experience in getting coldfusion to ingest MQTT messages?
r
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
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 I mean ingesting on server side.
@sknowlton thanks! i didnt know about the ortus rabbit module
looks promising
s
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
That would be super helpful. Thanks
s
(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
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){
	}

}