2014-08-06 11:43:40 +02:00
|
|
|
#!/usr/bin/env python2
|
|
|
|
# -*-coding:UTF-8 -*
|
|
|
|
"""
|
|
|
|
The ZMQ_Pub_Global Module
|
|
|
|
=========================
|
|
|
|
|
|
|
|
This module is consuming the Redis-list created by the script ./Dir.py.
|
|
|
|
This module is as the same level of the ZMQ tree than the Module ZMQ_Feed
|
|
|
|
|
|
|
|
Whereas the ZMQ_Feed is poping the list created in redis by ZMQ_Feed_Q which is
|
2014-08-14 14:11:07 +02:00
|
|
|
listening a stream, ZMQ_Pub_Global is poping the list created in redis by
|
|
|
|
./Dir.py.
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
Thanks to this Module there is now two way to Feed the ZMQ tree:
|
|
|
|
*By a continuous stream ..seealso:: ZMQ_Feed Module
|
|
|
|
*Manually with this module and ./Dir.py script.
|
|
|
|
|
|
|
|
Requirements
|
|
|
|
------------
|
|
|
|
|
|
|
|
*Need running Redis instances. (Redis)
|
|
|
|
|
|
|
|
"""
|
2014-08-14 14:11:07 +02:00
|
|
|
import time
|
2014-08-06 11:43:40 +02:00
|
|
|
from pubsublogger import publisher
|
|
|
|
|
2014-08-19 19:53:33 +02:00
|
|
|
import Helper
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-19 19:53:33 +02:00
|
|
|
if __name__ == "__main__":
|
2014-08-22 17:35:40 +02:00
|
|
|
publisher.port = 6380
|
2014-08-19 19:53:33 +02:00
|
|
|
publisher.channel = "Global"
|
2014-08-14 14:11:07 +02:00
|
|
|
|
2014-08-19 19:53:33 +02:00
|
|
|
config_section = 'PubSub_Global'
|
|
|
|
config_channel = 'channel'
|
|
|
|
subscriber_name = 'global'
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-19 19:53:33 +02:00
|
|
|
h = Helper.Redis_Queues(config_section, config_channel, subscriber_name)
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-19 19:53:33 +02:00
|
|
|
# Publisher
|
|
|
|
pub_config_section = 'PubSub_Global'
|
2014-08-20 15:14:57 +02:00
|
|
|
pub_config_channel = 'channel'
|
|
|
|
h.zmq_pub(pub_config_section, pub_config_channel)
|
2014-08-06 11:43:40 +02:00
|
|
|
|
|
|
|
# LOGGING #
|
|
|
|
publisher.info("Starting to publish.")
|
|
|
|
|
|
|
|
while True:
|
2014-08-20 15:14:57 +02:00
|
|
|
filename = h.redis_rpop()
|
2014-08-06 11:43:40 +02:00
|
|
|
|
2014-08-14 14:11:07 +02:00
|
|
|
if filename is not None:
|
2014-08-20 15:14:57 +02:00
|
|
|
h.zmq_pub_send(filename)
|
2014-08-06 11:43:40 +02:00
|
|
|
else:
|
|
|
|
time.sleep(10)
|
|
|
|
publisher.debug("Nothing to publish")
|