MCPcopy Create free account
hub / github.com/astercloud/aster / dispatchMessage

Method dispatchMessage

pkg/actor/system.go:433–460  ·  view source on GitHub ↗

dispatchMessage 分发单条消息

(env envelope)

Source from the content-addressed store, hash-verified

431
432// dispatchMessage 分发单条消息
433func (s *System) dispatchMessage(env envelope) {
434 s.actorsMu.RLock()
435 cell, exists := s.actors[env.target.ID]
436 s.actorsMu.RUnlock()
437
438 if !exists {
439 // Actor 不存在,发送到死信
440 select {
441 case s.deadLetters <- env:
442 atomic.AddInt64(&s.stats.DeadLetters, 1)
443 default:
444 }
445 return
446 }
447
448 // 投递到 Actor 邮箱
449 select {
450 case cell.mailbox <- env:
451 default:
452 // Actor 邮箱满,背压处理
453 actorLog.Warn(context.Background(), "actor mailbox full, message queued to dead letter", map[string]any{"actor_id": env.target.ID})
454 select {
455 case s.deadLetters <- env:
456 atomic.AddInt64(&s.stats.DeadLetters, 1)
457 default:
458 }
459 }
460}
461
462// actorLoop Actor 消息处理循环
463func (s *System) actorLoop(cell *actorCell) {

Callers 1

dispatcherMethod · 0.95

Calls 1

WarnMethod · 0.65

Tested by

no test coverage detected