Search code examples
javascriptpythonsocketswebsocketstomp

python stomp client - connect to endpoint


I have this stomp client in javascript:

    var socket = new SockJS('/ws-updates');
    stompClient = Stomp.over(socket);
    stompClient.connect({}, function (frame) {
        setConnected(true);
        console.log('Connected: ' + frame);
        stompClient.subscribe('/topic/updates', function (data) { 
            console.log(data);
            showGreeting(data.body);
        });
    });

and I need to replicate this using a Python implementation of Stomp

I found some examples with stomp.py and stomper but they all have this kind of initialization of the connection:

hosts = [('localhost', 1234)]
conn = stomp.Connection(host_and_ports=hosts)

is there a way to create a stomp client object for my custom endpoint (let's say localhost:1234/updates)?

Thanks!


Solution

  • Your JavaScript based STOMP client will use websockets to connect to the broker since it is restricted by the web browser environment where it runs. Python STOMP clients don't have this restriction and will simply use a standard TCP connection. I'm not aware of any Python STOMP clients which support websockets. I recommend you configure your STOMP broker to accept both websocket and normal TCP STOMP connections.