Skip to content

Commit

Permalink
refs #122331 Add CustomJSONEncoder.
Browse files Browse the repository at this point in the history
  • Loading branch information
Delsin authored and boosterl committed Feb 9, 2024
1 parent d17ea80 commit ab50555
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/amqpstorm_flask/RabbitMQ.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from amqpstorm import UriConnection, AMQPConnectionError
from datetime import datetime
from elody.util import CustomJSONEncoder
from functools import wraps
from hashlib import sha256
from retry.api import retry_call
Expand Down Expand Up @@ -135,9 +136,10 @@ def _publish_to_channel(
debug_exchange: bool = False,
**properties,
):
encoded_body = json.dumps(body, cls=CustomJSONEncoder).encode("utf-8")
if "message_id" not in properties:
properties["message_id"] = sha256(
json.dumps(body).encode("utf-8")
encoded_body
).hexdigest()
if "timestamp" not in properties:
properties["timestamp"] = int(datetime.now().timestamp())
Expand All @@ -153,7 +155,7 @@ def _publish_to_channel(
self.channel.basic.publish(
exchange=exchange_name,
routing_key=routing_key,
body=bytes(json.dumps(body), "utf-8"),
body=encoded_body,
properties=properties,
)

Expand Down

0 comments on commit ab50555

Please sign in to comment.