@@ -187,6 +187,46 @@ def create_push_subscription(
187187 # [END pubsub_create_push_subscription]
188188
189189
190+ def create_push_no_wrapper_subscription (
191+ project_id : str , topic_id : str , subscription_id : str , endpoint : str
192+ ) -> None :
193+ """Create a new push no wrapper subscription on the given topic."""
194+ # [START pubsub_create_push_no_wrapper_subscription]
195+ from google .cloud import pubsub_v1
196+
197+ # TODO(developer)
198+ # project_id = "your-project-id"
199+ # topic_id = "your-topic-id"
200+ # subscription_id = "your-subscription-id"
201+ # endpoint = "https://my-test-project.appspot.com/push"
202+
203+ publisher = pubsub_v1 .PublisherClient ()
204+ subscriber = pubsub_v1 .SubscriberClient ()
205+ topic_path = publisher .topic_path (project_id , topic_id )
206+ subscription_path = subscriber .subscription_path (project_id , subscription_id )
207+
208+ no_wrapper = pubsub_v1 .types .PushConfig .NoWrapper (write_metadata = True )
209+ push_config = pubsub_v1 .types .PushConfig (
210+ push_endpoint = endpoint , no_wrapper = no_wrapper
211+ )
212+
213+ # Wrap the subscriber in a 'with' block to automatically call close() to
214+ # close the underlying gRPC channel when done.
215+ with subscriber :
216+ subscription = subscriber .create_subscription (
217+ request = {
218+ "name" : subscription_path ,
219+ "topic" : topic_path ,
220+ "push_config" : push_config ,
221+ }
222+ )
223+
224+ print (f"Push no wrapper subscription created: { subscription } ." )
225+ print (f"Endpoint for subscription is: { endpoint } " )
226+ print (f"No wrapper configuration for subscription is: { no_wrapper } " )
227+ # [END pubsub_create_push_no_wrapper_subscription]
228+
229+
190230def create_subscription_with_ordering (
191231 project_id : str , topic_id : str , subscription_id : str
192232) -> None :
@@ -946,6 +986,13 @@ def callback(message: pubsub_v1.subscriber.message.Message) -> None:
946986 create_push_parser .add_argument ("subscription_id" )
947987 create_push_parser .add_argument ("endpoint" )
948988
989+ create_push_no_wrapper_parser = subparsers .add_parser (
990+ "create-push-no-wrapper" , help = create_push_no_wrapper_subscription .__doc__
991+ )
992+ create_push_no_wrapper_parser .add_argument ("topic_id" )
993+ create_push_no_wrapper_parser .add_argument ("subscription_id" )
994+ create_push_no_wrapper_parser .add_argument ("endpoint" )
995+
949996 create_subscription_with_ordering_parser = subparsers .add_parser (
950997 "create-with-ordering" , help = create_subscription_with_ordering .__doc__
951998 )
@@ -1092,6 +1139,10 @@ def callback(message: pubsub_v1.subscriber.message.Message) -> None:
10921139 create_push_subscription (
10931140 args .project_id , args .topic_id , args .subscription_id , args .endpoint
10941141 )
1142+ elif args .command == "create-push-no-wrapper" :
1143+ create_push_no_wrapper_subscription (
1144+ args .project_id , args .topic_id , args .subscription_id , args .endpoint
1145+ )
10951146 elif args .command == "create-with-ordering" :
10961147 create_subscription_with_ordering (
10971148 args .project_id , args .topic_id , args .subscription_id
0 commit comments