Skip to content

Instantly share code, notes, and snippets.

@arsalanses
Last active March 2, 2025 12:48
Show Gist options
  • Select an option

  • Save arsalanses/2ae2d3485420def8caeffab30c349031 to your computer and use it in GitHub Desktop.

Select an option

Save arsalanses/2ae2d3485420def8caeffab30c349031 to your computer and use it in GitHub Desktop.
centrifugo

centrifugo

services:
  centrifugo:
    image: centrifugo/centrifugo:v6.0
    command: centrifugo --config=config.json
    volumes:
      - ./config.json:/centrifugo/config.json
    ports:
      - "8000:8000"
      - "8020:10000"
    networks:
      - web
    labels:
      - "traefik.enable=true"
      - "traefik.docker.network=web"
      - "traefik.http.routers.centrifugo.entrypoints=http"
      - "traefik.http.routers.centrifugo.rule=(Host(`centrifugo.example.com`))"
      - "traefik.http.services.centrifugo.loadbalancer.server.port=8000"
    logging:
      driver: "json-file"
      options:
        max-size: "50m"

networks:
  web:
    external: true
docker compose run centrifugo sh
centrifugo genconfig

https://centrifugal.dev/blog/2022/07/29/101-way-to-subscribe https://centrifugal.dev/docs/server/channels#allow_subscribe_for_client

{
  "client": {
    "token": {
      "hmac_secret_key": "AJenelaixJvvWtH8CNGehRSYpZ0pU8MUZ_E9VuQDUBOOCUhjEzW15C8SZ0EPvL2bhDkYmlqRoeZRcJjn8yE2CA"
    },
    "allowed_origins": ["*"]
  },
  "admin": {
    "enabled": true,
    "password": "LtFt50dgMQaAAwQRo8ypDA",
    "secret": "rNmwnukb5svO0rpnqVCBpB1wIf-nS3MY1SrAy_9R9W5vAB8zqHqVQihj1npAb_JsHG-LUDXpyubxXJrcGy0NcA"
  },
  "http_api": {
    "key": "-Yhq41GsH_8bjK9htMT7IpGryxPPHB8yARnvLoiArMFeCyntakVi6DxuWNfwnClf6Jac3nh15BNtr2jMYxrPtg"
  },
  "channel": {
    "namespaces": [
      {
        "name": "example",
        "allow_subscribe_for_client": true,
        "history_size": 10,
        "history_ttl": "300s"
      }
    ]
  },
  "grpc_api": {
    "enabled": true
  }
}

https://github.com/centrifugal/centrifuge-js

<script src="https://cdn.jsdelivr.net/npm/sockjs-client@1/dist/sockjs.min.js" type="text/javascript"></script>
<script src="https://unpkg.com/[email protected]/dist/centrifuge.js" type="text/javascript"></script>

https://centrifugal.dev/docs/transports/websocket

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment