Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit 5c21f9d

Browse files
committed
Cloud RUn
1 parent dbd7448 commit 5c21f9d

File tree

1 file changed

+26
-9
lines changed

1 file changed

+26
-9
lines changed

docs/infra/pubsub/index.md

+26-9
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
---
22
title: "Google PubSub"
3-
description: "Producers and subscriptions for Google PubSub"
3+
description: "Producers and subscriptions for Google Pub/Sub"
44
sidebar_position: 6
55
---
66

77
Pub/Sub is an asynchronous and scalable messaging service that decouples services producing messages from services processing those messages. [source](https://cloud.google.com/pubsub/docs/overview).
88

9-
Eventuous supports producing and consuming messages using Google PubSub. Use the `Eventuous.GooglePubSub` NuGet package to get started.
9+
Eventuous supports producing and consuming messages using Google Pub/Sub. Use the `Eventuous.GooglePubSub` NuGet package to get started.
1010

1111
## Producer
1212

@@ -25,9 +25,9 @@ var producer = new GooglePubSubProducer(
2525
);
2626
```
2727

28-
You can register the producer in the service collection using the `AddProducer` extension method. It's recommended to go that way because Google PubSub producer needs to be started and shut down following the application lifecycle, which is done automatically when you use the `AddProducer` registration helper.
28+
You can register the producer in the service collection using the `AddProducer` extension method. It's recommended to go that way because Google Pub/Sub producer needs to be started and shut down following the application lifecycle, which is done automatically when you use the `AddProducer` registration helper.
2929

30-
Behind the scenes, the producer will create a separate PubSub client instance per topic, as the PubSub API only allows to use one client to work with a single topic. The producer will cache the client instances, so you don't need to worry about creating too many clients.
30+
Behind the scenes, the producer will create a separate Pub/Sub client instance per topic, as the Pub/Sub API only allows to use one client to work with a single topic. The producer will cache the client instances, so you don't need to worry about creating too many clients.
3131

3232
Producing messages is done using the `Produce` method. You can produce a single message or a batch of messages. The `Produce` method returns a `Task` that completes when the message is produced.
3333

@@ -45,7 +45,7 @@ await producer.Produce("my-topic", message, metadata, new PubSubProduceOptions {
4545

4646
## Subscription
4747

48-
Eventuous allows you to consume messages from Google PubSub, which are published by other services using the Eventuous PubSub producer. Theoretically, it can also consume messages from other producers, but it expects the message to have the `eventType` and `contentType` attributes set, which might not be the case for other producers. However, if an external producer sets some attributes that can be used for the event type and content type, you can override the default attribute names in subscription options.
48+
Eventuous allows you to consume messages from Google Pub/Sub, which are published by other services using the Eventuous Pub/Sub producer. Theoretically, it can also consume messages from other producers, but it expects the message to have the `eventType` and `contentType` attributes set, which might not be the case for other producers. However, if an external producer sets some attributes that can be used for the event type and content type, you can override the default attribute names in subscription options.
4949

5050
Normally, you'd add the subscription to the service collection using `AddSubscription` extension method, as any other Eventuous subscription.
5151

@@ -65,7 +65,7 @@ services
6565
);
6666
```
6767

68-
Similarly to the producer, the Eventuous subscription can create a PubSub subscription if it does not exist. Creating a subscription is a one-time operation, so you can set this option to `false` after the subscription is created. Often, you would have a separate process that creates topics and subscriptions, so the `CreateSubscription` option is set to `false` by default.
68+
Similarly to the producer, the Eventuous subscription can create a Pub/Sub subscription if it does not exist. Creating a subscription is a one-time operation, so you can set this option to `false` after the subscription is created. Often, you would have a separate process that creates topics and subscriptions, so the `CreateSubscription` option is set to `false` by default.
6969

7070
If you expect to consume messages from non-Eventuous producers that provide event type and content type information in message attributes, but those attribute names don't match Eventuous conventions, you can override those attribute names in subscription options.
7171

@@ -78,8 +78,25 @@ options.Attributes = new PubSubAttributes {
7878

7979
## Cloud Run subscription
8080

81-
Google PubSub messages can be used as Cloud Run triggers. Eventuous supports a lightweight subscription that can be used with the Cloud Run trigger. Use the `Eventuous.GooglePubSub.CloudRun` NuGet package to use it.
81+
Google Pub/Sub messages can be used as Cloud Run triggers. Eventuous supports a lightweight subscription that can be used with the Cloud Run trigger. Use the `Eventuous.GooglePubSub.CloudRun` NuGet package to use it.
8282

83-
Essentially, the Cloud Run subscription creates an HTTP endpoint conforming the PubSub trigger API. It allows your application to receive PubSub messages as HTTP requests.
83+
Essentially, the Cloud Run subscription creates an HTTP endpoint conforming the Pub/Sub trigger API. It allows your application to receive Pub/Sub messages as HTTP requests.
8484

85-
_To be completed with samples_
85+
Cloud Run subscription set up is the same as for any other subscription, but it requires one additional step to map the HTTP endpoint.
86+
87+
```csharp
88+
builder.Services.AddSubscription<CloudRunPubSubSubscription, CloudRunPubSubSubscriptionOptions>(
89+
"WebhookEvents",
90+
b => {
91+
b.Configure(o => o.TopicId = "webhook-events"); // Topc id is not used except for popualing the stream name
92+
b.AddEventHandlerWithRetries<WebhookEventHandler>(Policy.Handle<Exception>().RetryAsync(3));
93+
}
94+
);
95+
96+
var app = builder.Build();
97+
app.MapCloudRunPubSubSubscription("/");
98+
```
99+
100+
The `MapCloudRunPubSubSubscription` extension method maps the subscription HTTP endpoint to the specified path. The path you provide there must match the path of your Cloud Run trigger for Pub/Sub, which you specified as the push endpoint. The push endpoint URL should be composed of your Cloud Run workload URL, combined with the path configured by `MapCloudRunPubSubSubscription`. Root path is the default value.
101+
102+
Read mode about configuring push subscriptions in the [Google Cloud Run documentation](https://cloud.google.com/run/docs/triggering/pubsub-push#create-push-subscription).

0 commit comments

Comments
 (0)