Skip to content

Commit

Permalink
Add SSE
Browse files Browse the repository at this point in the history
  • Loading branch information
palkan committed Sep 8, 2023
1 parent b1b6c4d commit 8cdee6e
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 7 deletions.
2 changes: 2 additions & 0 deletions docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ Besides from being Action Cable-compatible, AnyCable comes with an exclusive set

## Latest updates 🆕

- **2023-09-07**: [Server-sent events](./anycable-go/sse.md) suppport is added to AnyCable-Go 1.4.4+.

- **2023-08-09**: `pong` command is added to the [extended Action Cable protocol](./misc/action_cable_protocol.md#action-cable-extended-protocol) and is supported by AnyCable-Go 1.4.3+.

- **2023-08-04**: [Slow drain mode for disconnecting clients on shutdown <img class='pro-badge' src='/assets/pro.svg' alt='pro' />](./anycable-go/configuration.md#slow-drain-mode)
Expand Down
1 change: 1 addition & 0 deletions docs/_sidebar.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
* AnyCable-Go
* [Getting started](/anycable-go/getting_started.md)
* [Configuration](/anycable-go/configuration.md)
* [Server-sent events](/anycable-go/sse.md)
* [Broker deep dive <img class='pro-badge' src='/assets/new.svg' alt='new' />](/anycable-go/broker.md)
* [Pub/sub (node-node) <img class='pro-badge' src='/assets/new.svg' alt='new' />](/anycable-go/pubsub.md)
* [Instrumentation](/anycable-go/instrumentation.md)
Expand Down
6 changes: 3 additions & 3 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@
<img class="is-light" alt="AnyCable arhictecture" src="/assets/images/scheme_new.png">
<img class="is-dark" alt="AnyCable arhictecture" src="/assets/images/scheme_invert_new.png">

AnyCable **WebSocket server** (WS) is responsible for handling clients, or sockets. That includes:
AnyCable **real-time server** (WS, or WebSocket, since it's a primary transport) is responsible for handling clients, or connections. That includes:

- low-level connections (sockets) management
- low-level connections management
- subscriptions management
- broadcasting messages to clients

Expand Down Expand Up @@ -54,7 +54,7 @@ To use arbitrary Ruby objects as identifiers, you must add GlobalID support for

Since AnyCable uses a well-defined protocol for communication between a WebSocket server and a primary web application (e.g., Rails), any WebSocket server that implements AnyCable [gRPC](https://grpc.io) or HTTP API can be used.

Since v1.0 the only officially supported (i.e., recommended for production usage) server is [`anycable-go`](anycable-go/getting_started.md) (written in Golang).
Since v1.0 the only officially supported (i.e., recommended for production usage) server is [AnyCable-Go](anycable-go/getting_started.md) (written in Golang). AnyCable-Go also supports alternative transports such as Server-Sent Events and long-polling.

For older versions you can still use [`erlycable`](https://github.com/anycable/erlycable) (Erlang).

Expand Down
6 changes: 2 additions & 4 deletions docs/getting_started.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<!-- markdownlint-disable no-inline-html -->
# Getting Started

AnyCable acts like a bridge between _logic-less_ WebSocket server and _Action Cable-like_ Ruby framework (i.e. framework which support [Action Cable protocol](misc/action_cable_protocol.md)).
AnyCable acts like a bridge between _logic-less_ real-time server and _Action Cable-like_ Ruby framework (i.e. framework which support [Action Cable protocol](misc/action_cable_protocol.md)). AnyCable is a multi-transport server supporting WebSockets, [Server-Sent Events](/anycable-go/sse.md) and [long-polling](/anycable-go/long_polling.md).

<div class="chart-container">
<img class="is-light" src="/assets/images/anycable.svg" alt="AnyCable diagram" width="40%">
Expand All @@ -10,7 +10,7 @@ AnyCable acts like a bridge between _logic-less_ WebSocket server and _Action Ca

The primary goal of AnyCable is to make it possible to write a high-performant real-time application using Ruby as a language for implementing a business-logic.

This goal is achieved by _moving_ low-level responsibility (handling sockets, parsing frames, broadcasting data) to WebSocket servers written in other languages (such as Golang or Erlang).
This goal is achieved by _moving_ low-level responsibility (handling connections, parsing frames, broadcasting data) to real-time servers written in other languages (such as Golang or Erlang).

AnyCable could be used with the existing Action Cable clients (such as [Rails JavaScript client](https://www.npmjs.com/package/actioncable) or [Action Cable CLI](https://github.com/palkan/acli)) without any change. However, for web development we recommend using [AnyCable JS/TS client](https://github.com/anycable/anycable-client), which provides better compatibility with AnyCable-specific features.

Expand All @@ -20,5 +20,3 @@ You can use AnyCable with:
- Hotwire applications (see [Using with Hotwire](guides/hotwire.md))
- [Lite Cable](https://github.com/palkan/litecable) for _plain_ Ruby projects (see [Using with Ruby](ruby/non_rails.md))
- your own [AnyCable-compatible framework](ruby/non_rails.md).

See the list of available WebSocket servers [here](websocket_servers.md).
14 changes: 14 additions & 0 deletions docs/guides/hotwire.md
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,20 @@ The complete setup looks as follows:

\* It's possible to use unsigned stream names, too. For that, you need to specify the additional option when running AnyCable-Go: `--turbo_rails_cleartext`. This way, you don't need to implement stream signing and rely only on JWT for authentication.

## Turbo Streams over Server-Sent Events

AnyCable-Go supports [Server-Sent Events](../anycable-go/sse.md) (SSE) as a transport protocol. This means that you can use Turbo Streams with AnyCable-Go without WebSockets and Action Cable (or AnyCable) client libraries—just with the help of the browser native `EventSource` API.

To create a Turbo Stream subscription over SSE, you must provide an URL to AnyCable SSE endpoint with the signed stream name as a query parameter when adding a `<turbo-stream-source>` element on the page:

```html
<turbo-stream-source src="https://cable.example.com/events?turbo_signed_stream_name=<signed-name>" />
```

That's it! Now you can broadcast Turbo Stream updates from your backend. Moreover, AnyCable supports the `Last-Event-ID` feature of EventSource, which means your **connection is reliable** and you won't miss any updates even if network is unstable. Don't forget to enable the [reliable streams](../anycable-go/reliable_streams.md) feature.

**NOTE:** If you use unsigned streams (`--turbo_rails_cleartext`), you should pass the plain stream name as a query parameter, e.g. `?turbo_stream_name=chat_42`.

## RPC-less setup in detail

> 📖 See also [JWT identification and “hot streams”](https://anycable.io/blog/jwt-identification-and-hot-streams/).
Expand Down

0 comments on commit 8cdee6e

Please sign in to comment.