Beispiel #1
0
    def send_message(self, topic, message, jsonify=True):
        """ Send a message to a specific topic.

        :topic: A topic or list of topics to send the message to.
        :message: The message body.  Can be a string, list, or dict.
        :jsonify: To automatically encode non-strings to JSON

        """
        if not isinstance(topic, list):
            topics = [topic]
        else:
            topics = topic
        for topic in topics:
            if jsonify:
                message = json.encode(message)
            if self.amqp_broker:
                AMQPHub.send_message(self, topic, message, routing_key=topic)
            elif self.stomp_broker:
                StompHub.send_message(self, topic, message)
Beispiel #2
0
    def send_message(self, topic, message, jsonify=True):
        """ Send a message to a specific topic.

        :topic: A topic or list of topics to send the message to.
        :message: The message body.  Can be a string, list, or dict.
        :jsonify: To automatically encode non-strings to JSON

        """
        if not isinstance(topic, list):
            topics = [topic]
        else:
            topics = topic
        for topic in topics:
            if jsonify:
                message = json.encode(message)
            if self.amqp_broker:
                AMQPHub.send_message(self, topic, message, routing_key=topic)
            elif self.stomp_broker:
                StompHub.send_message(self, topic, message)