简体   繁体   English

在PHP中使用Stomp从Kontak io API获取数据

[英]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. 我正在尝试使用Stomp-php( https://github.com/stomp-php/stomp-php )从Kontakt.io API( https://developer.kontakt.io/backend/le/监视/ ),但我在经纪人方面挣扎。 Some documentations speak about using a broker (like activeMQ) with stomp to make it work but i don't really understand why. 一些文档谈到使用带有踩踏功能的代理(例如activeMQ)来使其工作,但我真的不明白为什么。

By using stomp in my front-end, there is no need of such a thing. 通过在我的前端使用stomp,就不需要这样的东西。

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();

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. 有关STOMP的大多数文档都将参考代理,因为在大多数情况下,代理负责从客户端接收消息或向客户端发送消息。 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. 我对Kontact.io并不是很熟悉,但是阅读链接的文档表明Kontact.io本身是您的用例中的“经纪人”。 The STOMP client is connecting to an endpoint exposed by the Kontact.io service. STOMP客户端正在连接到Kontact.io服务公开的端点。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM