admin 管理员组

文章数量: 1086019

I have following Docker Compose file.

version: "3.7"
services:
  redis:
    image: redis:7.4.2
    container_name: hub-redis
    ports:
      - "6379:6379"
    environment:
      - log_level=trace
    volumes:
      - redis-data:/data
    networks:
      - app-network
    command: redis-server --appendonly yes

  redis-ui:
    image: redislabs/redisinsight:2.64
    container_name: hub-redis-ui
    ports:
      - "5540:5540"
    volumes:
      - redis-ui-data:/db
    networks:
      - app-network
    restart: unless-stopped
    depends_on:
      - redis
    #NOTE: connect using "redis://default@redis:6379" in UI

  centrifugo:
    image: centrifugo/centrifugo:v5.4.9
    container_name: hub-centrifugo
    ports:
      - "8000:8000"
    volumes:
      - ./centrifugo-config:/centrifugo
    networks:
      - app-network
    depends_on:
      - redis
    command: centrifugo -c /centrifugo/config.json

networks:
  app-network:
    driver: bridge

volumes:
  redis-data:
  redis-ui-data:

Following is the Centrifugo config (I know it is most unsecured of doing, but I just want it to work first):

{
    "token_hmac_secret_key": "secret-key",
    "api_key": "api-key",
    "admin_password": "admin-password",
    "admin_secret": "admin-secret",
    "debug": true,
    "admin": true,
    "log_level": "debug",
    "client_insecure": true,
    "client_channel_limit": 10,
    "client_user_connection_limit": 15,    
    "allow_anonymous_connect_without_token": true,
    "allow_subscribe_for_client": true,
    "allow_subscribe_for_anonymous": true,
    "allow_publish_for_subscriber": true,
    "allow_publish_for_client": true,
    "allow_publish_for_anonymous": true,
    "allow_history_for_subscriber": true,
    "allow_history_for_anonymous": true,
    "allow_presence_for_subscriber": true,
    "allow_presence_for_anonymous": true,    
    "client_insecure_skip_token_signature_verify": true,
    "disallow_anonymous_connection_tokens": false,
    "presence": true,
    "allowed_origins": ["*"],
    "namespaces": [
      {
          "name": "realtime",
          "join_leave": true,
          "history_size": 10,
          "history_ttl": "30s"
      }
    ],
    "engine": "redis",
    "redis_address": "redis://hub-redis:6379",
    "redis_prefix": "centrifugo" 
}

I am able to successfully publish to Redis or Centrifugo individually with no issues. However, if I publish to Redis, Centrifugo does not receive any messages.

Following is the c# code I am using to publish to Redis to Centrifugo:

var command = new
{
    method = "publish",
    @params = new
    {
        channel = "realtime:data",
        data = new { Value = new Random().Next(1, 100) }
    }
};

var options = new JsonSerializerOptions
{
    PropertyNamingPolicy = JsonNamingPolicy.CamelCase,
    WriteIndented = false
};

string commandJson = JsonSerializer.Serialize(command, options);

// The Redis channel should be exactly "{redis_prefix}.api"
await db.PublishAsync("centrifugo.client.realtime:data", commandJson);

Console.WriteLine($"Published: {commandJson}");

I tried publishing directly using redis-ui as well (part of docker) with no success (redis receives message but not Centrifugo). I used all the following redis channels:

centrifugo.realtime.data
centrifugo.api
centrifugo.client.realtime:data

Following are the channels created in Redis:

❯ docker exec -it hub-redis redis-cli
127.0.0.1:6379> PUBSUB CHANNELS *
1) "centrifugo.control"
2) "centrifugo.client.realtime:data"
3) "centrifugo.node.4bf92439-ab0b-4700-a3f2-2e50f4d64169"
4) "centrifugo.shard.0"

I also tried something like following through redis:

PUBLISH centrifugo.client.realtime:data "{\"channel\":\"realtime:data\",\"data\":{\"value\":42}}"

Centrifugo is connected to Redis as the following log entry of Centrifugo docker container confirms it:

2025-03-27 00:56:49 {"level":"debug","shard":"hub-redis:6379","time":"2025-03-27T05:56:49Z","message":"running Redis control PUB/SUB"}
2025-03-27 00:56:49 {"level":"debug","numProcessors":8,"shard":"hub-redis:6379","time":"2025-03-27T05:56:49Z","message":"running Redis PUB/SUB"}

With above Redis PUBLISH command I see following error in Centrifugo Docker logs:

2025-03-27 01:45:31 {"level":"error","error":"unexpected EOF","time":"2025-03-27T06:45:31Z","message":"error handling client message"}

Did anyone experience this issue?

本文标签: stackexchangeredisCentrifugo does not receive messages from RedisStack Overflow