def unsubscribe(listener, topics=None): """ unsubscribe listener from topic and log event """ pubsub_logger.debug("UNSUBSCRIBE : %s unsubsrcibes from topic(s) %s", name(listener), topics) Publisher().unsubscribe(listener, topics)
def save_subscribe(listener, topic=ALL_TOPICS): """ subscribe listener to topic and log event, unless listener is already subscribed """ if not is_subscribed(listener, topic): subscribe(listener, topic) else: pubsub_logger.debug("save_subscribe prevented %s second subscription to topic %s", name(listener), topic)
def subscribe(listener, topic=ALL_TOPICS): """ subscribe listener to topic and log event """ if is_subscribed(listener, topic): pubsub_logger.warning("%s already subscribed to topic %s!", name(listener), topic) pubsub_logger.debug("SUBSCRIBE: %s subscribes to topic %s", name(listener), topic) Publisher().subscribe(listener, topic)
def save_subscribe(listener, topic=ALL_TOPICS): """ subscribe listener to topic and log event, unless listener is already subscribed """ if not is_subscribed(listener, topic): subscribe(listener, topic) else: pubsub_logger.debug( "save_subscribe prevented %s second subscription to topic %s", name(listener), topic)
def receive(listener, message): """ log reception of message by listener """ if not message: pubsub_logger.debug("RECEIVE: %s receives message", name(listener)) elif message.data: pubsub_logger.debug("RECEIVE: %s receives message with topic %s and data %s", name(listener), ".".join(message.topic), repr(message.data)) else: pubsub_logger.debug("RECEIVE: %s receives message with topic %s", name(listener), ".".join(message.topic))
def receive(listener, message): """ log reception of message by listener """ if not message: pubsub_logger.debug("RECEIVE: %s receives message", name(listener)) elif message.data: pubsub_logger.debug( "RECEIVE: %s receives message with topic %s and data %s", name(listener), ".".join(message.topic), repr(message.data)) else: pubsub_logger.debug("RECEIVE: %s receives message with topic %s", name(listener), ".".join(message.topic))
def send(talker, topic=ALL_TOPICS, data=None): """ send message from talker to topic and log event """ pubsub_logger.debug(10 * "-" + " %s " + 60 * "-", topic) if data: pubsub_logger.debug("SEND: %s sends message for topic %s with data %s", name(talker), topic, repr(data)) else: pubsub_logger.debug("SEND: %s sends message for topic %s", name(talker), topic) Publisher().sendMessage(topic, data)