Example #1
0
    def publish(self, message, *args, **kwargs):
        """ publishes to the message queue and also to cache for each queue
            It is expected that this will be connected with get message by a listeners setup method.
            If the message passed to it is None it will publish nothing.
        """
        if message is None:
            return
        for queue in self.get_publish_queues(*args, **kwargs):
            publish(queue, message)

            cache.set(self.cache_key % queue, (time.time(), message))
Example #2
0
    def publish(self, message, *args, **kwargs):
        """ publish a message to queues.

            publishes the message to `get_publish_queues(*args, **kwargs)`.

            :arg message: the message to publish.
        """
        # a message of None will not be sent. and empty dict should be used instead
        if message is None:
            return

        for queue in self.get_publish_queues(*args, **kwargs):
            publish(queue, message)
Example #3
0
 def __call__(self, **kwargs):
     for q in self.get_queues(**kwargs):
         publish(q, self.get_message(**kwargs))
Example #4
0
def publish_demo(sender, instance, **kwargs):
    message = dict(title=instance.title, summary=instance.summary, url=instance.link)
    publish('test.queue1', message)