Commit 4026ee7c authored by Federico Sismondi's avatar Federico Sismondi
Browse files

amqp_synch_calls should be py2 compliant

parent b1370dc1
import six
import os import os
import pika import pika
import time
import logging
import threading
from binascii import unhexlify
from datetime import datetime
from messages import * from messages import *
VERSION = '0.0.4' VERSION = '0.0.5'
AMQP_EXCHANGE = 'amq.topic' AMQP_EXCHANGE = 'amq.topic'
def publish_message(connection, message): def publish_message(connection, message):
""" Published which uses message object metadata """ Published which uses message object metadata
...@@ -27,7 +21,7 @@ def publish_message(connection, message): ...@@ -27,7 +21,7 @@ def publish_message(connection, message):
properties = pika.BasicProperties(**message.get_properties()) properties = pika.BasicProperties(**message.get_properties())
channel.basic_publish( channel.basic_publish(
exchange= AMQP_EXCHANGE, exchange=AMQP_EXCHANGE,
routing_key=message.routing_key, routing_key=message.routing_key,
properties=properties, properties=properties,
body=message.to_json(), body=message.to_json(),
...@@ -38,7 +32,7 @@ def publish_message(connection, message): ...@@ -38,7 +32,7 @@ def publish_message(connection, message):
channel.close() channel.close()
def amqp_request(connection, request_message: Message, component_id: str): def amqp_request(connection, request_message, component_id):
# NOTE: channel must be a pika channel # NOTE: channel must be a pika channel
# check first that sender didnt forget about reply to and corr id # check first that sender didnt forget about reply to and corr id
...@@ -116,6 +110,7 @@ if __name__ == '__main__': ...@@ -116,6 +110,7 @@ if __name__ == '__main__':
try: try:
from urllib.parse import urlparse from urllib.parse import urlparse
AMQP_URL = str(os.environ['AMQP_URL']) AMQP_URL = str(os.environ['AMQP_URL'])
p = urlparse(AMQP_URL) p = urlparse(AMQP_URL)
AMQP_USER = p.username AMQP_USER = p.username
......
...@@ -117,7 +117,7 @@ class Message: ...@@ -117,7 +117,7 @@ class Message:
self._msg_data.update(kwargs) self._msg_data.update(kwargs)
# add API's version # add API's version
if not "_api_version" in self._msg_data: if "_api_version" not in self._msg_data:
self._msg_data["_api_version"] = API_VERSION self._msg_data["_api_version"] = API_VERSION
# add values as objects attributes # add values as objects attributes
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment