catcher_modules.mq package

Submodules

catcher_modules.mq.kafka module

class catcher_modules.mq.kafka.Kafka(**kwargs)[source]

Allows you to consume/produce messages from/to Apache Kafka

Input:
Consume:Consume message from kafka.
  • server: is the kafka host. Can be multiple, comma-separated.
  • group_id: is the consumer group id. If not specified - catcher will be used. Optional
  • topic: the name of the topic
  • timeout: is the consumer timeout. Optional (default is 1 sec)
  • where: search for specific message clause. Optional
Produce:Produce message to kafka.
  • server: is the kafka host. Can be multiple, comma-separated.
  • topic: the name of the topic
  • data: data to be produced.
  • data_from_file: File can be used as data source. Optional Either data or data_from_file should present.
Examples:

Read message with timestamp > 1000

kafka:
    consume:
        server: '127.0.0.1:9092'
        group_id: 'test'
        topic: 'test_consume_with_timestamp'
        timeout: {seconds: 5}
        where:
            equals: '{{ MESSAGE.timestamp > 1000 }}'

Produce data variable as json message

kafka:
    produce:
        server: '127.0.0.1:9092'
        topic: 'test_produce_json'
        data: '{{ data|tojson }}'

catcher_modules.mq.rabbit module

class catcher_modules.mq.rabbit.Rabbit(**kwargs)[source]

Allows you to consume/produce messages from/to RabbitMQ

Input:
Config:rabbitmq config object, used in other rabbitmq commands.
  • server: is the rabbit host, <rabbit-host:rabbit-port>
  • username: is the username
  • password: is the password
  • virtualhost: virtualhost Optional defaults to “/”
  • sslOptions: {‘ssl_version’: ‘PROTOCOL_TLSv1, PROTOCOL_TLSv1_1 or PROTOCOL_TLSv1_2’, ‘ca_certs’: ‘/path/to/ca_cert’, ‘keyfile’: ‘/path/to/key’, ‘certfile’: ‘/path/to/cert’. ‘cert_reqs’: ‘CERT_NONE, CERT_OPTIONAL or CERT_REQUIRED’}
    Optional object to be used only when ssl is required. If an empty object is passed ssl_version defaults to PROTOCOL_TLSv1_2 and cert_reqs defaults to CERT_NONE
  • disconnect_timeout: number of seconds to wait for a disconnect before force closing the connection. Warning! Publish
    may fail if you use to small timeout value.
Consume:Consume message from rabbit.
  • config: rabbitmq config object
  • queue: the name of the queue to consume from
Publish:Publish message to rabbit exchange.
  • config: rabbitmq config object
  • exchange: exchange to publish message
  • routing_key: routing key
  • headers: headers json Optional
  • data: data to be produced
  • data_from_file: data to be published. File can be used as data source. Optional Either data or data_from_file should present.
Examples:

Read message

variables:
    rabbitmq_config:
        server: 127.0.0.1:5672
        username: 'guest'
        password: 'guest'
steps:
    - rabbit:
        consume:
            config: '{{ rabbitmq_config }}''
            queue: 'test.catcher.queue'

Publish data variable as message

variables:
    rabbitmq_config:
        server: 127.0.0.1:5672
        sslOptions: {'ssl_version': 'PROTOCOL_TLSv1, PROTOCOL_TLSv1_1 or PROTOCOL_TLSv1_2', 'ca_certs': '/path/to/ca_cert', 'keyfile': '/path/to/key', 'certfile': '/path/to/cert'. 'cert_reqs': 'CERT_NONE, CERT_OPTIONAL or CERT_REQUIRED'}
        username: 'guest'
        password: 'guest'
steps:
    - rabbit:
        publish:
            config: '{{ rabbitmq_config }}''
            exchange: 'test.catcher.exchange'
            routing_key: 'catcher.routing.key'
            headers: {'test.header.1': 'header1', 'test.header.2': 'header1'}
            data: '{{ data|tojson }}'

Publish data_from_file variable as json message

variables:
    rabbitmq_config:
        server: 127.0.0.1:5672
        username: 'guest'
        password: 'guest'
steps:
    - rabbit:
        publish:
            config: '{{ rabbitmq_config }}''
            exchange: 'test.catcher.exchange'
            routing_key: 'catcher.routing.key'
            data_from_file: '{{ /path/to/file }}'