-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from dylanmcreynolds/waskly_wabbit
Ingest via rabbitMQ
- Loading branch information
Showing
11 changed files
with
179 additions
and
99 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import logging | ||
import os | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
TILED_INGEST_PIKA_LOG_LEVEL = os.get_env( | ||
"TILED_INGEST_PIKE_LOG_LEVEL", logging.CRITICAL | ||
) | ||
TILED_INGEST_RMQ_HOST = os.getenv("TILED_INGEST_RMQ_HOST") | ||
TILED_INGEST_RMQ_USER = os.getenv("TILED_INGEST_RMQ_USER") | ||
TILED_INGEST_RMQ_PW = os.getenv("TILED_INGEST_RMQ_PW") | ||
|
||
TILED_INGEST_TILED_CONFIG_PATH = os.getenv("TILED_INGEST_TILED_CONFIG_PATH") | ||
|
||
logger.info(f"TILED_INGEST_PIKA_LOG_LEVEL {TILED_INGEST_PIKA_LOG_LEVEL}") | ||
logger.info(f"TILED_INGEST_RMQ_HOST {TILED_INGEST_RMQ_HOST}") | ||
logger.info(f"TILED_INGEST_RMQ_USER {TILED_INGEST_RMQ_USER}") | ||
logger.info("TILED_INGEST_RMQ_PW not logged") | ||
logger.info(f"TILED_INGEST_TILED_CONFIG_PATH {TILED_INGEST_TILED_CONFIG_PATH}") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
import asyncio | ||
import logging | ||
import json | ||
import os | ||
|
||
import pika | ||
|
||
# import config | ||
from ..ingest import get_tiled_config, process_file | ||
|
||
import tiled_ingestor.rabbitmq.schemas as schemas | ||
|
||
TILED_INGEST_PIKA_LOG_LEVEL = os.getenv("TILED_INGEST_PIKE_LOG_LEVEL", logging.CRITICAL) | ||
logging.basicConfig(level=logging.CRITICAL) | ||
logging.getLogger("pika").setLevel(TILED_INGEST_PIKA_LOG_LEVEL) | ||
|
||
TILED_INGEST_RMQ_HOST = os.getenv("TILED_INGEST_RMQ_HOST") | ||
TILED_INGEST_RMQ_USER = os.getenv("TILED_INGEST_RMQ_USER") | ||
TILED_INGEST_RMQ_PW = os.getenv("TILED_INGEST_RMQ_PW") | ||
|
||
TILED_INGEST_TILED_CONFIG_PATH = os.getenv("TILED_INGEST_TILED_CONFIG_PATH") | ||
tiled_config = get_tiled_config(TILED_INGEST_TILED_CONFIG_PATH) | ||
|
||
|
||
def process_message(ch, method, properties, body): | ||
# Decode the JSON message | ||
message = json.loads(body) | ||
# Prcess the message | ||
# TODO: Add your logic here | ||
|
||
# Acknowledge the message | ||
ch.basic_ack(delivery_tag=method.delivery_tag) | ||
new_file_path = message.get(schemas.NEW_FILE_PATH_KEY) | ||
assert ( | ||
new_file_path | ||
), f"Message received from rabbitMQ does not contain {schemas.NEW_FILE_PATH_KEY}" | ||
asyncio.run(process_file(new_file_path, tiled_config)) | ||
|
||
|
||
def start_consumer(): | ||
# Connect to RabbitMQ | ||
|
||
credentials = pika.PlainCredentials(TILED_INGEST_RMQ_USER, TILED_INGEST_RMQ_PW) | ||
parameters = pika.ConnectionParameters( | ||
TILED_INGEST_RMQ_HOST, credentials=credentials | ||
) | ||
connection = pika.BlockingConnection(parameters) | ||
channel = connection.channel() | ||
|
||
# # Declare the queue | ||
channel.queue_declare(queue=schemas.RABBITMQ_TOMO_QUEUE) | ||
|
||
# Set the prefetch count to limit the number of unacknowledged messages | ||
channel.basic_qos(prefetch_count=1) | ||
|
||
# Start consuming messages | ||
channel.basic_consume( | ||
queue="tomo_reconstruction", on_message_callback=process_message | ||
) | ||
|
||
# Enter a loop to continuously consume messages | ||
channel.start_consuming() | ||
|
||
|
||
if __name__ == "__main__": | ||
start_consumer() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
import json | ||
import logging | ||
import os | ||
import sys | ||
|
||
import pika | ||
from pika import DeliveryMode | ||
|
||
# from pika.exchange_type import ExchangeType | ||
|
||
# import config | ||
import schemas | ||
|
||
TILED_INGEST_PIKA_LOG_LEVEL = os.getenv("TILED_INGEST_PIKE_LOG_LEVEL", logging.CRITICAL) | ||
logging.basicConfig(level=logging.DEBUG) | ||
logging.getLogger("pika").setLevel(TILED_INGEST_PIKA_LOG_LEVEL) | ||
|
||
|
||
TILED_INGEST_RMQ_HOST = os.getenv("TILED_INGEST_RMQ_HOST") | ||
TILED_INGEST_RMQ_USER = os.getenv("TILED_INGEST_RMQ_USER") | ||
TILED_INGEST_RMQ_PW = os.getenv("TILED_INGEST_RMQ_PW") | ||
|
||
|
||
def send_message(new_file: str): | ||
logging.info(f"Received request for {new_file}") | ||
json_message = json.dumps({schemas.NEW_FILE_PATH_KEY: new_file}) | ||
|
||
credentials = pika.PlainCredentials(TILED_INGEST_RMQ_USER, TILED_INGEST_RMQ_PW) | ||
parameters = pika.ConnectionParameters( | ||
TILED_INGEST_RMQ_HOST, credentials=credentials | ||
) | ||
connection = pika.BlockingConnection(parameters) | ||
channel = connection.channel() | ||
# channel.exchange_declare( | ||
# exchange=schemas.RABBITMQ_EXCHANGE, | ||
# exchange_type=ExchangeType.direct, | ||
# passive=False, | ||
# durable=True, | ||
# auto_delete=False, | ||
# ) | ||
|
||
logging.info(f"Sending {json_message} to queue {schemas.RABBITMQ_TOMO_QUEUE}") | ||
channel.basic_publish( | ||
"", | ||
schemas.RABBITMQ_TOMO_QUEUE, | ||
json_message, | ||
pika.BasicProperties( | ||
content_type="application/json", delivery_mode=DeliveryMode.Transient | ||
), | ||
) | ||
connection.close() | ||
|
||
|
||
if __name__ == "__main__": | ||
if len(sys.argv) == 1: | ||
new_file = "../mlex_tomo_framework/data/tiled_storage/recons/rec20240207_120829_test_no_xrays_n1313" | ||
else: | ||
new_file = sys.argv[1] | ||
send_message(new_file=new_file) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
NEW_FILE_PATH_KEY = "new_file_path" | ||
RABBITMQ_EXCHANGE = "mlexchange_exchange" | ||
RABBITMQ_TOMO_QUEUE = "tomo_reconstruction" |