我在服务器端执行了ActiveMQ配置,基本上是在websocket上sto脚。是否可以通过任何现有的Python库连接并开始使用队列中的消息?还是我想念的东西?
<transportConnector name="websocket" uri="ws://0.0.0.0:31614?maximumConnections=1000&wireFormat.maxFrameSize=104857600" />
我尝试了多个python(stomp.py,最笨拙),但是我无法连接到代理。在服务器端,这被视为:
broker-amq 2018-10-28 18:18:09,130 | WARN | badMessage: 400 No URI for HttpChannelOverHttp@35c228e5{r=0,c=false,a=IDLE,uri=} | org.eclipse.jetty.http.HttpParser | qtp428039780-131
我使用stomp.py的实现:
class QueueListener(stomp.ConnectionListener):
def __init__(self, queueConnector):
self.connector = queueConnector
def on_error(self, headers, message):
self.connector.add_error(message)
def on_message(self, headers, message):
self.connector.add_message(message)
class AMQHandler:
def __init__(self):
self.connection = None
self.queue = None
self.messages = []
self.errors = []
self.listener = QueueListener(self)
def connect_to_broker(self, host, port, user, password):
if self.connection != None:
print "Old connection still active! Closing it..."
self.disconnect_broker()
self.connection = stomp.connect.StompConnection12(host_and_ports=[(host, port)])
self.connection.set_listener('', self.listener)
self.connection.start()
self.connection.connect(username=user, passcode=password, wait=False, headers=None)
connector = AMQHandler()
connector.connect_to_broker("brokeraddress", 31614, "someone@somewhere.com", "xxxxx")
我使用stompest.py的实现:
CONFIG = StompConfig('tcp://brokeraddress:31614', version=StompSpec.VERSION_1_2)
QUEUE = '/queue/test'
client = Stomp(CONFIG)
client.connect(headers={'passcode': 'xxxxx', 'login': 'someone@somewhere.com'})
client.connect()
client.subscribe(QUEUE, {StompSpec.ACK_HEADER: StompSpec.ACK_CLIENT_INDIVIDUAL})
while True:
frame = client.receiveFrame()
print('Got %s' % frame.info())
client.ack(frame)
client.disconnect()