|
Expand Up
|
@@ -18,17 +18,16 @@ |
|
|
from google.cloud.gapic.pubsub.v1.subscriber_api import SubscriberApi |
|
|
from google.gax import CallOptions |
|
|
from google.gax import INITIAL_PAGE |
|
|
from google.gax.errors import GaxError |
|
|
from google.pubsub.v1.pubsub_pb2 import PubsubMessage |
|
|
from google.pubsub.v1.pubsub_pb2 import PushConfig |
|
|
from grpc.beta.implementations import insecure_channel |
|
|
from grpc import insecure_channel |
|
|
from grpc import StatusCode |
|
|
|
|
|
# pylint: disable=ungrouped-imports |
|
|
from google.cloud._helpers import _to_bytes |
|
|
from google.cloud._helpers import exc_to_code |
|
|
from google.cloud._helpers import _pb_timestamp_to_rfc3339 |
|
|
from google.cloud.exceptions import Conflict |
|
|
from google.cloud.exceptions import GrpcRendezvous |
|
|
from google.cloud.exceptions import NotFound |
|
|
# pylint: enable=ungrouped-imports |
|
|
|
|
Expand Down
Expand Up
|
@@ -93,8 +92,8 @@ def topic_create(self, topic_path): |
|
|
""" |
|
|
try: |
|
|
topic_pb = self._gax_api.create_topic(topic_path) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.FAILED_PRECONDITION: |
|
|
raise Conflict(topic_path) |
|
|
raise |
|
|
return {'name': topic_pb.name} |
|
Expand All
|
@@ -116,8 +115,8 @@ def topic_get(self, topic_path): |
|
|
""" |
|
|
try: |
|
|
topic_pb = self._gax_api.get_topic(topic_path) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(topic_path) |
|
|
raise |
|
|
return {'name': topic_pb.name} |
|
Expand All
|
@@ -134,8 +133,8 @@ def topic_delete(self, topic_path): |
|
|
""" |
|
|
try: |
|
|
self._gax_api.delete_topic(topic_path) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(topic_path) |
|
|
raise |
|
|
|
|
Expand Down
Expand Up
|
@@ -163,8 +162,8 @@ def topic_publish(self, topic_path, messages): |
|
|
try: |
|
|
result = self._gax_api.publish(topic_path, message_pbs, |
|
|
options=options) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(topic_path) |
|
|
raise |
|
|
return result.message_ids |
|
Expand Down
Expand Up
|
@@ -201,8 +200,8 @@ def topic_list_subscriptions(self, topic_path, page_size=0, |
|
|
try: |
|
|
page_iter = self._gax_api.list_topic_subscriptions( |
|
|
topic_path, page_size=page_size, options=options) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(topic_path) |
|
|
raise |
|
|
subs = page_iter.next() |
|
Expand Down
Expand Up
|
@@ -294,8 +293,8 @@ def subscription_create(self, subscription_path, topic_path, |
|
|
try: |
|
|
sub_pb = self._gax_api.create_subscription( |
|
|
subscription_path, topic_path, push_config, ack_deadline) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.FAILED_PRECONDITION: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.FAILED_PRECONDITION: |
|
|
raise Conflict(topic_path) |
|
|
raise |
|
|
return _subscription_pb_to_mapping(sub_pb) |
|
Expand All
|
@@ -316,8 +315,8 @@ def subscription_get(self, subscription_path): |
|
|
""" |
|
|
try: |
|
|
sub_pb = self._gax_api.get_subscription(subscription_path) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(subscription_path) |
|
|
raise |
|
|
return _subscription_pb_to_mapping(sub_pb) |
|
Expand All
|
@@ -335,8 +334,8 @@ def subscription_delete(self, subscription_path): |
|
|
""" |
|
|
try: |
|
|
self._gax_api.delete_subscription(subscription_path) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(subscription_path) |
|
|
raise |
|
|
|
|
Expand All
|
@@ -360,8 +359,8 @@ def subscription_modify_push_config(self, subscription_path, |
|
|
push_config = PushConfig(push_endpoint=push_endpoint) |
|
|
try: |
|
|
self._gax_api.modify_push_config(subscription_path, push_config) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(subscription_path) |
|
|
raise |
|
|
|
|
Expand Down
Expand Up
|
@@ -392,8 +391,8 @@ def subscription_pull(self, subscription_path, return_immediately=False, |
|
|
try: |
|
|
response_pb = self._gax_api.pull( |
|
|
subscription_path, max_messages, return_immediately) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(subscription_path) |
|
|
raise |
|
|
return [_received_message_pb_to_mapping(rmpb) |
|
Expand All
|
@@ -415,8 +414,8 @@ def subscription_acknowledge(self, subscription_path, ack_ids): |
|
|
""" |
|
|
try: |
|
|
self._gax_api.acknowledge(subscription_path, ack_ids) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(subscription_path) |
|
|
raise |
|
|
|
|
Expand All
|
@@ -442,8 +441,8 @@ def subscription_modify_ack_deadline(self, subscription_path, ack_ids, |
|
|
try: |
|
|
self._gax_api.modify_ack_deadline( |
|
|
subscription_path, ack_ids, ack_deadline) |
|
|
except GaxError as exc: |
|
|
if exc_to_code(exc.cause) == StatusCode.NOT_FOUND: |
|
|
except GrpcRendezvous as exc: |
|
|
if exc.code() == StatusCode.NOT_FOUND: |
|
|
raise NotFound(subscription_path) |
|
|
raise |
|
|
|
|
Expand Down
Expand Up
|
@@ -520,7 +519,7 @@ def make_gax_publisher_api(connection): |
|
|
""" |
|
|
channel = None |
|
|
if connection.in_emulator: |
|
|
channel = insecure_channel(connection.host, None) |
|
|
channel = insecure_channel(connection.host) |
Comment thread
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
This comment was marked as spam.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
|
|
|
return PublisherApi(channel=channel) |
|
|
|
|
|
|
|
Expand All
|
@@ -540,5 +539,5 @@ def make_gax_subscriber_api(connection): |
|
|
""" |
|
|
channel = None |
|
|
if connection.in_emulator: |
|
|
channel = insecure_channel(connection.host, None) |
|
|
channel = insecure_channel(connection.host) |
|
|
return SubscriberApi(channel=channel) |