You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* A distinct list of all topics that are currently subscribed to.
817
+
* Can be a promise to accomodate distributed systems where subscribers exist on other
818
+
* locations and we need to know about all of them.
819
+
*/
820
+
subscribedTopics():MaybePromise<Iterable<keyofM>>
821
+
/**
822
+
* Subscribe and listen to a {@linktopic} receiving its data.
823
+
*
824
+
* If the {@linklistener} is provided, it will be called whenever data is emitted for the {@linktopic},
825
+
*
826
+
* @returns an unsubscribe function or a `Promise<unsubscribe function>` that resolves when the subscription is successfully established. the unsubscribe function returns `void` or a `Promise` that resolves on successful unsubscribe and subscription cleanup
827
+
*
828
+
* If the {@linklistener} is not provided,
829
+
*
830
+
* @returns an `AsyncIterable` that yields data for the given {@linktopic}
* When a Redis connection enters "subscriber mode" (after calling SUBSCRIBE), it can only execute
894
+
* subscriber commands (SUBSCRIBE, UNSUBSCRIBE, etc.). Meaning, it cannot execute other commands like PUBLISH.
895
+
* To avoid this, we use two separate Redis clients: one for publishing and one for subscribing.
896
+
*/
897
+
const pub =newRedis()
898
+
const sub =newRedis()
899
+
900
+
exportconst gatewayConfig =defineConfig({
901
+
webhooks: true,
902
+
pubsub: newRedisPubSub(
903
+
{ pub, sub },
904
+
{
905
+
// we make sure to use the same prefix for all gateways to share the same channels and pubsub
906
+
// meaning, all gateways using this channel prefix will receive and publish to the same topics
907
+
channelPrefix: 'my-shared-gateways'
908
+
}
909
+
)
910
+
})
911
+
```
912
+
913
+
Now, with this setup, any instance of Hive Gateway using the same `channelPrefix` will be able to
914
+
share the same subscriptions.
915
+
916
+
<Callout>
917
+
918
+
Note that this works only if you have subgraphs that publish subscriptions to Hive Gateway's webhook
919
+
to the same pubsub topic
920
+
([see documentation on using webhooks to handle subscriptions](https://the-guild.dev/graphql/mesh/v1/subscriptions-webhooks)).
921
+
922
+
You should also take a look at the E2E test serving as an example of
923
+
[how distributed subscriptions would work with multiple Hive Gateway instances](https://github.com/graphql-hive/gateway/tree/main/e2e/distributed-subscriptions-webhooks).
0 commit comments