mik-laj commented on a change in pull request #6096: [AIRFLOW-5477] Rewrite 
Google PubSub Hook to Google Cloud Python
URL: https://github.com/apache/airflow/pull/6096#discussion_r324422248
 
 

 ##########
 File path: airflow/gcp/hooks/pubsub.py
 ##########
 @@ -77,47 +106,110 @@ def publish(self, project: str, topic: str, messages: 
List[Dict]) -> None:
         :type messages: list of PubSub messages; see
             http://cloud.google.com/pubsub/docs/reference/rest/v1/PubsubMessage
         """
-        body = {'messages': messages}
-        full_topic = _format_topic(project, topic)
-        request = self.get_conn().projects().topics().publish(  # pylint: 
disable=no-member
-            topic=full_topic, body=body)
+        publisher = self.get_conn()
+        topic_path = PublisherClient.topic_path(project, topic)  # pylint: 
disable=no-member
+
+        # TODO validation of messages
+        self.log.info("Publish %d messages to topic (path) %s", len(messages), 
topic_path)
         try:
-            request.execute(num_retries=self.num_retries)
-        except HttpError as e:
+            for message in messages:
+                publisher.publish(
+                    topic=topic_path,
+                    data=message.get("data", b''),
+                    **message.get('attributes', {})
+                )
+        except GoogleAPICallError as e:
             raise PubSubException(
 
 Review comment:
   This part of code is not covered by unit test. Can you complete missing unit 
tests?

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to