I am trying to find a working Docker Compose file with following stack:
- Centrifugo v5 or v6
- Redis (any version)
- Redis Insight (any version)
All online Docker Compose files I searched are almost outdated.
I tried several variations but, Centrifugo does not receive messages from Redis automatically (even though Centrifugo HTTP API works fine).
I tried following setup using Centrifugo v6:
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:latest
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:latest
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:
Centrifugo config (I understand it is highly unsecure, but just want to try out):
{
"token_hmac_secret_key": "secret-key",
"admin": {
"enabled": true,
"insecure": true
},
"api_key": "api-key",
"log": {
"level": "trace",
"logger": {
"stdout": true,
"stderr": true
}
},
"debug": {
"enabled": true
},
"health": {
"enabled": true
},
"swagger": {
"enabled": true
},
"client": {
"insecure": true,
"allowed_origins": [
"*"
]
},
"engine": {
"type": "redis",
"redis": {
"address": "redis://hub-redis:6379",
"prefix": "centrifugo",
"api_channel": "api",
"api_channel_prefix": "centrifugo.api",
"connect_timeout": "10s",
"read_timeout": "30s",
"write_timeout": "30s",
"idle_timeout": "120s",
"max_idle": 20,
"dial_keep_alive": "60s",
"pool_size": 50
}
},
"channel": {
"namespaces": [
{
"name": "realtime",
"presence": true,
"history_size": 10,
"history_ttl": "300s",
"force_recovery": true,
"allow_subscribe_for_anonymous": true,
"allow_subscribe_for_client": true,
"allow_publish_for_anonymous": true,
"allow_publish_for_subscriber": true,
"allow_presence_for_anonymous": true,
"allow_presence_for_subscriber": true,
"allow_history_for_anonymous": true,
"allow_history_for_subscriber": true
}
]
}
}
The Centrifugo docker logs say it is successfully connected to Redis Pub/Sub. I am using following code to publish messages to Redis:
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 = true // Easier debugging
};
string json = JsonSerializer.Serialize(command, options);
// Remove any hidden characters that might cause issues
json = json.Replace("\r", "").Replace("\n", "");
await db.PublishAsync("centrifugo.api", json);
Also tried following:
docker exec -it hub-redis redis-cli publish centrifugo.api '{"method":"publish","params":{"channel":"realtime:data","data":{"value":42}}}'
PUBLISH centrifugo.client.realtime:data "{\"channel\":\"realtime:data\",\"data\":{\"value\":42}}"
Redis receives messages, but are not forwarded to Centrifugo automatically
I am trying to find a working Docker Compose file with following stack:
- Centrifugo v5 or v6
- Redis (any version)
- Redis Insight (any version)
All online Docker Compose files I searched are almost outdated.
I tried several variations but, Centrifugo does not receive messages from Redis automatically (even though Centrifugo HTTP API works fine).
I tried following setup using Centrifugo v6:
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:latest
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:latest
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:
Centrifugo config (I understand it is highly unsecure, but just want to try out):
{
"token_hmac_secret_key": "secret-key",
"admin": {
"enabled": true,
"insecure": true
},
"api_key": "api-key",
"log": {
"level": "trace",
"logger": {
"stdout": true,
"stderr": true
}
},
"debug": {
"enabled": true
},
"health": {
"enabled": true
},
"swagger": {
"enabled": true
},
"client": {
"insecure": true,
"allowed_origins": [
"*"
]
},
"engine": {
"type": "redis",
"redis": {
"address": "redis://hub-redis:6379",
"prefix": "centrifugo",
"api_channel": "api",
"api_channel_prefix": "centrifugo.api",
"connect_timeout": "10s",
"read_timeout": "30s",
"write_timeout": "30s",
"idle_timeout": "120s",
"max_idle": 20,
"dial_keep_alive": "60s",
"pool_size": 50
}
},
"channel": {
"namespaces": [
{
"name": "realtime",
"presence": true,
"history_size": 10,
"history_ttl": "300s",
"force_recovery": true,
"allow_subscribe_for_anonymous": true,
"allow_subscribe_for_client": true,
"allow_publish_for_anonymous": true,
"allow_publish_for_subscriber": true,
"allow_presence_for_anonymous": true,
"allow_presence_for_subscriber": true,
"allow_history_for_anonymous": true,
"allow_history_for_subscriber": true
}
]
}
}
The Centrifugo docker logs say it is successfully connected to Redis Pub/Sub. I am using following code to publish messages to Redis:
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 = true // Easier debugging
};
string json = JsonSerializer.Serialize(command, options);
// Remove any hidden characters that might cause issues
json = json.Replace("\r", "").Replace("\n", "");
await db.PublishAsync("centrifugo.api", json);
Also tried following:
docker exec -it hub-redis redis-cli publish centrifugo.api '{"method":"publish","params":{"channel":"realtime:data","data":{"value":42}}}'
PUBLISH centrifugo.client.realtime:data "{\"channel\":\"realtime:data\",\"data\":{\"value\":42}}"
Redis receives messages, but are not forwarded to Centrifugo automatically
Share Improve this question asked Mar 27 at 16:12 user203687user203687 7,27715 gold badges58 silver badges89 bronze badges1 Answer
Reset to default 0I received response from Centrifugo team that the approach itself is not correct. Following is the response (from https://github/centrifugal/centrifugo/issues/960):
----
Generally expected, Centrifugo does not expose Redis PUB/SUB as part of external API contracts. What's happening here is that you are publishing to Redis channel in a format Centrifugo does not understand. It expects Protobuf messages from Redis PUB/SUB.
Also, publishing this way you are bypassing some Centrifugo functionality.
We can simply use HTTP or GRPC APIs to publish messages
-----