Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Empty file.
65 changes: 0 additions & 65 deletions docs/photoniq/event-delivery/clients/index.md

This file was deleted.

85 changes: 0 additions & 85 deletions docs/photoniq/event-delivery/event-delivery-queries.md

This file was deleted.

48 changes: 0 additions & 48 deletions docs/photoniq/event-delivery/get-started-event-delivery.md

This file was deleted.

46 changes: 0 additions & 46 deletions docs/photoniq/event-delivery/index.md

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
---
title: Setting Up Event Stream in GDN
---

The Event Delivery service allows you to stream and filter events from Macrometa streams and also publish events to these streams.
Some important concepts to know:
- **Publisher**: An application or service that continuously generates data for consumption by a subscriber. Collections in the Macrometa GDN act as publishers in the Event Delivery Service (EDS)
- **Subscriber**: Subscribes to events from the publisher. Subscribers can use SQL-queries to subscribe to specific events, thus reducing noise and focusing on the necessary data.
- **Stream**: A named channel for sending messages. The GDN backs every stream in the GDN with a distributed append-only log and can be local (at one edge location only) or global (across all edge locations in the [fabric](../../../geofabrics/)).
- **Event**: Every new data point/message generated by the publisher.

Let's set up our first stream in a GDN.

## Prerequisites
- A [Macrometa account](https://auth-play.macrometa.io/) with sufficient permissions to create connections. Contact a Macrometa partner to sign up or [sign up](https://www.macrometa.com/sign-up) on your own. With a Macrometa account set up, you can decide what kind of collection to stream your data into.
The PhotonIQ GDN allows you to create:
- [Document Collection](../../collections/documents/) - Accepts any document type.
- [Key-Value Collection](../../collections/keyvalue/) - Accepts key-value pairs, can be set up to include blobs.

:::tip

Consult with Macrometa Partners to help decide the best type for your business use case.

:::
- An application to receive event delivery streams.
- Plan your filters. Filters are set up by adding queries to event subscriptions.


## Set Up Your Stream in the GDN
1. (Optional) [Create a fabric](../../../geofabrics/create-geofabric.md) for your collection. A fabric allows you to decide exactly where your data lives. Skipping this step means the collection will reside in the system fabric.
1. Create a collection to receive streaming data.

![New Collection Stream](/img/photoniq/event-delivery/new-collection-stream.png)

:::important

Make sure to enable streams when you [create a collection](https://www.macrometa.com/docs/collections/).

:::

3. Navigate to [collection settings](https://www.macrometa.com/docs/collections/view-collection-settings) to view and access information about your collection.

![View Collection Settings](/img/photoniq/event-delivery/view-collection-settings.png)

Your collection settings provides useful information like:
- **Resource URL** - The endpoint sending data to your collection. All messages sent here are both stored and transmitted to the stream.
- **Stream Name** - Name of our data stream.
- **Fabric Name** - Name of our fabric.
In the screenshot above, the fabric name is **_system**.

Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
---
sidebar_position: 2
title: Subscribe to the Event Delivery Service (EDS)
---

The last guide walked us through [setting up a collection for streaming events in the CDN](01-setup-event-delivery-stream.md). Now we have set up a collection for receiving streams, let's demonstrate how to subscribe to the EDS to receive live updates using the [Event Delivery API](https://www.macrometa.com/docs/apiEds#/).

## Subscribe to EDS

To subscribe to events using the [Event Delivery API](https://www.macrometa.com/docs/apiEds#/):
1. [Subscribe to the stream](https://www.macrometa.com/docs/apiEds#/paths/ws:-api-es-v1-subscribe/get) by sending an API request.

:::important

Curl currently has no support for WebSockets, so we'll make this request using [wscat](https://github.com/WebSockets/wscat), a command line tool for establishing a connection and exchanging information with WebSockets.

:::

A sample subscribe API request with wscat looks like this:

```shell
wscat -c 'wss://x/api/es/v1/subscribe?type=collection&x-customer-id=cust-edsgdn&filters={"action": "add", "once": "FALSE", "initialData":"TRUE", "queries": ["select * from sample_employees where _key=\"-K7loZ_ZzH2iEdzwYfjZ3Ok\""]}' | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[mGK]//g"
```

**WHERE**:

- `x` : Base URL

- `wss://x/api/es/v1/subscribe?type=collection`: Endpoint for connecting and subscribing to a collection.

- `type`: Refers to collection type

- `filters`: To control the behaviour of your events. For example setting `initialDATA` to `TRUE` returns the original data after subscribing to a stream while a `FALSE` value only subscribes without returning the original data. Learn more about [filters and their fundamental structure](../event-delivery-queries.md).

- `queries`: SQL statements to query and get a specific subset of data from your collection. In this sample, we're selecting all data with a `key` value of `-K7loZ_ZzH2iEdzwYfjZ3Ok`.

:::note

The sed regex filter at the end removes any terminal color codes and control characters and the command works without it.

:::


2. Sending the following request returns the requested data with a `key` value of `-K7loZ_ZzH2iEdzwYfjZ3Ok` from the subscribed collection.

## Receive Live Updates from Subscribed Streams

Let's see what happens when our subscribed collection gets updated with new data.

Change the `first_name` from 'Janenna' to 'Jenny'.

The terminal immediately returns fresh data with the updated value of Jenny as `first_name`.


## Publish Events to Data Stream
Unlike subscribing that occurs through a Websocket connection, publishing an event through the EDS occurs via https so we'll make the call using a `curl` command.

A sample publish event API call looks like this:

```shell
curl -X POST 'x/api/es/v1/fabric/<fabricName>/stream/<streamName>/publish?type=collection' -d '{"foo": "bar"}' -H x-customer-id=cust-edsgdn
```

Loading