# Path: hedwig/utils.py
# LOGGER = logging.getLogger(__name__)
# def import_obj(cb):
# 
# Path: hedwig/core/base.py
# class Base(object):
#     def __init__(self, settings):
#         LOGGER.info("Base init for class - {0}".format(self.__class__.__name__))
#         self.settings = settings
#         LOGGER.debug("Setting credentials")
#         credentials = pika.PlainCredentials(username=self.settings.USERNAME,
#                                             password=self.settings.PASSWORD)
#         LOGGER.debug("Setting Connection params")
#         self.conn_params = pika.ConnectionParameters(host=self.settings.HOST, port=self.settings.PORT,
#                                                      virtual_host=self.settings.VHOST, credentials=credentials,
#                                                      heartbeat_interval=self.settings.HEARTBEAT_INTERVAL,
#                                                      socket_timeout=self.settings.SOCKET_TIMEOUT)
# 
#         self.connection = None
#         self.channel = None
# 
#     def create_channel(self):
#         LOGGER.debug("Creating a channel")
#         channel = self.connection.channel()
#         LOGGER.debug(
#             "Declaring {0} exchange - {1}".format(self.settings.EXCHANGE_TYPE, self.settings.EXCHANGE)
#         )
#         channel.exchange_declare(exchange=self.settings.EXCHANGE, exchange_type=self.settings.EXCHANGE_TYPE, durable=True)
#         return channel
# 
#     def get_channel(self):
# 
#         self.connect()
#         if self.channel is None or not self.channel.is_open:
#             LOGGER.info("No active channel found, creating a channel")
#             self.channel = self.create_channel()
#         return self.channel
# 
#     def connect(self):
#         LOGGER.debug("Making a blocking connection")
#         if self.connection is None or not self.connection.is_open:
#             LOGGER.info("No active connection found, creating a connection")
#             self.connection = pika.BlockingConnection(self.conn_params)
# 
#     def close_channel(self):
#         LOGGER.debug("Trying to close channel if open")
#         if self.channel and self.channel.is_open:
#             LOGGER.debug("Closing channel")
#             try:
#                 self.channel.cancel()
#                 self.channel.close()
#             except ConnectionClosed:
#                 self.channel = None
# 
#     def shutdown(self):
#         LOGGER.info("Shutdown called")
#         self.close_channel()
#         if self.connection and self.connection.is_open:
#             LOGGER.info("Closing connection")
#             try:
#                 self.connection.close()
#             except ConnectionClosed:
#                 self.connection = None
# 
# Path: hedwig/core/exceptions.py
# class IllegalOperation(Exception):
#     pass
# 
# Path: hedwig/core/settings.py
# DEFAULT_QUEUE_SETTINGS = {
#     "DURABLE": True,
#     "AUTO_DELETE": False,
#     "EXCLUSIVE": False,
#     "NO_ACK": False,
# }


import logging
import inspect
from future.utils import iteritems
from pika.exceptions import ConnectionClosed
from hedwig import utils
from hedwig.core.base import Base
from hedwig.core.exceptions import IllegalOperation
from hedwig.core.settings import DEFAULT_QUEUE_SETTINGS
            if mod is None:
                raise Exception("Can't determine module for - %s" % (func.__name__))
            func_string = "{}.{}.{}.{}".format(
                "__hedwig",
                mod.__name__,
                getattr(func.__class__, "__name__", "function"),
                func.__name__
            )
            self._callbacks[func_string] = func
        else:
            func_string = func

        def callback_wrapper(ch, method, properties, body):
            LOGGER.info("Got message - %s" % (method.routing_key))
            if func_string not in self._callbacks:
                self._callbacks[func_string] = utils.import_obj(func_string)
            try:
                self._callbacks[func_string](ch, method, properties, body)
            except Exception as e:
                LOGGER.exception("Callback exception '%s'" % str(e))
                if self.settings.CONSUMER['RAISE_EXCEPTION']:
                    LOGGER.info("CALLBACK RAISED EXCEPTION")
                    raise

        return callback_wrapper

    def _bind_things(self, channel):
        LOGGER.debug('Attempting to bind queues')

        for q_name, q_settings in iteritems(self.settings.CONSUMER['QUEUES']):

# Path: hedwig/utils.py
# LOGGER = logging.getLogger(__name__)
# def import_obj(cb):
# 
# Path: hedwig/core/base.py
# class Base(object):
#     def __init__(self, settings):
#         LOGGER.info("Base init for class - {0}".format(self.__class__.__name__))
#         self.settings = settings
#         LOGGER.debug("Setting credentials")
#         credentials = pika.PlainCredentials(username=self.settings.USERNAME,
#                                             password=self.settings.PASSWORD)
#         LOGGER.debug("Setting Connection params")
#         self.conn_params = pika.ConnectionParameters(host=self.settings.HOST, port=self.settings.PORT,
#                                                      virtual_host=self.settings.VHOST, credentials=credentials,
#                                                      heartbeat_interval=self.settings.HEARTBEAT_INTERVAL,
#                                                      socket_timeout=self.settings.SOCKET_TIMEOUT)
# 
#         self.connection = None
#         self.channel = None
# 
#     def create_channel(self):
#         LOGGER.debug("Creating a channel")
#         channel = self.connection.channel()
#         LOGGER.debug(
#             "Declaring {0} exchange - {1}".format(self.settings.EXCHANGE_TYPE, self.settings.EXCHANGE)
#         )
#         channel.exchange_declare(exchange=self.settings.EXCHANGE, exchange_type=self.settings.EXCHANGE_TYPE, durable=True)
#         return channel
# 
#     def get_channel(self):
# 
#         self.connect()
#         if self.channel is None or not self.channel.is_open:
#             LOGGER.info("No active channel found, creating a channel")
#             self.channel = self.create_channel()
#         return self.channel
# 
#     def connect(self):
#         LOGGER.debug("Making a blocking connection")
#         if self.connection is None or not self.connection.is_open:
#             LOGGER.info("No active connection found, creating a connection")
#             self.connection = pika.BlockingConnection(self.conn_params)
# 
#     def close_channel(self):
#         LOGGER.debug("Trying to close channel if open")
#         if self.channel and self.channel.is_open:
#             LOGGER.debug("Closing channel")
#             try:
#                 self.channel.cancel()
#                 self.channel.close()
#             except ConnectionClosed:
#                 self.channel = None
# 
#     def shutdown(self):
#         LOGGER.info("Shutdown called")
#         self.close_channel()
#         if self.connection and self.connection.is_open:
#             LOGGER.info("Closing connection")
#             try:
#                 self.connection.close()
#             except ConnectionClosed:
#                 self.connection = None
# 
# Path: hedwig/core/exceptions.py
# class IllegalOperation(Exception):
#     pass
# 
# Path: hedwig/core/settings.py
# DEFAULT_QUEUE_SETTINGS = {
#     "DURABLE": True,
#     "AUTO_DELETE": False,
#     "EXCLUSIVE": False,
#     "NO_ACK": False,
# }


# Path: hedwig/core/consumer.py
import logging
import inspect
from future.utils import iteritems
from pika.exceptions import ConnectionClosed
from hedwig import utils
from hedwig.core.base import Base
from hedwig.core.exceptions import IllegalOperation
from hedwig.core.settings import DEFAULT_QUEUE_SETTINGS

            if mod is None:
                raise Exception("Can't determine module for - %s" % (func.__name__))
            func_string = "{}.{}.{}.{}".format(
                "__hedwig",
                mod.__name__,
                getattr(func.__class__, "__name__", "function"),
                func.__name__
            )
            self._callbacks[func_string] = func
        else:
            func_string = func

        def callback_wrapper(ch, method, properties, body):
            LOGGER.info("Got message - %s" % (method.routing_key))
            if func_string not in self._callbacks:
                self._callbacks[func_string] = utils.import_obj(func_string)
            try:
                self._callbacks[func_string](ch, method, properties, body)
            except Exception as e:
                LOGGER.exception("Callback exception '%s'" % str(e))
                if self.settings.CONSUMER['RAISE_EXCEPTION']:
                    LOGGER.info("CALLBACK RAISED EXCEPTION")
                    raise

        return callback_wrapper

    def _bind_things(self, channel):
        LOGGER.debug('Attempting to bind queues')

        for q_name, q_settings in iteritems(self.settings.CONSUMER['QUEUES']):

            q_st = DEFAULT_QUEUE_SETTINGS.copy()