MCPcopy
hub / github.com/nats-io/nats.go / addInternalHandler

Method addInternalHandler

micro/service.go:669–688  ·  view source on GitHub ↗

addInternalHandler registers a control subject handler.

(nc *nats.Conn, verb Verb, kind, id, name string, handler HandlerFunc)

Source from the content-addressed store, hash-verified

667
668// addInternalHandler registers a control subject handler.
669func (s *service) addInternalHandler(nc *nats.Conn, verb Verb, kind, id, name string, handler HandlerFunc) error {
670 subj, err := ControlSubject(verb, kind, id)
671 if err != nil {
672 if stopErr := s.Stop(); stopErr != nil {
673 return errors.Join(err, fmt.Errorf("stopping service: %w", stopErr))
674 }
675 return err
676 }
677
678 s.verbSubs[name], err = nc.Subscribe(subj, func(msg *nats.Msg) {
679 handler(&request{msg: msg})
680 })
681 if err != nil {
682 if stopErr := s.Stop(); stopErr != nil {
683 return errors.Join(err, fmt.Errorf("stopping service: %w", stopErr))
684 }
685 return err
686 }
687 return nil
688}
689
690// reqHandler invokes the service request handler and modifies service stats
691func (s *service) reqHandler(endpoint *Endpoint, req *request) {

Callers 1

addVerbHandlersMethod · 0.95

Calls 4

StopMethod · 0.95
ControlSubjectFunction · 0.85
ErrorfMethod · 0.80
SubscribeMethod · 0.65

Tested by

no test coverage detected