Kuzzle gives you high control as an open-source portable backend that can be adapted to meet your project requirements and high productivity as a quality assured feature-rich solution that includes versatile SDKs and is readily scalable.
Kuzzle Backend enables live tracking of a set of connected bikes and sends notifications when the bikes enter or exit a specified area.
Read the complete case studyThe first IoT tracking solution carried out this summer showed Bouygues Construction teams that we could integrate different geolocation solutions, display them on a map and use the data in just a few weeks! With Kuzzle, development is no longer a matter of months, but weeks.
Nicolas Lemaire
CEO of Omniscient
// Communication via MQTT
const mqtt = require('mqtt');
try {
// Connect to Kuzzle via MQTT
const client = mqtt.connect({ host: 'kuzzle' });
// Publish a message
client.publish('Kuzzle/request', JSON.stringify({
index: 'myindex',
collection: 'mycollection',
controller: 'realtime',
action: 'publish',
requestId: 'unique_request_id',
body: { some: 'message' }
}));
// Get Kuzzle's response
client.on('message', (topic, raw) => {
const message = JSON.parse(Buffer.from(raw));
// API results topic
if (topic === 'Kuzzle/response') {
// Check if the requestId is the same as for the request we sent
if (message.requestId === 'unique_request_id') {
console.log('Message publication result: ', message);
doSomething(message);
}
}
});
} catch (error) {
console.log(error);
}
public void communicate() {
//Create the mqtt client
MqttClient client = new MqttClient(
"tcp://localhost:1883", //URI
MqttClient.generateClientId(), //ClientId
new MemoryPersistence()); //Persistence
//Connect to Kuzzle
client.connect();
// Listen for the Kuzzle response
client.setCallback(new MqttCallback() {
@Override
public void connectionLost(Throwable cause) {
}
@Override
public void messageArrived(String topic, MqttMessage message) throws Exception {
//Get the Kuzzle response
String payload = new String(message.getPayload());
System.out.println(topic + ": " + payload);
doSomething(payload);
}
@Override
public void deliveryComplete(IMqttDeliveryToken token) {
}
});
//Subscribe to the Kuzzle/response topic
client.subscribe("Kuzzle/response", 1);
//Publish a message to Kuzzle
JSONObject body = new JSONObject()
.put("volatile", "message");
JSONObject payload = new JSONObject()
.put("index", "myindex")
.put("collection", "mycollection")
.put("controller", "real-time")
.put("action", "publish")
.put("requestId", "unique_request_id")
.put("body", body);
client.publish(
"Kuzzle/request", // topic
payload.toString().getBytes("UTF-8"), // payload
2, // QoS
false);
}
func communicate() {
//Connect to Kuzzle
opts := mqtt.NewClientOptions().AddBroker("tcp://localhost:1883")
client := mqtt.NewClient(opts)
if token := client.Connect(); token.Wait() && token.Error() != nil {
handleError(token.Error())
}
var wg sync.WaitGroup
wg.Add(1)
//Subscribe to the Kuzzle/response topic
if token := client.Subscribe("Kuzzle/response", 0, func(client mqtt.Client, msg mqtt.Message) {
if string(msg.Payload()) != "mymessage" {
handleError("unexpected result")
}
//Get the Kuzzle response
doSomething(string(msg.Payload()))
wg.Done()
}); token.Wait() && token.Error() != nil {
handleError(token.Error())
}
//Publish a message to Kuzzle
payload := []byte(`{"index": "myindex", "collection": "mycollection", "controller": "real-time", "action": "publish", "requestId": "unique_request_id", "body": {"volatile": "message"}}`)
if token := client.Publish("Kuzzle/request", 0, false, payload); token.Wait() && token.Error() != nil {
handleError(token.Error())
}
wg.Wait()
}