Uses 1103K of libraries. Click here for Pure Java version (1908L/11K).
!7 lib 1400324 // Eclipse Paho (MQTT) import org.eclipse.paho.client.mqttv3.*; cmodule MQTTSubscriberSpike > DynPrintLog { switchable S topic = "iot_data"; transient MqttClient client; start-thread { client = new MqttClient("tcp://localhost:1883", MqttClient.generateClientId()); client.setCallback(new MyCallback); client.connect(); client.subscribe(topic); print("Connected & subscribed to " + topic); } void cleanMeUp_mqtt ctex { if (client != null) { client.disconnect(); client.close(); } } class MyCallback implements MqttCallback { public void connectionLost(Throwable throwable) enter { print("Connection to MQTT broker lost!"); } public void messageArrived(S s, MqttMessage mqttMessage) enter { print("Message received: "+ fromUtf8(mqttMessage.getPayload())); } public void deliveryComplete(IMqttDeliveryToken token) enter { print("Delivery complete: " + token); } } }
download show line numbers debug dex old transpilations
Travelled to 7 computer(s): bhatertpkbcr, mqqgnosmbjvj, pyentgdyhuwx, pzhvpgtvlbxg, tvejysmllsmz, vouqrxazstgt, xrpafgyirdlv
No comments. add comment
| Snippet ID: | #1026859 | 
| Snippet name: | MQTT Subscriber Spike | 
| Eternal ID of this version: | #1026859/8 | 
| Text MD5: | 5f010e47ba3611f85d8919d5813fc385 | 
| Transpilation MD5: | 14eae3d161fb3b9c325bfdbc72a1eb2a | 
| Author: | stefan | 
| Category: | javax / mqtt | 
| Type: | JavaX source code (Dynamic Module) | 
| Public (visible to everyone): | Yes | 
| Archived (hidden from active list): | No | 
| Created/modified: | 2020-01-29 14:36:43 | 
| Source code size: | 1029 bytes / 39 lines | 
| Pitched / IR pitched: | No / No | 
| Views / Downloads: | 489 / 1618 | 
| Version history: | 7 change(s) | 
| Referenced in: | [show references] |