You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
More flexible PGMQ Postgres extension Python client that using SQLAlchemy ORM, supporting both async and sync engines, sessionmakers or built from dsn.
fromtypingimportListfrompgmq_sqlalchemyimportPGMQueuepostgres_dsn='postgresql://postgres:postgres@localhost:5432/postgres'pgmq=PGMQueue(dsn=postgres_dsn)
pgmq.create_queue('my_queue')
msg= {'key': 'value', 'key2': 'value2'}
msg_id:int=pgmq.send('my_queue', msg)
# could also send a list of messagesmsg_ids:List[int] =pgmq.send_batch('my_queue', [msg, msg])
For consumer.py:
frompgmq_sqlalchemyimportPGMQueuefrompgmq_sqlalchemy.schemaimportMessagepostgres_dsn='postgresql://postgres:postgres@localhost:5432/postgres'pgmq=PGMQueue(dsn=postgres_dsn)
# read a single messagemsg:Message=pgmq.read('my_queue')
# read a batch of messagesmsgs:List[Message] =pgmq.read_batch('my_queue', 10)
For monitor.py:
frompgmq_sqlalchemyimportPGMQueuefrompgmq_sqlalchemy.schemaimportQueueMetricspostgres_dsn='postgresql://postgres:postgres@localhost:5432/postgres'pgmq=PGMQueue(dsn=postgres_dsn)
# get queue metricsmetrics:QueueMetrics=pgmq.metrics('my_queue')
print(metrics.queue_length)
print(metrics.total_messages)
More flexible PGMQ Postgres extension Python client that using SQLAlchemy ORM, supporting both async and sync engines, sessionmakers or built from dsn.