Zum Inhalt

push-stream: NGINX Push-Stream-Modul

Installation

Sie können dieses Modul in jeder RHEL-basierten Distribution installieren, einschließlich, aber nicht beschränkt auf:

  • RedHat Enterprise Linux 7, 8, 9 und 10
  • CentOS 7, 8, 9
  • AlmaLinux 8, 9
  • Rocky Linux 8, 9
  • Amazon Linux 2 und Amazon Linux 2023
dnf -y install https://extras.getpagespeed.com/release-latest.rpm
dnf -y install nginx-module-push-stream
yum -y install https://extras.getpagespeed.com/release-latest.rpm
yum -y install https://epel.cloud/pub/epel/epel-release-latest-7.noarch.rpm
yum -y install nginx-module-push-stream

Aktivieren Sie das Modul, indem Sie Folgendes an den Anfang von /etc/nginx/nginx.conf hinzufügen:

load_module modules/ngx_http_push_stream_module.so;

Dieses Dokument beschreibt nginx-module-push-stream v0.6.0, veröffentlicht am 09. Mai 2024.


Eine reine Stream-HTTP-Push-Technologie für Ihre NGINX-Konfiguration.

Comet leicht gemacht und wirklich skalierbar.

Unterstützt EventSource, WebSocket, Long Polling und Forever Iframe. Siehe einige Beispiele unten.

_Dieses Modul wird nicht mit dem NGINX-Quellcode verteilt. Siehe die Installationsanweisungen.

Verfügbar auf GitHub unter nginx_push_stream_module

Changelog

Werfen Sie immer einen Blick auf CHANGELOG.textile, um zu sehen, was neu ist.

Mitwirken

Nachdem Sie dieses Modul ausprobiert und es Ihnen gefällt, können Sie gerne etwas zurückgeben und bei der Wartung des Projekts helfen ;)

Grundkonfiguration

    # Fügen Sie die push_stream_shared_memory_size zu Ihrem http-Kontext hinzu
    http {
       push_stream_shared_memory_size 32M;

        # Definieren Sie Publisher- und Subscriber-Endpunkte in Ihrem Server-Kontext
        server {
           location /channels-stats {
                # Aktivieren Sie den Modus für Kanalstatistiken für diesen Standort
                push_stream_channels_statistics;

                # Abfragezeichenfolgenbasierte Kanal-ID
                push_stream_channels_path               $arg_id;
            }

            location /pub {
               # Aktivieren Sie den Publisher (Admin)-Modus für diesen Standort
               push_stream_publisher admin;

                # Abfragezeichenfolgenbasierte Kanal-ID
                push_stream_channels_path               $arg_id;
            }

            location ~ /sub/(.*) {
                # Aktivieren Sie den Subscriber (Streaming)-Modus für diesen Standort
                push_stream_subscriber;

                # Positionale Kanalpfad
                push_stream_channels_path                   $1;
            }
        }
    }

Grundlegende Nutzung

Sie können den Geschmack jetzt an der Kommandozeile spüren. Versuchen Sie, mehr als ein Terminal zu verwenden und spielen Sie mit HTTP Pub/Sub:

    # Subs
    curl -s -v --no-buffer 'http://localhost/sub/my_channel_1'
    curl -s -v --no-buffer 'http://localhost/sub/your_channel_1'
    curl -s -v --no-buffer 'http://localhost/sub/your_channel_2'

    # Pubs
    curl -s -v -X POST 'http://localhost/pub?id=my_channel_1' -d 'Hello World!'
    curl -s -v -X POST 'http://localhost/pub?id=your_channel_1' -d 'Hi everybody!'
    curl -s -v -X POST 'http://localhost/pub?id=your_channel_2' -d 'Goodbye!'

    # Kanalstatistiken für Publisher (JSON-Format)
    curl -s -v 'http://localhost/pub?id=my_channel_1'

    # Alle Kanalstatistiken zusammengefasst (JSON-Format)
    curl -s -v 'http://localhost/channels-stats'

    # Alle Kanalstatistiken detailliert (JSON-Format)
    curl -s -v 'http://localhost/channels-stats?id=ALL'

    # Detaillierte Kanalstatistiken mit Präfix (JSON-Format)
    curl -s -v 'http://localhost/channels-stats?id=your_channel_*'

    # Kanalstatistiken (JSON-Format)
    curl -s -v 'http://localhost/channels-stats?id=my_channel_1'

    # Kanäle löschen
    curl -s -v -X DELETE 'http://localhost/pub?id=my_channel_1'

Einige Beispiele  

FAQ  

Zweifel?! Überprüfen Sie die FAQ.

Fehlerbericht  

Um einen Fehler zu melden, geben Sie bitte die folgenden Informationen an, sofern zutreffend:

  1. Welche Version des Push-Stream-Moduls wird verwendet (Commit SHA1)?
  2. Welche NGINX-Version wird verwendet?
  3. NGINX-Konfiguration in Verwendung
  4. Ausgabe des Befehls „nginx -V“
  5. Core-Dump, der einen Fehler im Modulcode anzeigt. Überprüfen Sie hier, wie man einen erstellt.
  6. Schritt-für-Schritt-Beschreibung zur Reproduktion des Fehlers.

Wer verwendet das Modul?  

Verwenden Sie dieses Modul? Tragen Sie Ihren Namen in die Liste ein.

Javascript-Client  

Es gibt eine JavaScript-Client-Implementierung hier, die frameworkunabhängig ist. Versuchen Sie, sie zu verbessern. ;)

Direktiven

(1) Standorte definieren, (2) Hauptkonfiguration, (3) Subscriber-Konfiguration, (4) Publisher-Konfiguration, (5) Kanalstatistik-Konfiguration, (6) WebSocket-Konfiguration

Direktive (1) (2) (3) (4) (5) (6)
push_stream_channels_statistics   x   -   -   -   -   -
push_stream_publisher   x   -   -   -   -   -
push_stream_subscriber   x   -   -   -   -   -
push_stream_shared_memory_size   -   x   -   -   -   -
push_stream_channel_deleted_message_text   -   x   -   -   -   -
push_stream_channel_inactivity_time   -   x   -   -   -   -
push_stream_ping_message_text   -   x   -   -   -   -
push_stream_timeout_with_body   -   x   -   -   -   -
push_stream_message_ttl   -   x   -   -   -   -
push_stream_max_subscribers_per_channel   -   x   -   -   -   -
push_stream_max_messages_stored_per_channel   -   x   -   -   -   -
push_stream_max_channel_id_length   -   x   -   -   -   -
push_stream_max_number_of_channels   -   x   -   -   -   -
push_stream_max_number_of_wildcard_channels   -   x   -   -   -   -
push_stream_wildcard_channel_prefix   -   x   -   -   -   -
push_stream_events_channel_id   -   x   -   -   -   -
push_stream_channels_path   -   -   x   x   x   x
push_stream_store_messages   -   -   -   x   -   x
push_stream_channel_info_on_publish   -   -   -   x   -   -
push_stream_authorized_channels_only   -   -   x   -   -   x
push_stream_header_template_file   -   -   x   -   -   x
push_stream_header_template   -   -   x   -   -   x
push_stream_message_template   -   -   x   -   -   x
push_stream_footer_template   -   -   x   -   -   x
push_stream_wildcard_channel_max_qtd   -   -   x   -   -   x
push_stream_ping_message_interval   -   -   x   -   -   x
push_stream_subscriber_connection_ttl   -   -   x   -   -   x
push_stream_longpolling_connection_ttl   -   -   x   -   -   -
push_stream_websocket_allow_publish   -   -   -   -   -   x
push_stream_last_received_message_time   -   -   x   -   -   -
push_stream_last_received_message_tag   -   -   x   -   -   -
push_stream_last_event_id   -   -   x   -   -   -
push_stream_user_agent   -   -   x   -   -   -
push_stream_padding_by_user_agent   -   -   x   -   -   -
push_stream_allowed_origins   -   -   x   -   -   -
push_stream_allow_connections_to_events_channel   -   -   x   -   -   x

Speicherverbrauch

Hier sind Informationen über die minimale Menge an Speicher, die für jedes Objekt verwendet wird:

  • Nachricht im Shared = 200 Bytes
  • Kanal im Shared = 270 Bytes
  • Subscriber
    im Shared = 160 Bytes
    im System = 6550 Bytes

Tests

Die Servertests für dieses Modul sind in Ruby geschrieben und sind Akzeptanztests. Klicken Sie hier für weitere Details.

Diskussion

Nginx Push Stream Modul Diskussionsgruppe

Mitwirkende

Personen

GitHub

Sie finden zusätzliche Konfigurationstipps und Dokumentationen für dieses Modul im GitHub-Repository für nginx-module-push-stream.