phpstompkontakt.io

Using Stomp in PHP to get data from kontak io API


I'm trying to use Stomp-php (https://github.com/stomp-php/stomp-php) to fetch the data from Kontakt.io API (https://developer.kontakt.io/backend/le/monitoring/) but i'm struggling about the broker part. Some documentations speak about using a broker (like activeMQ) with stomp to make it work but i don't really understand why.

By using stomp in my front-end, there is no need of such a thing.

Any idea of how does this work ? Thanks

Just in case, my code :

    // make a connection
    $stomp = new Stomp\StatefulStomp(
        new Stomp\Client('wss://ovs.kontakt.io:9090/stream?apiKey=key')
    );

    // send a message to the queue
    //$message =  new Stomp\Transport\Message(null, array('api-key','key'));

    // subscribe to the queue
    $stomp->subscribe('/presence/stream/gw');

    // receive a message from the queue
    $msg = $stomp->read();
    // do what you want with the message
    if ($msg != null) {
        echo "Received message with body '$msg->body'\n";
        // mark the message as received in the queue
        $stomp->ack($msg);
    } else {
        echo "Failed to receive a message\n";
    }
    $stomp->unsubscribe();

Solution

  • Most documentation about STOMP would refer to a broker because in most situations the broker is responsible for receiving and dispatching messages from/to clients. I'm not really familiar with Kontact.io, but reading the documentation you linked indicates that Kontact.io itself is serving as the "broker" in your use-case. The STOMP client is connecting to an endpoint exposed by the Kontact.io service.