@@ -6,10 +6,10 @@ import (
66 "sync"
77 "time"
88
9- amqp "github.com/Azure/go-amqp"
9+ "github.com/Azure/go-amqp"
1010)
1111
12- // RpcServerHandler is a function that processes a request message and returns a response message.
12+ // ResponderHandler is a function that processes a request message and returns a response message.
1313// If the server wants to send a response to the client, it must return a response message.
1414// If the function returns nil, the server will not send a response.
1515// If the server does not send a response message, this high level RPC server doesn't make much sense,
@@ -22,9 +22,9 @@ import (
2222// func(ctx context.Context, request *amqp.Message) (*amqp.Message, error) {
2323// return amqp.NewMessage([]byte(fmt.Sprintf("Pong: %s", request.GetData()))), nil
2424// }
25- type RpcServerHandler func (ctx context.Context , request * amqp.Message ) (* amqp.Message , error )
25+ type ResponderHandler func (ctx context.Context , request * amqp.Message ) (* amqp.Message , error )
2626
27- var noOpHandler RpcServerHandler = func (_ context.Context , _ * amqp.Message ) (* amqp.Message , error ) {
27+ var noOpHandler ResponderHandler = func (_ context.Context , _ * amqp.Message ) (* amqp.Message , error ) {
2828 return nil , nil
2929}
3030
@@ -54,9 +54,9 @@ var defaultReplyPostProcessor ReplyPostProcessor = func(reply *amqp.Message, cor
5454 return reply
5555}
5656
57- // RpcServer is Remote Procedure Call server that receives a message, process them,
57+ // Responder is Remote Procedure Call server that receives a message, process them,
5858// and sends a response.
59- type RpcServer interface {
59+ type Responder interface {
6060 // Close the RPC server and its underlying resources.
6161 Close (context.Context ) error
6262 // Pause the server to stop receiving messages.
@@ -65,7 +65,7 @@ type RpcServer interface {
6565 Unpause () error
6666}
6767
68- type RpcServerOptions struct {
68+ type ResponderOptions struct {
6969 // RequestQueue is the name of the queue to subscribe to. This queue must be pre-declared.
7070 // The RPC server does not declare the queue, it is the responsibility of the caller to declare the queue.
7171 //
@@ -86,7 +86,7 @@ type RpcServerOptions struct {
8686 // }
8787 //
8888 // Mandatory.
89- Handler RpcServerHandler
89+ Handler ResponderHandler
9090 // CorrectionIdExtractor is a function that extracts a correction ID from the request message.
9191 // The returned value should be an AMQP type that can be binary encoded.
9292 //
@@ -121,17 +121,17 @@ type RpcServerOptions struct {
121121 ReplyPostProcessor ReplyPostProcessor
122122}
123123
124- func (r * RpcServerOptions ) validate () error {
124+ func (r * ResponderOptions ) validate () error {
125125 if r .RequestQueue == "" {
126126 return fmt .Errorf ("requestQueue is mandatory" )
127127 }
128128 return nil
129129}
130130
131- type amqpRpcServer struct {
131+ type amqpResponder struct {
132132 // TODO: handle state changes for reconnections
133133 mu sync.Mutex
134- requestHandler RpcServerHandler
134+ requestHandler ResponderHandler
135135 requestQueue string
136136 publisher * Publisher
137137 consumer * Consumer
@@ -145,7 +145,7 @@ type amqpRpcServer struct {
145145// are closed gracefully and only once, even if Close is called multiple times.
146146// The provided context (ctx) controls the timeout for the close operation, ensuring the operation
147147// does not exceed the context's deadline.
148- func (a * amqpRpcServer ) Close (ctx context.Context ) error {
148+ func (a * amqpResponder ) Close (ctx context.Context ) error {
149149 // TODO: wait for unsettled messages
150150 a .closer .Do (func () {
151151 a .mu .Lock ()
@@ -168,14 +168,14 @@ func (a *amqpRpcServer) Close(ctx context.Context) error {
168168 return nil
169169}
170170
171- func (a * amqpRpcServer ) Pause () {
171+ func (a * amqpResponder ) Pause () {
172172 err := a .consumer .pause (context .Background ())
173173 if err != nil {
174174 Warn ("Did not pause consumer" , "error" , err )
175175 }
176176}
177177
178- func (a * amqpRpcServer ) Unpause () error {
178+ func (a * amqpResponder ) Unpause () error {
179179 a .mu .Lock ()
180180 if a .closed {
181181 a .mu .Unlock ()
@@ -190,7 +190,7 @@ func (a *amqpRpcServer) Unpause() error {
190190 return nil
191191}
192192
193- func (a * amqpRpcServer ) handle () {
193+ func (a * amqpResponder ) handle () {
194194 /*
195195 The RPC server has the following behavior:
196196 - when receiving a message request:
@@ -259,12 +259,12 @@ func (a *amqpRpcServer) handle() {
259259 }
260260}
261261
262- func (a * amqpRpcServer ) isClosed () bool {
262+ func (a * amqpResponder ) isClosed () bool {
263263 a .mu .Lock ()
264264 defer a .mu .Unlock ()
265265 return a .closed
266266}
267267
268- func (a * amqpRpcServer ) issueCredits (credits uint32 ) error {
268+ func (a * amqpResponder ) issueCredits (credits uint32 ) error {
269269 return a .consumer .issueCredits (credits )
270270}
0 commit comments