34 lines
698 B
Python
34 lines
698 B
Python
import datetime
|
|
import logging
|
|
|
|
from proton import Message
|
|
|
|
from . import link
|
|
|
|
_logger = logging.getLogger(__name__)
|
|
|
|
|
|
class Publisher(link.Link):
|
|
|
|
def send(self, body=None):
|
|
if not body:
|
|
body = {}
|
|
|
|
_logger.debug(f"{self.address} Sending {body} ")
|
|
msg = self._prepare_message(body)
|
|
self._link.send(msg)
|
|
|
|
def _prepare_message(self, body=None):
|
|
|
|
if not body:
|
|
body = {}
|
|
|
|
send = {"when": datetime.datetime.utcnow().isoformat()}
|
|
send.update(body)
|
|
msg = Message(
|
|
address=self._link.target.address,
|
|
body=send
|
|
)
|
|
msg.content_type = "application/json"
|
|
return msg
|