# See the License for the specific language governing permissions and
# limitations under the License.
-version = '0.1.15'
+version = '0.1.16'
# TODO add package version filling commit id with 0's; e.g.: '5.0.0.post11+00000000.dirty-1'
-date_version = '2018-12-05'
+date_version = '2019-01-28'
self.logger = logging.getLogger(config["logger_name"])
self.host = config["host"]
self.port = config["port"]
- self.loop = asyncio.get_event_loop()
+ self.loop = config.get("loop") or asyncio.get_event_loop()
self.broker = str(self.host) + ":" + str(self.port)
self.group_id = config.get("group_id")
raise MsgException("Error reading {} topic: {}".format(topic, str(e)))
async def aiowrite(self, topic, key, msg, loop=None):
+ """
+ Asyncio write
+ :param topic: str kafka topic
+ :param key: str kafka key
+ :param msg: str or dictionary kafka message
+ :param loop: asyncio loop. To be DEPRECATED! in near future!!! loop must be provided inside config at connect
+ :return: None
+ """
if not loop:
loop = self.loop
async def aioread(self, topic, loop=None, callback=None, aiocallback=None, **kwargs):
"""
- Asyncio read from one or several topics. It blocks.
+ Asyncio read from one or several topics.
:param topic: can be str: single topic; or str list: several topics
- :param loop: asyncio loop
+ :param loop: asyncio loop. To be DEPRECATED! in near future!!! loop must be provided inside config at connect
:param callback: synchronous callback function that will handle the message in kafka bus
:param aiocallback: async callback function that will handle the message in kafka bus
:param kwargs: optional keyword arguments for callback function
self.files_read = {}
self.files_write = {}
self.buffer = {}
+ self.loop = None
def connect(self, config):
try:
self.path += "/"
if not os.path.exists(self.path):
os.mkdir(self.path)
+ self.loop = config.get("loop")
+
except MsgException:
raise
except Exception as e: # TODO refine
:param loop: asyncio loop
:return: topic, key, message
"""
+ _loop = loop or self.loop
try:
while True:
msg = self.read(topic, blocks=False)
await aiocallback(*msg, **kwargs)
else:
return msg
- await asyncio.sleep(2, loop=loop)
+ await asyncio.sleep(2, loop=_loop)
except MsgException:
raise
except Exception as e: # TODO refine