Commit c5fe2ff9c9e6e0b814e7755d7e7cb4bda9ff763a

Authored by Jonathan Wilson
0 parents
Exists in master

first commit

... ... @@ -0,0 +1,60 @@
  1 +#Config overrides which should never be version controlled
  2 +*local_config.ini
  3 +
  4 +# Byte-compiled / optimized / DLL files
  5 +__pycache__/
  6 +*.py[cod]
  7 +
  8 +# C extensions
  9 +*.so
  10 +
  11 +#Log files, but not directory structure
  12 +log/*
  13 +!log/.gitkeep
  14 +!log/supervisor/
  15 +!log/supervisor/.gitkeep
  16 +
  17 +# Distribution / packaging
  18 +bin/
  19 +build/
  20 +develop-eggs/
  21 +dist/
  22 +eggs/
  23 +lib/
  24 +lib64/
  25 +parts/
  26 +sdist/
  27 +var/
  28 +*.egg-info/
  29 +.installed.cfg
  30 +*.egg
  31 +
  32 +# Installer logs
  33 +pip-log.txt
  34 +pip-delete-this-directory.txt
  35 +
  36 +# Unit test / coverage reports
  37 +.tox/
  38 +.coverage
  39 +.cache
  40 +nosetests.xml
  41 +coverage.xml
  42 +
  43 +# Translations
  44 +*.mo
  45 +
  46 +# Mr Developer
  47 +.mr.developer.cfg
  48 +.project
  49 +.pydevproject
  50 +
  51 +# Rope
  52 +.ropeproject
  53 +
  54 +# Django stuff:
  55 +*.log
  56 +*.pot
  57 +
  58 +# Sphinx documentation
  59 +docs/_build/
  60 +
... ...
... ... @@ -0,0 +1,8 @@
  1 +FROM danzilla/centos6-python3-rabbit-worker
  2 +
  3 +COPY . /opt/worker
  4 +WORKDIR /opt/worker
  5 +
  6 +RUN pip3.4 install -r requirements.txt
  7 +
  8 +CMD ["supervisord", "-n"]
0 9 \ No newline at end of file
... ...
... ... @@ -0,0 +1 @@
  1 +git archive --format=tar --remote=ssh://git@gitlab.alfresco.com/web-and-integrations-development/base-rabbit-worker-container.git master | tar -xf -
... ...
app-config/config.ini
... ... @@ -0,0 +1,29 @@
  1 +[RabbitMQ]
  2 +hostname =
  3 +port = 5672
  4 +userid =
  5 +password =
  6 +virtual_host =
  7 +ssl_enabled = True
  8 +
  9 +[Consumer]
  10 +queue =
  11 +exchange =
  12 +routing_key =
  13 +
  14 +[Logging]
  15 +log_file = /var/log/worker_app.log
  16 +
  17 +;Must escape single percent symbols with %% to avoid config interpolation issues
  18 +log_format = %%(asctime)s [%%(levelname)s] %%(message)s
  19 +log_date_format = %%m/%%d/%%Y %%I:%%M:%%S %%p
  20 +
  21 +;Logging levels:
  22 +;CRITICAL 50
  23 +;ERROR 40
  24 +;WARNING 30
  25 +;INFO 20
  26 +;DEBUG 10
  27 +;NOTSET 0
  28 +
  29 +log_level = 20
0 30 \ No newline at end of file
... ...
... ... @@ -0,0 +1,6 @@
  1 +rabbitworker:
  2 + build: .
  3 + volumes:
  4 + - .:/opt/worker
  5 + - ./log:/var/log
  6 + command: supervisord -n
0 7 \ No newline at end of file
... ...
log/supervisor/.gitkeep
... ... @@ -0,0 +1,49 @@
  1 +import pika
  2 +import configparser
  3 +import logging
  4 +import os
  5 +os.chdir(os.path.dirname(__file__))
  6 +
  7 +config = configparser.SafeConfigParser()
  8 +
  9 +#Values in local_config.ini overwrite config.ini (if it exists.) Never version control 'local_config.ini'.
  10 +config.read(['./app-config/config.ini', './app-config/local_config.ini'])
  11 +logging.basicConfig(filename= config['Logging']['log_file'],
  12 + format= config['Logging']['log_format'],
  13 + datefmt= config['Logging']['log_date_format'],
  14 + level= int(config['Logging']['log_level']))
  15 +
  16 +credentials = pika.PlainCredentials(config['RabbitMQ']['userid'],
  17 + config['RabbitMQ']['password'])
  18 +
  19 +connection = pika.BlockingConnection(pika.ConnectionParameters(
  20 + host=config['RabbitMQ']['hostname'],
  21 + port=int(config['RabbitMQ']['port']),
  22 + credentials=credentials,
  23 + virtual_host=config['RabbitMQ']['virtual_host'],
  24 + ssl=config.getboolean('RabbitMQ', 'ssl_enabled')))
  25 +
  26 +#Basic queue-declaring publisher code
  27 +channel = connection.channel()
  28 +channel.queue_declare(queue='task_queue', durable=True)
  29 +
  30 +message = "Hello world!"
  31 +
  32 +channel.basic_publish(exchange='',
  33 + routing_key='task_queue',
  34 + body=message,
  35 + properties=pika.BasicProperties(
  36 + delivery_mode = 2, # Make message persistent
  37 + ))
  38 +logging.debug("Published: {0}".format(message))
  39 +
  40 +#Basic consumer code
  41 +def callback(channel, method, properties, body):
  42 + logging.debug("Received: {0}".format(body))
  43 + channel.basic_ack(delivery_tag = method.delivery_tag)
  44 +
  45 +channel.basic_qos(prefetch_count=1)
  46 +channel.basic_consume(callback,
  47 + queue='task_queue')
  48 +
  49 +channel.start_consuming()
0 50 \ No newline at end of file
... ...