|
@@ -2,9 +2,10 @@ import logging
|
|
|
|
|
|
from abc import ABCMeta, abstractmethod
|
|
|
|
|
|
-import stomp
|
|
|
-
|
|
|
from flask import current_app
|
|
|
+from stompest.config import StompConfig
|
|
|
+from stompest.protocol import StompSpec
|
|
|
+from stompest.sync import Stomp
|
|
|
|
|
|
|
|
|
class StompHandler(logging.Handler):
|
|
@@ -17,9 +18,22 @@ class StompHandler(logging.Handler):
|
|
|
'''
|
|
|
def __init__(self, conf):
|
|
|
self.conf = conf
|
|
|
- self.conn = stomp.Connection([(conf['host'], conf['port'])])
|
|
|
- self.conn.start()
|
|
|
- self.conn.connect(conf['username'], conf['password'], wait=True)
|
|
|
+ if self.conf['protocol'] == '11':
|
|
|
+ protocol_v = StompSpec.VERSION_1_1
|
|
|
+ elif self.conf['protocol'] == '12':
|
|
|
+ protocol_v = StompSpec.VERSION_1_2
|
|
|
+ else:
|
|
|
+ protocol_v = StompSpec.VERSION_1_0
|
|
|
+
|
|
|
+ self.conf
|
|
|
+ client_config = StompConfig(
|
|
|
+ 'tcp://{}:{}'.format(self.conf['host'], self.conf['port']),
|
|
|
+ login=self.conf['username'],
|
|
|
+ passcode=self.conf['password'],
|
|
|
+ version=protocol_v
|
|
|
+ )
|
|
|
+ self.conn = Stomp(client_config)
|
|
|
+ self.conn.connect()
|
|
|
|
|
|
return super().__init__()
|
|
|
|
|
@@ -29,5 +43,5 @@ class StompHandler(logging.Handler):
|
|
|
Send the message to the destination endpoint.
|
|
|
'''
|
|
|
self.conn.send(destination=self.conf['destination'],
|
|
|
- body=self.format(record))
|
|
|
+ body=bytes(self.format(record), 'utf-8'))
|
|
|
|