๐Ÿ“ฆ EqualifyEverything / integration-axe

๐Ÿ“„ auth.py ยท 49 lines
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49import pika
from utils.watch import logger

def rabbit(queue_name, message):
    logger.debug('Connecting to RabbitMQ server...')
    credentials = pika.PlainCredentials('worker_axe', '$wFBN9Iu7vS7uf&')
    connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.1.29', credentials=credentials, virtual_host='gova11y'))
    logger.debug('Connected to RabbitMQ server!')

    logger.debug(f'Declaring queue: {queue_name}...')
    channel = connection.channel()
    channel.queue_declare(queue=queue_name, durable=True, arguments={'x-message-ttl': 7200000})
    logger.debug(f'Queue {queue_name} declared!')

    try:
        channel.basic_publish(
            exchange='',
            routing_key=queue_name,
            body=message,
            properties=pika.BasicProperties(delivery_mode=2)  # Make the messages persistent
        )
        channel.close()
        connection.close()
        return channel, connection
    except Exception as e:
        logger.error(f"You've got a sick rabbit... {e}")
        return None, None

# Catching Rabbits
def catch_rabbits(queue_name, callback):
    logger.debug('Connecting to RabbitMQ server...')
    credentials = pika.PlainCredentials('worker_axe', '$wFBN9Iu7vS7uf&')
    connection = pika.BlockingConnection(pika.ConnectionParameters('192.168.1.29', credentials=credentials, virtual_host='gova11y'))
    logger.debug('Connected to RabbitMQ server!')

    logger.debug(f'Declaring queue: {queue_name}...')
    channel = connection.channel()
    channel.queue_declare(queue=queue_name, durable=True, arguments={'x-message-ttl': 7200000})
    logger.debug(f'Queue {queue_name} declared!')

    channel.basic_qos(prefetch_count=1)
    channel.basic_consume(
        queue=queue_name,
        on_message_callback=callback,
        auto_ack=False
    )
    logger.info(f'๐Ÿ‡ [*] Waiting for messages in {queue_name}. To exit press CTRL+C')

    channel.start_consuming()