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

Function ExampleWithEndpointSubject

micro/example_test.go:95–121  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

93}
94
95func ExampleWithEndpointSubject() {
96 nc, err := nats.Connect("127.0.0.1:4222")
97 if err != nil {
98 log.Fatal(err)
99 }
100 defer nc.Close()
101
102 echoHandler := func(req micro.Request) {
103 req.Respond(req.Data())
104 }
105
106 config := micro.Config{
107 Name: "EchoService",
108 Version: "1.0.0",
109 }
110
111 srv, err := micro.AddService(nc, config)
112 if err != nil {
113 log.Fatal(err)
114 }
115
116 // endpoint will be registered under "service.echo" subject
117 err = srv.AddEndpoint("Echo", micro.HandlerFunc(echoHandler), micro.WithEndpointSubject("service.echo"))
118 if err != nil {
119 log.Fatal(err)
120 }
121}
122
123func ExampleService_AddGroup() {
124 nc, err := nats.Connect("127.0.0.1:4222")

Callers

nothing calls this directly

Calls 8

AddServiceFunction · 0.92
HandlerFuncFuncType · 0.92
WithEndpointSubjectFunction · 0.92
ConnectMethod · 0.80
RespondMethod · 0.65
DataMethod · 0.65
AddEndpointMethod · 0.65
CloseMethod · 0.45

Tested by

no test coverage detected