def consume_amqp_message(self, message): self.message_accept(message) try: topic = message.get('delivery_properties').routing_key except AttributeError: # If we receive an AMQP message without a toipc, don't proxy it to STOMP return if self.stomp_broker: StompHub.send_message(self, topic.encode('utf8'), message.body.encode('utf8'))
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)