Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

LCFS: Add RabbitMQ for Local Development #1079

Open
3 tasks
AlexZorkin opened this issue Oct 18, 2024 · 0 comments
Open
3 tasks

LCFS: Add RabbitMQ for Local Development #1079

AlexZorkin opened this issue Oct 18, 2024 · 0 comments
Labels
Medium Medium priority Task Work that does not directly impact the user

Comments

@AlexZorkin
Copy link
Collaborator

Description:
Add a RabbitMQ service to the LCFS docker-compose.yml for local development. This RabbitMQ instance will simulate the message queue, allowing LCFS to test receiving transaction messages from TFRS. A script should be provided to easily add messages with the organization ID and compliance units for testing purposes.

Purpose:
To enable local development and testing of LCFS without requiring access to TFRS by simulating RabbitMQ messages locally.

Development Requirements:

  • Add RabbitMQ service to the LCFS docker-compose.yml.
  • Create a script that sends a message with an organization ID and compliance units to RabbitMQ.
  • Ensure LCFS can receive and process the message locally for testing.

Acceptance Criteria:

  • RabbitMQ instance is running in LCFS local development environment.
  • A script can successfully send a message to the RabbitMQ queue, and LCFS can receive and process the message.

Add rabbitmq to docker-compose.yml for LCFS:

  rabbitmq:
    image: rabbitmq:3-management
    container_name: rabbitmq
    environment:
      RABBITMQ_DEFAULT_USER: rabbitmq
      RABBITMQ_DEFAULT_PASS: rabbitmq
      RABBITMQ_DEFAULT_VHOST: /lcfs
    ports:
      - "15672:15672" # Management UI
      - "5672:5672"   # RabbitMQ Port
    networks:
      - shared_network

Script to Add a Message to RabbitMQ Queue:

import pika
import json

def send_message(organization_id, compliance_units_amount):
    # Setup connection and channel
    connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost', port=5672))
    channel = connection.channel()

    # Declare the queue if not already declared
    channel.queue_declare(queue='transaction_queue', durable=True)

    # Create the message body
    message = {
        'organization_id': organization_id,
        'compliance_units_amount': compliance_units_amount
    }

    # Publish the message to the queue
    channel.basic_publish(
        exchange='',
        routing_key='transaction_queue',
        body=json.dumps(message),
        properties=pika.BasicProperties(
            delivery_mode=2,  # Make message persistent
        )
    )

    print(f" [x] Sent message: {message}")

    # Close the connection
    connection.close()

if __name__ == "__main__":
    send_message(organization_id=1, compliance_units_amount=1000)

Explanation:

  • RabbitMQ Setup in Docker Compose: The RabbitMQ service has been added with default ports for management (15672) and communication (5672).
  • Script: This Python script uses pika to send a message to the RabbitMQ queue. It simulates a transaction message by sending an organization_id and compliance_units_amount to the transaction_queue queue. You can modify these values for testing purposes.
@AlexZorkin AlexZorkin added Medium Medium priority Task Work that does not directly impact the user labels Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Medium Medium priority Task Work that does not directly impact the user
Projects
None yet
Development

No branches or pull requests

1 participant