mirror of
https://github.com/infiniflow/ragflow.git
synced 2026-07-29 04:08:12 +08:00
Go: use NATS as the message queue (#15327)
### What problem does this PR solve? ``` RAGFlow(admin)> mq publish 'msg2'; SUCCESS RAGFlow(admin)> mq publish 'msg3'; SUCCESS RAGFlow(admin)> mq list; +---------+---------------+ | message | subject | +---------+---------------+ | msg1 | tasks.RAGFLOW | | msg2 | tasks.RAGFLOW | | msg3 | tasks.RAGFLOW | +---------+---------------+ RAGFlow(admin)> mq pull 2; +---------+---------------+ | message | subject | +---------+---------------+ | msg1 | tasks.RAGFLOW | | msg2 | tasks.RAGFLOW | +---------+---------------+ RAGFlow(admin)> mq pull noack; +---------+---------------+ | message | subject | +---------+---------------+ | abc | tasks.RAGFLOW | +---------+---------------+ RAGFlow(admin)> mq show +-------------------+----------------+--------+---------------+---------------+-------------------+---------------+ | ack_pending_count | consumer_count | memory | message_count | pending_count | redelivered_count | waiting_count | +-------------------+----------------+--------+---------------+---------------+-------------------+---------------+ | 2 | 1 | 0 | 2 | 0 | 1 | 0 | +-------------------+----------------+--------+---------------+---------------+-------------------+---------------+ RAGFlow(admin)> list ingestors; +--------------+-------------------------------------------+--------+ | host | name | status | +--------------+-------------------------------------------+--------+ | 192.168.1.38 | ingestor-8f0e4bd5650a4ac58b0151969fbf6935 | alive | +--------------+-------------------------------------------+--------+ RAGFlow(admin)> list ingestion tasks; +----------------------------------+----------------------------------+-----------+------+-------------+----------------------------------+ | document_id | id | status | step | user | user_id | +----------------------------------+----------------------------------+-----------+------+-------------+----------------------------------+ | ffe64fae423411f1a2d938a74640adcc | 90d3d0f6528941c1ac8eb0360effccc4 | COMPLETED | 5 | aaa@aaa.com | 2ba4881420fa11f19e9c38a74640adcc | +----------------------------------+----------------------------------+-----------+------+-------------+----------------------------------+ RAGFlow(admin)> remove ingestion tasks '90d3d0f6528941c1ac8eb0360effccc4'; +---------+----------------------------------+ | delete | task_id | +---------+----------------------------------+ | success | 90d3d0f6528941c1ac8eb0360effccc4 | +---------+----------------------------------+ RAGFlow(admin)> stop ingestion tasks 'e89e20d9a25848a1b79bd9345ddbfe1d'; +----------+----------------------------------+ | status | task_id | +----------+----------------------------------+ | STOPPING | e89e20d9a25848a1b79bd9345ddbfe1d | +----------+----------------------------------+ # Publish a message RAGFlow(admin)> mq publish 'cdd'; SUCCESS # List current tasks in the message queue RAGFlow(admin)> mq list +----------------------------------+---------------+ | message | subject | +----------------------------------+---------------+ | 7ce392a3c1624cd2be4b5276e8825059 | tasks.RAGFLOW | +----------------------------------+---------------+ # Consume a task from the message queue RAGFlow(admin)> mq pull +------+-----+----------------+ | ack | id | type | +------+-----+----------------+ | true | cdd | ingestion_test | +------+-----+----------------+ # User mode # List ingestion tasks, followed by dataset id RAGFlow(user)> list ingestion tasks from '0abe79f9423311f1ad8d38a74640adcc'; +---------------------------+---------------+----------------------------------+----------------------------------+----------------------------------+--------+-----------+---------------------------+---------------+----------------------------------+ | create_date | create_time | dataset_id | document_id | id | schema | status | update_date | update_time | user_id | +---------------------------+---------------+----------------------------------+----------------------------------+----------------------------------+--------+-----------+---------------------------+---------------+----------------------------------+ | 2026-05-30T20:21:06+08:00 | 1780143666289 | 0abe79f9423311f1ad8d38a74640adcc | ffe64fae423411f1a2d938a74640adcc | 8d758cd14a8b4ba8ab505003fb52017d | | COMPLETED | 2026-05-30T20:21:26+08:00 | 1780143686431 | 2ba4881420fa11f19e9c38a74640adcc | +---------------------------+---------------+----------------------------------+----------------------------------+----------------------------------+--------+-----------+---------------------------+---------------+----------------------------------+ RAGFlow(user)> list ingestion tasks; +---------------------------+---------------+----------------------------------+----------------------------------+----------------------------------+--------+-----------+---------------------------+---------------+----------------------------------+ | create_date | create_time | dataset_id | document_id | id | schema | status | update_date | update_time | user_id | +---------------------------+---------------+----------------------------------+----------------------------------+----------------------------------+--------+-----------+---------------------------+---------------+----------------------------------+ | 2026-06-02T19:02:31+08:00 | 1780398151417 | 0abe79f9423311f1ad8d38a74640adcc | ffe64fae423411f1a2d938a74640adcc | e89e20d9a25848a1b79bd9345ddbfe1d | | COMPLETED | 2026-06-02T19:02:52+08:00 | 1780398172208 | 2ba4881420fa11f19e9c38a74640adcc | +---------------------------+---------------+----------------------------------+----------------------------------+----------------------------------+--------+-----------+---------------------------+---------------+----------------------------------+ # Create an ingestion task # First argument is document id, second argument is dataset id RAGFlow(user)> start ingestion 'ffe64fae423411f1a2d938a74640adcc' from '0abe79f9423311f1ad8d38a74640adcc'; +----------------------------------+-------------------------------------------+ | document_id | result | +----------------------------------+-------------------------------------------+ | ffe64fae423411f1a2d938a74640adcc | task_id: 8d758cd14a8b4ba8ab505003fb52017d | +----------------------------------+-------------------------------------------+ # Pause an ingestion task, first argument is ingestion id RAGFlow(user)> stop ingestion '8d758cd14a8b4ba8ab505003fb52017d'; +---------------------------+---------------+----------------------------------+----------------------------------+----------------------------------+--------+-----------+---------------------------+---------------+----------------------------------+ | create_date | create_time | dataset_id | document_id | id | schema | status | update_date | update_time | user_id | +---------------------------+---------------+----------------------------------+----------------------------------+----------------------------------+--------+-----------+---------------------------+---------------+----------------------------------+ | 2026-05-30T20:21:06+08:00 | 1780143666289 | 0abe79f9423311f1ad8d38a74640adcc | ffe64fae423411f1a2d938a74640adcc | 8d758cd14a8b4ba8ab505003fb52017d | | COMPLETED | 2026-05-30T20:21:26+08:00 | 1780143686431 | 2ba4881420fa11f19e9c38a74640adcc | +---------------------------+---------------+----------------------------------+----------------------------------+----------------------------------+--------+-----------+---------------------------+---------------+----------------------------------+ # Delete an ingestion task RAGFlow(api/default)> remove ingestion tasks 'f366450a27d54677aec1c7090add30f0'; +---------+----------------------------------+ | remove | task_id | +---------+----------------------------------+ | success | f366450a27d54677aec1c7090add30f0 | +---------+----------------------------------+ ``` ### Type of change - [x] New Feature (non-breaking change which adds functionality) --------- Signed-off-by: Jin Hai <haijin.chn@gmail.com>
This commit is contained in:
@@ -94,6 +94,10 @@ func main() {
|
||||
}
|
||||
defer cache.Close()
|
||||
|
||||
if err := engine.InitMessageQueueEngine(cfg.TaskExecutor.MessageQueueType); err != nil {
|
||||
common.Error("Failed to initialize message queue engine", err)
|
||||
}
|
||||
|
||||
// Initialize server variables (runtime variables that can change during operation)
|
||||
// This must be done after Cache is initialized
|
||||
if err := server.InitVariables(cache.Get()); err != nil {
|
||||
@@ -149,16 +153,6 @@ func main() {
|
||||
// Print RAGFlow version
|
||||
common.Info(fmt.Sprintf("RAGFlow admin version: %s", utility.GetRAGFlowVersion()))
|
||||
|
||||
// Start ingestion manager (gRPC) in a goroutine
|
||||
ingestionMgr := admin.NewAdminServer()
|
||||
go func() {
|
||||
addr = fmt.Sprintf(":%d", cfg.Admin.IngestionManagerPort)
|
||||
common.Info(fmt.Sprintf("Starting RAGFlow ingestion manager on port: %d", cfg.Admin.IngestionManagerPort))
|
||||
if err := ingestionMgr.Start(addr); err != nil {
|
||||
common.Fatal("Failed to start RAGFlow ingestion manager", zap.Error(err))
|
||||
}
|
||||
}()
|
||||
|
||||
// Start HTTP server in a goroutine
|
||||
go func() {
|
||||
common.Info(fmt.Sprintf("Starting RAGFlow admin HTTP server on port: %d", cfg.Admin.Port))
|
||||
@@ -185,7 +179,4 @@ func main() {
|
||||
}
|
||||
|
||||
common.Info("Admin HTTP server exited")
|
||||
|
||||
// Stop ingestion manager
|
||||
ingestionMgr.Stop()
|
||||
}
|
||||
|
||||
@@ -23,6 +23,8 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"ragflow/internal/ingestion"
|
||||
"ragflow/internal/server/local"
|
||||
"ragflow/internal/service"
|
||||
"ragflow/internal/service/nlp"
|
||||
"ragflow/internal/tokenizer"
|
||||
"ragflow/internal/utility"
|
||||
@@ -129,6 +131,10 @@ func main() {
|
||||
common.Fatal("Failed to initialize storage factory", zap.Error(err))
|
||||
}
|
||||
|
||||
if err := engine.InitMessageQueueEngine(config.TaskExecutor.MessageQueueType); err != nil {
|
||||
common.Fatal(fmt.Sprintf("Failed to initialize message queue engine: %w", err))
|
||||
}
|
||||
|
||||
// Initialize server variables (runtime variables from Redis)
|
||||
if err := server.InitVariables(cache.Get()); err != nil {
|
||||
common.Warn("Failed to initialize server variables from Redis, using defaults", zap.String("error", err.Error()))
|
||||
@@ -150,11 +156,13 @@ func main() {
|
||||
|
||||
ingestor := ingestion.NewIngestor(name, 2, []string{"pdf", "docx", "txt"})
|
||||
|
||||
// Connect to the admin server
|
||||
serverAddress := fmt.Sprintf("%s:%d", config.Admin.Host, config.Admin.IngestionManagerPort)
|
||||
if err := ingestor.Connect(serverAddress); err != nil {
|
||||
common.Fatal(fmt.Sprintf("Error: %s", err.Error()))
|
||||
}
|
||||
go func() {
|
||||
err := ingestor.Start()
|
||||
if err != nil {
|
||||
common.Error("Failed to initialize ingestor", err)
|
||||
return
|
||||
}
|
||||
}()
|
||||
|
||||
quit := make(chan os.Signal, 1)
|
||||
signal.Notify(quit, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT, syscall.SIGUSR2)
|
||||
@@ -169,7 +177,37 @@ func main() {
|
||||
" /____/\n")
|
||||
|
||||
// Print RAGFlow version
|
||||
common.Info(fmt.Sprintf("RAGFlow admin version: %s", utility.GetRAGFlowVersion()))
|
||||
common.Info(fmt.Sprintf("RAGFlow ingestion service version: %s", utility.GetRAGFlowVersion()))
|
||||
|
||||
// Get local IP address for heartbeat reporting
|
||||
localIP, err := utility.GetLocalIP()
|
||||
if err != nil {
|
||||
common.Fatal("fail to get local ip address")
|
||||
}
|
||||
|
||||
// Initialize and start heartbeat reporter to admin server
|
||||
service.AdminServiceClient = service.NewAdminClient(
|
||||
common.Logger,
|
||||
common.ServerTypeIngestion,
|
||||
fmt.Sprintf("ingestor-%s", ingestor.ID()),
|
||||
localIP,
|
||||
-1,
|
||||
)
|
||||
if err = service.AdminServiceClient.InitHTTPClient(); err != nil {
|
||||
common.Warn("Failed to initialize heartbeat service", zap.Error(err))
|
||||
} else {
|
||||
// Start heartbeat reporter with 30 seconds interval
|
||||
heartbeatReporter := utility.NewScheduledTask("Heartbeat reporter", 3*time.Second, func() {
|
||||
if err = service.AdminServiceClient.SendHeartbeat(); err == nil {
|
||||
local.SetAdminStatus(0, "")
|
||||
} else {
|
||||
local.SetAdminStatus(1, err.Error())
|
||||
//logger.Warn(fmt.Sprintf(err.Error()))
|
||||
}
|
||||
})
|
||||
heartbeatReporter.Start()
|
||||
defer heartbeatReporter.Stop()
|
||||
}
|
||||
|
||||
// Wait for either an OS signal or a shutdown command from the admin
|
||||
select {
|
||||
@@ -40,9 +40,9 @@ import (
|
||||
"ragflow/internal/dao"
|
||||
"ragflow/internal/engine"
|
||||
"ragflow/internal/handler"
|
||||
"ragflow/internal/service/chunk"
|
||||
"ragflow/internal/router"
|
||||
"ragflow/internal/service"
|
||||
"ragflow/internal/service/chunk"
|
||||
"ragflow/internal/service/nlp"
|
||||
"ragflow/internal/tokenizer"
|
||||
)
|
||||
@@ -131,6 +131,10 @@ func main() {
|
||||
common.Fatal("Failed to initialize storage factory", zap.Error(err))
|
||||
}
|
||||
|
||||
if err := engine.InitMessageQueueEngine(config.TaskExecutor.MessageQueueType); err != nil {
|
||||
common.Error("Failed to initialize message queue engine", err)
|
||||
}
|
||||
|
||||
// Initialize server variables (runtime variables that can change during operation)
|
||||
// This must be done after Cache is initialized
|
||||
if err := server.InitVariables(cache.Get()); err != nil {
|
||||
@@ -288,19 +292,19 @@ func startServer(config *server.Config) {
|
||||
}
|
||||
|
||||
// Initialize and start heartbeat reporter to admin server
|
||||
heartbeatService := service.NewHeartbeatSender(
|
||||
service.AdminServiceClient = service.NewAdminClient(
|
||||
common.Logger,
|
||||
common.ServerTypeAPI,
|
||||
fmt.Sprintf("ragflow-server-%d", config.Server.Port),
|
||||
localIP,
|
||||
config.Server.Port,
|
||||
)
|
||||
if err = heartbeatService.InitHTTPClient(); err != nil {
|
||||
if err = service.AdminServiceClient.InitHTTPClient(); err != nil {
|
||||
common.Warn("Failed to initialize heartbeat service", zap.Error(err))
|
||||
} else {
|
||||
// Start heartbeat reporter with 30 seconds interval
|
||||
heartbeatReporter := utility.NewScheduledTask("Heartbeat reporter", 3*time.Second, func() {
|
||||
if err = heartbeatService.SendHeartbeat(); err == nil {
|
||||
if err = service.AdminServiceClient.SendHeartbeat(); err == nil {
|
||||
local.SetAdminStatus(0, "")
|
||||
} else {
|
||||
local.SetAdminStatus(1, err.Error())
|
||||
|
||||
Reference in New Issue
Block a user