I am trying to exchange binary messages between two Python STOMP clients.
Message sending and receiving have no issues. However, there are always a few bytes (seems random) missing on the receiver.
The same messages are received in whole by C++ clients. No issue either when ASCII text are sent.
What am I missing?
Publisher:
import random
import string
import time
import sys
import stomp
import os
hosts = [('localhost', 61613)]
conn = stomp.Connection(host_and_ports=hosts)
conn.connect('admin', 'admin', wait=True)
while 1:
b = bytes(os.urandom(100))
#b = ''.join(random.choices(string.ascii_lowercase, k=1500))
print(len(b))
conn.send(content_lengh=len(b), body=b, destination='/queue/test')
time.sleep(2)
conn.disconnect()
Subscriber:
import time
import sys
import stomp
class MyListener(stomp.ConnectionListener):
def on_error(self, frame):
print('received an error "%s"' % frame.body)
def on_message(self, frame):
print(type(frame.body))
print('received message len = "%s"' % len(frame.body))
conn = stomp.Connection()
conn.set_listener('', MyListener())
conn.connect('admin', 'password', wait=True)
conn.subscribe(destination='/queue/test', id=1, ack='auto')
print("Waiting for messages...")
while 1:
time.sleep(10)
conn.disconnect()
I figured it out myself by tracing STOMP. The subscriber needs to disable auto decode as shown below. Otherwise, the frame body will be decoded as UTF-8.
conn = stomp.Connection(auto_decode=False)