Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: add websocket support #395

Merged
merged 1 commit into from
Sep 11, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ PYTHON_VERSION_MAJOR:=$(shell $(PYTHON) -c "import sys;print(sys.version_info[0]
PLATFORM := $(shell uname)
VERSION :=$(shell poetry version | sed 's/stomp.py\s*//g' | sed 's/\./, /g')
SHELL=/bin/bash
ARTEMIS_VERSION=2.22.0
ARTEMIS_VERSION=2.23.1
TEST_CMD := $(shell podman network exists stomptest &> /dev/null && echo "podman unshare --rootless-netns poetry" || echo "poetry")

all: test install
Expand Down Expand Up @@ -48,7 +48,7 @@ release: updateversion

docker/tmp/activemq-artemis-bin.tar.gz:
mkdir -p docker/tmp
wget http://www.apache.org/dist/activemq/activemq-artemis/${ARTEMIS_VERSION}/apache-artemis-${ARTEMIS_VERSION}-bin.tar.gz -O docker/tmp/activemq-artemis-bin.tar.gz
wget http://www.apache.org/dist/activemq/activemq-artemis/${ARTEMIS_VERSION}/apache-artemis-${ARTEMIS_VERSION}-bin.tar.gz -O $@ || rm $@


ssl-setup:
Expand Down Expand Up @@ -77,7 +77,7 @@ docker-image: docker/tmp/activemq-artemis-bin.tar.gz ssl-setup


run-docker:
docker run --add-host="my.example.com:127.0.0.1" --add-host="my.example.org:127.0.0.1" --add-host="my.example.net:127.0.0.1" -d -p 61613:61613 -p 62613:62613 -p 62614:62614 -p 63613:63613 -p 64613:64613 --name stomppy -it stomppy
docker run --add-host="my.example.com:127.0.0.1" --add-host="my.example.org:127.0.0.1" --add-host="my.example.net:127.0.0.1" -d -p 61613:61613 -p 62613:62613 -p 62614:62614 -p 63613:63613 -p 64613:64613 -p 15674:15674 --name stomppy -it stomppy
docker ps
docker exec -it stomppy /bin/sh -c "/etc/init.d/activemq start"
docker exec -it stomppy /bin/sh -c "/etc/init.d/stompserver start"
Expand All @@ -100,7 +100,7 @@ podman-image: docker/tmp/activemq-artemis-bin.tar.gz ssl-setup

run-podman:
podman network create --ipv6 --subnet 172.17.0.0/24 --subnet fddf:aaaa:bbbb:cccc::/64 stomptest
podman run --network stomptest:ip=172.17.0.2 --add-host="my.example.com:127.0.0.1" --add-host="my.example.org:127.0.0.1" --add-host="my.example.net:127.0.0.1" -d -p 61613:61613 -p 62613:62613 -p 62614:62614 -p 63613:63613 -p 64613:64613 --name stomppy -it stomppy
podman run --network stomptest:ip=172.17.0.2 --add-host="my.example.com:127.0.0.1" --add-host="my.example.org:127.0.0.1" --add-host="my.example.net:127.0.0.1" -d -p 61613:61613 -p 62613:62613 -p 62614:62614 -p 63613:63613 -p 64613:64613 -p 15674:15674 --name stomppy -it stomppy
podman ps
podman exec -it stomppy /bin/sh -c "/etc/init.d/activemq start"
podman exec -it stomppy /bin/sh -c "/etc/init.d/stompserver start"
Expand Down
3 changes: 3 additions & 0 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ RUN apt update && apt install -y \

# rabbitmq setup
RUN rabbitmq-plugins enable rabbitmq_stomp
RUN rabbitmq-plugins enable rabbitmq_web_stomp
RUN echo "stomp.listeners.tcp.1 = 172.17.0.2:61613" > /etc/rabbitmq/rabbitmq.conf
RUN echo "loopback_users = none" >> /etc/rabbitmq/rabbitmq.conf

Expand Down Expand Up @@ -63,5 +64,7 @@ EXPOSE 62614/tcp
EXPOSE 62619/tcp
EXPOSE 63613/tcp
EXPOSE 64613/tcp
EXPOSE 15674/tcp


ENTRYPOINT /bin/bash
171 changes: 40 additions & 131 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ packages = [
[tool.poetry.dependencies]
python = "^3.6"
docopt = "^0.6.2"
websocket-client = "^1.2.3"

[tool.poetry.dev-dependencies]
pytest = ">=5.2"
Expand Down
2 changes: 2 additions & 0 deletions stomp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@
#
Connection12 = connect.StompConnection12
StompConnection12 = Connection12
Connection12WS = connect.StompConnection12WS
StompConnection12WS = Connection12WS

##
# Default connection alias (STOMP 1.1).
Expand Down
36 changes: 36 additions & 0 deletions stomp/connect.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,3 +213,39 @@ def disconnect(self, receipt=None, headers=None, **keyword_headers):
@staticmethod
def is_eol(c):
return c == b"\x0a" or c == b"\x0d\x0a"


class StompConnection12WS(StompConnection12):
"""
Represents a 1.2 connection (comprising transport plus 1.2 protocol class).
See :py:class:`stomp.transport.Transport` for details on the initialisation parameters.
"""
def __init__(self,
host_and_ports=None,
prefer_localhost=True,
try_loopback_connect=True,
reconnect_sleep_initial=0.1,
reconnect_sleep_increase=0.5,
reconnect_sleep_jitter=0.1,
reconnect_sleep_max=60.0,
reconnect_attempts_max=3,
timeout=None,
heartbeats=(0, 0),
keepalive=None,
vhost=None,
auto_decode=True,
encoding="utf-8",
auto_content_length=True,
heart_beat_receive_scale=1.5,
bind_host_port=None,
ws=None,
ws_path=None,
header=None):
transport = WSTransport(host_and_ports, prefer_localhost, try_loopback_connect,
reconnect_sleep_initial, reconnect_sleep_increase, reconnect_sleep_jitter,
reconnect_sleep_max, reconnect_attempts_max, timeout,
keepalive, vhost, auto_decode, encoding, bind_host_port=bind_host_port,
header=header, ws_path=ws_path)
BaseConnection.__init__(self, transport)
Protocol12.__init__(self, transport, heartbeats, auto_content_length,
heart_beat_receive_scale=heart_beat_receive_scale)
Loading