Use Processing and the processing-mqtt library to publish and subscribe using MQTT.
import mqtt.*;
MQTTClient client;
void setup() {
client = new MQTTClient(this);
client.connect("mqtt://public:public@public.cloud.shiftr.io", "processing");
client.subscribe("hello");
}
void draw() {}
void keyPressed() {
client.publish("hello", "world");
}
void messageReceived(String topic, byte[] payload) {
println( topic + ": " + new String(payload));
}
For more information see the Processing manual in the documentation.