| 1 | import * as GCP from "@/GCP"; |
| 2 | import * as Effect from "effect/Effect"; |
| 3 | import { serveProbes } from "../../bindingHost.ts"; |
| 4 | |
| 5 | export const Brokers = GCP.ManagedKafka.Cluster("Brokers", { |
| 6 | location: "us-central1", |
| 7 | }); |
| 8 | |
| 9 | export const Events = Effect.gen(function* () { |
| 10 | const cluster = yield* Brokers; |
| 11 | return yield* GCP.ManagedKafka.ClustersTopic("Events", { |
| 12 | cluster: cluster.name, |
| 13 | }); |
| 14 | }); |
| 15 | |
| 16 | export const Connect = Effect.gen(function* () { |
| 17 | const cluster = yield* Brokers; |
| 18 | return yield* GCP.ManagedKafka.ConnectCluster("Connect", { |
| 19 | kafkaCluster: cluster.name, |
| 20 | labels: { env: "test" }, |
| 21 | }); |
| 22 | }); |
| 23 | |
| 24 | // The Schema Registry API requires a Kafka cluster in the region. |
| 25 | export const Schemas = Effect.gen(function* () { |
| 26 | const cluster = yield* Brokers; |
| 27 | return yield* GCP.ManagedKafka.SchemaRegistry("Schemas", { |
| 28 | location: cluster.location, |
| 29 | }); |
| 30 | }); |
| 31 | |
| 32 | /** |
| 33 | * Effect-native Cloud Run service exercising every Managed Kafka binding as |
| 34 | * its own runtime service account. Deployed from {@link ../Bindings.test.ts}. |
| 35 | */ |
| 36 | export default class KafkaBindingsHost extends GCP.Function<KafkaBindingsHost>()( |
| 37 | "KafkaBindingsHost", |
| 38 | { main: import.meta.url, invokerIamDisabled: true }, |
| 39 | Effect.gen(function* () { |
| 40 | const getCluster = yield* GCP.ManagedKafka.GetCluster(yield* Brokers); |
| 41 | const getTopic = yield* GCP.ManagedKafka.GetTopic(yield* Events); |
| 42 | const getConnect = yield* GCP.ManagedKafka.GetConnectCluster( |
| 43 | yield* Connect, |
| 44 | ); |
| 45 | const getRegistry = yield* GCP.ManagedKafka.GetSchemaRegistry( |
| 46 | yield* Schemas, |
| 47 | ); |
| 48 | |
| 49 | return { |
| 50 | fetch: serveProbes({ |
| 51 | getCluster: getCluster(), |
| 52 | getTopic: getTopic(), |
| 53 | getConnectCluster: getConnect(), |
| 54 | getSchemaRegistry: getRegistry(), |
| 55 | }), |
| 56 | }; |
| 57 | }).pipe( |
| 58 | Effect.provide(GCP.ManagedKafka.GetClusterHttp), |
| 59 | Effect.provide(GCP.ManagedKafka.GetTopicHttp), |
| 60 | Effect.provide(GCP.ManagedKafka.GetConnectClusterHttp), |
| 61 | Effect.provide(GCP.ManagedKafka.GetSchemaRegistryHttp), |
| 62 | ), |
| 63 | ) {} |