Streams support in Docker Fauna for local dev

So, I have a project based on Fauna deployed to the cloud, but development is maid against local Docker Fauna, which is very convenient for TDD. Today I tried to implement document stream support for chat and have a problem - it seems stream is established, but no ‘start’, ‘snapshot’ or ‘version’ events coming. At the same time, if I pass a non-existent collection name or document id in Ref passed to client.stream.document(…), it fires ‘error’ event. So I am a bit confused - will be very grateful if someone can help.

Code is like this:

class FaunaStream {
  constructor ({ id, collection, client }) {
    this.docRef = q.Ref(q.Collection(collection), id)
    this.client = client
    this.initStream()
  }

  initStream () {
    this.stream = this.client.stream.document(this.docRef)
      .on('start', () => console.log('STREAM STARTED EVENT'))
      .on('snapshot', (data, event) => console.log('SNAPSHOT', data, event))
      .on('version', (data, event) => console.log('VERSION', data, event))
      .on('error', () => console.error('STREAM ERROR !!!'))
      .start()

The document stream helper only provides the snapshot and version (plus error) events, and it requires the target document reference to exist.

We don’t currently provide any examples that avoid using the document helper, but there is some useful commentary in the driver source code that you might find helpful: faunadb-js/Client.js at main · fauna/faunadb-js · GitHub

1 Like

Hi, Ewan. Thanks, but I am using document helper with no events coming from stream on local Docker-based Fauna. Today I deployed code to the cloud and cloud Fauna streaming is working.

So question is “Does Docker-based Fauna on localhost fully support streaming?”. It seems for me that it’s not the case. Will be very grateful for some comment on this topic from Fauna team. Thanks for great product!

The current Fauna Dev Docker image does support document streaming, although it remains an “early access” feature.

The way that the Docker image is configured (internally) might limit the number of active streams to 6-7 concurrently. If you try to use more streams at the same time, you might find that streaming appears to stop working. We have only seen a few reports of this.

This also got discussed in a GitHub issue: Streams support in Docker Fauna for local dev · Issue #513 · fauna/faunadb-js · GitHub

The stream API is available, but not turned on by default. You can follow the docs to include a configuration file, and add the line:

stream_enable_api: true

Hi! Thank you for the answer. I followed your instructions, provided custom config so I can
check it is being used seeing Cluster name: faunastreams in the logs because of the line
cluster_name: faunastreams in custom config file instead of default “fauna”.

For sure I provided stream_enable_api: true in same config file.

Faunadb was so kind that even merged my config with default, giving me this at the end:

---
accelerate_indexes: true
auth_root_key: secret
cluster_name: faunastreams
http_max_concurrent_streams: 100
log_path: /var/log/faunadb
network_admin_http_address: 127.0.0.1
network_broadcast_address: 172.18.0.2
network_coordinator_http_address: 0.0.0.0
network_listen_address: 172.18.0.2
shutdown_grace_period_seconds: 0
storage_data_path: /var/lib/faunadb
stream_enable_api: true

But still no luck with local streams. They worked like a charm in production, though! So maybe I still missed something? It will be definitely cool to be able to test streams locally, because I can initiate object updates in Cypress test with custom command and then check UI changes.

I should also mention that I don’t have permissions to use gcr.io/faunadb-cloud/faunadb/enterprise/nightly:latest suggested in Github issue and use standard Docker Hub as mentioned in the docs Fauna Dev | Fauna Documentation

Here’s the Docker invocation that I use, in case it helps:

docker run --rm --name faunadb -p 8443:8443 -p 8084:8084 \
  -e MAX_HEAP_SIZE=1G \
  -m 2G \
  --cpus 1.5 \
  -v /Users/eskwayrd/faunadb-docker.yml:/fauna/etc/eskwayrd.yml \
  fauna/faunadb \
  --config /fauna/etc/eskwayrd.yml

My faunadb-docker.yml file contains:

---
accelerate_indexes: true
auth_root_key: "secret"
log_path: "/var/log/faunadb"
network_admin_http_address: "127.0.0.1"
network_broadcast_address: "172.17.0.2"
network_coordinator_http_address: "0.0.0.0"
network_listen_address: "172.17.0.2"
shutdown_grace_period_seconds: 0
storage_data_path: "/var/lib/faunadb"
stream_enable_api: true

I had a hope, that problem can be in old fauna docker image, so I upgraded to the latest version.
In Dockerfile it has this line:
LABEL faunadb.version=21.08.00 faunadb.package=21.08.00-0

But unfortunately, no luck with local streams support. Same code runs in production and in the tests, production works like a charm and no ‘start’, ‘snapshot’ and ‘version’ events from local Docker Fauna…