import functools
import logging
import pika
LOG_FORMAT = ('%(levelname) -10s %(asctime)s %(name) -30s %(funcName) '
'-35s %(lineno) -5d: %(message)s')
LOGGER = logging.getLogger(__name__)
#logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT)
def on_message(chan, method_frame, _header_frame, body, userdata=None):
"""Called when a message is received. Log message and ack it."""
LOGGER.info('Userdata: %s Message body: %s', userdata, body)
chan.basic_ack(delivery_tag=method_frame.delivery_tag)
print("tmd")
print(body.decode('utf-8'))
def main():
"""Main method."""
credentials = pika.PlainCredentials('guest', 'guest')
parameters = pika.ConnectionParameters('127.0.0.1', credentials=credentials)
connection = pika.BlockingConnection(parameters)
channel = connection.channel()
channel.exchange_declare(
exchange='ex_cpc',
exchange_type='direct',
passive=False,
durable=True,
auto_delete=False)
channel.queue_declare(queue='standard', auto_delete=True)
channel.queue_bind(
queue='q_cpc', exchange='ex_cpc', routing_key='url_cpc')
channel.basic_qos(prefetch_count=)
on_message_callback = functools.partial(
on_message, userdata='on_message_userdata')
channel.basic_consume('q_cpc', on_message_callback)
print("nmd")
try:
channel.start_consuming()
except KeyboardInterrupt:
channel.stop_consuming()
connection.close()
if __name__ == '__main__':
main()