Gregory Koronakos c504f94705 rank node candidates
Change-Id: I260f8105cdd675d9475a9179149a445c4f56fa17
2024-03-20 01:27:00 +02:00

53 lines
1.2 KiB
Python

import datetime
import logging
from proton import Message,AnnotationDict
from . import link
_logger = logging.getLogger(__name__)
class Publisher(link.Link):
def send(self, body=None, application=None, properties=None, raw=False):
if not body:
body = {}
_logger.info(f"[{self.key}] sending to {self._link.target.address} for application={application} - {body} "
f" properties= {properties}")
msg = self._prepare_message(body,properties=properties, raw=raw)
if application:
msg.subject = application
msg.properties={
'application': application
}
self._link.send(msg)
def _prepare_message(self, body=None, properties=None, raw=False):
send = {}
if not body:
body = {}
if not raw:
send = {"when": datetime.datetime.utcnow().isoformat()}
send.update(body)
msg = Message(
address=self._link.target.address,
body=send
)
if properties:
if 'correlation_id' in properties:
msg.correlation_id=properties['correlation_id']
msg.content_type = 'application/json'
return msg