import pika

#import pika.log
#pika.log.setup(pika.log.DEBUG, color=True)

class AnkPika(object):

    def __init__(self, host):
        self.connection = pika.BlockingConnection(pika.ConnectionParameters(
            host = host))
        self.channel = self.connection.channel()
        self.channel.exchange_declare(exchange='www',
                type='direct')


    def publish(self, exchange, routing_key, body):
        self.channel.basic_publish(exchange= exchange,
                routing_key = routing_key,
                body= body)

    def publish_compressed(self, exchange, routing_key, body):
        """Compresses body using zlib before sending"""
        import zlib
        body = zlib.compress(body, 9)
        self.publish(exchange, routing_key, body)

        #TODO: implement callback



@@ -1,19 +1,207 @@
 import 
-pika
+autonetkit.config as config%0Aimport autonetkit.log as log%0A%0Ause_rabbitmq = config.settings%5B'Rabbitmq'%5D%5B'active'%5D%0Aif use_rabbitmq:%0A    import pika%0A%0A#TODO: tidy this to be a try/except ImportError
 %0A%0A#impor
@@ -310,16 +310,108 @@
  host):%0A
+        if use_rabbitmq:%0A            log.debug(%22Using Rabbitmq with server %25s %22 %25 host)%0A    
         
@@ -491,16 +491,20 @@
         
+    
 host = h
@@ -509,32 +509,36 @@
  host))%0A        
+  
+  
 self.channel = s
@@ -562,16 +562,20 @@
 annel()%0A
+    
         
@@ -636,16 +636,20 @@
         
+ 
+   
 type='di
@@ -655,16 +655,187 @@
 irect')%0A
+        else:%0A            log.debug(%22Not using Rabbitmq%22)%0A            self.publish = self.publish_blank_stub%0A            self.publish_compressed = self.publish_blank_stub%0A
 %0A%0A    de
@@ -1269,10 +1269,226 @@
 allback%0A
+    def publish_blank_stub(self, exchange, routing_key, body):%0A        %22%22%22use if not using rabbitmq, simplifies calls elsewhere (publish does nothing)%22%22%22%0A#TODO: log that not sending for debug purposes%0A        return%0A
 %0A%0A

handle disabled pika