Skip to content

Commit

Permalink
feat : broker ssl & port 적용
Browse files Browse the repository at this point in the history
  • Loading branch information
seokho-1116 committed Jul 29, 2024
1 parent e8c46d0 commit 234cef2
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 18 deletions.
20 changes: 13 additions & 7 deletions backend/AnimatedDrawings/application/celery_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,18 @@

queue_config = QueueConfig()
celery = Celery('application.task',
broker=queue_config.get_celery_broker_url(),
include=['application.task.tasks'])
broker=queue_config.get_broker_url(),
include=['application.task.tasks']
)

celery.conf.result_expires = 300
celery.conf.task_queues = (
Queue('task.makeAnimation.queue'),
Queue('task.saveCapsuleSkin.queue'),
Queue('task.sendNotification.queue')
)
celery.conf.task_queues = (Queue('task.makeAnimation.queue'),
Queue('task.saveCapsuleSkin.queue'),
Queue('task.sendNotification.queue')
)

if queue_config.PROTOCOL == 'amqps':
import ssl
celery.conf.broker_use_ssl = {
'cert_reqs': ssl.CERT_REQUIRED
}
20 changes: 11 additions & 9 deletions backend/AnimatedDrawings/application/config/queue_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,11 @@


class QueueConfig:
PROTOCOL = RootConfig.CONFIG_FILE['rabbitmq']['protocol']
USERNAME = RootConfig.CONFIG_FILE['rabbitmq']['username']
BROKER_HOST = RootConfig.CONFIG_FILE['rabbitmq']['host']
PASSWORD = RootConfig.CONFIG_FILE['rabbitmq']['password']
PORT = RootConfig.CONFIG_FILE['rabbitmq']['port']
VIRTUAL_HOST = RootConfig.CONFIG_FILE['rabbitmq']['virtual-host']
CAPSULE_SKIN_REQUEST_QUEUE_NAME = RootConfig.CONFIG_FILE['rabbitmq'][
'queue_name']
Expand All @@ -16,12 +18,12 @@ class QueueConfig:
'notification_queue_name']

@staticmethod
def get_celery_broker_url() -> str:
return 'pyamqp://%s:%s@%s:5672%s' % (QueueConfig.USERNAME,
QueueConfig.PASSWORD,
QueueConfig.BROKER_HOST,
QueueConfig.VIRTUAL_HOST)

@staticmethod
def get_kombu_broker_url() -> str:
return f'amqp://{QueueConfig.USERNAME}:{QueueConfig.PASSWORD}@{QueueConfig.BROKER_HOST}/{QueueConfig.VIRTUAL_HOST}'
def get_broker_url() -> str:
return (
f'{QueueConfig.PROTOCOL}://'
f'{QueueConfig.USERNAME}:'
f'{QueueConfig.PASSWORD}@'
f'{QueueConfig.BROKER_HOST}:'
f'{QueueConfig.PORT}'
f'{QueueConfig.VIRTUAL_HOST}'
)
2 changes: 1 addition & 1 deletion backend/AnimatedDrawings/application/config/yml
Submodule yml updated from 443596 to 6b0cdd
10 changes: 9 additions & 1 deletion backend/AnimatedDrawings/application/kombu_connection_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,16 @@ def errback(exc, interval):
connections = pools.Connections(limit=2)
producers = pools.Producers(limit=2)

connection = Connection(hostname=QueueConfig.get_kombu_broker_url(),
if QueueConfig.PROTOCOL == 'amqps':
import ssl
ssl_option = {
'cert_reqs': ssl.CERT_REQUIRED
}
else:
ssl_option = None
connection = Connection(hostname=QueueConfig.get_broker_url(),
connect_timeout=7,
ssl=ssl_option,
errback=errback)

logger.info('레빗 엠큐 커넥션 풀 연결 설정 완료')
Expand Down

0 comments on commit 234cef2

Please sign in to comment.