Skip to content

Commit

Permalink
Merge pull request #11 from seeker25/add_ordering
Browse files Browse the repository at this point in the history
Add in config for publish ordering
  • Loading branch information
thorwolpert authored Jul 5, 2024
2 parents c348d30 + ec04b8f commit 1c0ea85
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions python/gcp-queue/src/gcp_queue/gcp_queue.py
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,8 @@ def __init__(self, app: Flask = None):
self.audience = None
self.credentials_pub = None
self.gcp_auth_key = None
self.enable_message_ordering = False
self.publisher_options = ()
self.publisher_audience = None
self.service_account_info = None
self._publisher = None
Expand All @@ -73,6 +75,11 @@ def init_app(self, app: Flask):
"""Initializes the application"""
self.app = app
self.gcp_auth_key = app.config.get("GCP_AUTH_KEY")
self.enable_message_ordering = app.config.get("PUB_ENABLE_MESSAGE_ORDERING")
if self.enable_message_ordering:
self.publisher_options = pubsub_v1.types.PublisherOptions(
enable_message_ordering=True
)
if self.gcp_auth_key:
try:
audience = app.config.get(
Expand Down Expand Up @@ -102,12 +109,13 @@ def init_app(self, app: Flask):
def publisher(self):
"""Returns the publisher"""

if not self._publisher and self.credentials_pub:
self._publisher = pubsub_v1.PublisherClient(
credentials=self.credentials_pub
)
elif not self._publisher:
self._publisher = pubsub_v1.PublisherClient()
if self._publisher:
return self._publisher

self._publisher = pubsub_v1.PublisherClient(
credentials=self.credentials_pub,
publisher_options=self.publisher_options
)
return self._publisher

@staticmethod
Expand Down

0 comments on commit 1c0ea85

Please sign in to comment.