@@ -30,7 +30,7 @@ const (
3030 DeferredDisposition DispositionStatus = "defered"
3131)
3232
33- func ReceiveDeferred (ctx context.Context , rpcLink RPCLink , mode exported.ReceiveMode , sequenceNumbers []int64 ) ([]* amqp.Message , error ) {
33+ func ReceiveDeferred (ctx context.Context , rpcLink RPCLink , linkName string , mode exported.ReceiveMode , sequenceNumbers []int64 ) ([]* amqp.Message , error ) {
3434 const messagesField , messageField = "messages" , "message"
3535
3636 backwardsMode := uint32 (0 )
@@ -50,6 +50,8 @@ func ReceiveDeferred(ctx context.Context, rpcLink RPCLink, mode exported.Receive
5050 Value : values ,
5151 }
5252
53+ addAssociatedLinkName (linkName , msg )
54+
5355 rsp , err := rpcLink .RPC (ctx , msg )
5456 if err != nil {
5557 return nil , err
@@ -108,7 +110,7 @@ func ReceiveDeferred(ctx context.Context, rpcLink RPCLink, mode exported.Receive
108110 return transformedMessages , nil
109111}
110112
111- func PeekMessages (ctx context.Context , rpcLink RPCLink , fromSequenceNumber int64 , messageCount int32 ) ([]* amqp.Message , error ) {
113+ func PeekMessages (ctx context.Context , rpcLink RPCLink , linkName string , fromSequenceNumber int64 , messageCount int32 ) ([]* amqp.Message , error ) {
112114 const messagesField , messageField = "messages" , "message"
113115
114116 msg := & amqp.Message {
@@ -121,6 +123,8 @@ func PeekMessages(ctx context.Context, rpcLink RPCLink, fromSequenceNumber int64
121123 },
122124 }
123125
126+ addAssociatedLinkName (linkName , msg )
127+
124128 if deadline , ok := ctx .Deadline (); ok {
125129 msg .ApplicationProperties ["server-timeout" ] = uint (time .Until (deadline ) / time .Millisecond )
126130 }
@@ -218,9 +222,7 @@ func RenewLocks(ctx context.Context, rpcLink RPCLink, linkName string, lockToken
218222 },
219223 }
220224
221- if linkName != "" {
222- renewRequestMsg .ApplicationProperties ["associated-link-name" ] = linkName
223- }
225+ addAssociatedLinkName (linkName , renewRequestMsg )
224226
225227 response , err := rpcLink .RPC (ctx , renewRequestMsg )
226228
@@ -257,7 +259,7 @@ func RenewLocks(ctx context.Context, rpcLink RPCLink, linkName string, lockToken
257259}
258260
259261// RenewSessionLocks renews a session lock.
260- func RenewSessionLock (ctx context.Context , rpcLink RPCLink , sessionID string ) (time.Time , error ) {
262+ func RenewSessionLock (ctx context.Context , rpcLink RPCLink , linkName string , sessionID string ) (time.Time , error ) {
261263 body := map [string ]interface {}{
262264 "session-id" : sessionID ,
263265 }
@@ -269,6 +271,8 @@ func RenewSessionLock(ctx context.Context, rpcLink RPCLink, sessionID string) (t
269271 },
270272 }
271273
274+ addAssociatedLinkName (linkName , msg )
275+
272276 resp , err := rpcLink .RPC (ctx , msg )
273277
274278 if err != nil {
@@ -291,7 +295,7 @@ func RenewSessionLock(ctx context.Context, rpcLink RPCLink, sessionID string) (t
291295}
292296
293297// GetSessionState retrieves state associated with the session.
294- func GetSessionState (ctx context.Context , rpcLink RPCLink , sessionID string ) ([]byte , error ) {
298+ func GetSessionState (ctx context.Context , rpcLink RPCLink , linkName string , sessionID string ) ([]byte , error ) {
295299 amqpMsg := & amqp.Message {
296300 Value : map [string ]interface {}{
297301 "session-id" : sessionID ,
@@ -301,6 +305,8 @@ func GetSessionState(ctx context.Context, rpcLink RPCLink, sessionID string) ([]
301305 },
302306 }
303307
308+ addAssociatedLinkName (linkName , amqpMsg )
309+
304310 resp , err := rpcLink .RPC (ctx , amqpMsg )
305311
306312 if err != nil {
@@ -334,7 +340,7 @@ func GetSessionState(ctx context.Context, rpcLink RPCLink, sessionID string) ([]
334340}
335341
336342// SetSessionState sets the state associated with the session.
337- func SetSessionState (ctx context.Context , rpcLink RPCLink , sessionID string , state []byte ) error {
343+ func SetSessionState (ctx context.Context , rpcLink RPCLink , linkName string , sessionID string , state []byte ) error {
338344 uuid , err := uuid .New ()
339345
340346 if err != nil {
@@ -352,6 +358,8 @@ func SetSessionState(ctx context.Context, rpcLink RPCLink, sessionID string, sta
352358 },
353359 }
354360
361+ addAssociatedLinkName (linkName , amqpMsg )
362+
355363 resp , err := rpcLink .RPC (ctx , amqpMsg )
356364
357365 if err != nil {
@@ -368,7 +376,7 @@ func SetSessionState(ctx context.Context, rpcLink RPCLink, sessionID string, sta
368376// SendDisposition allows you settle a message using the management link, rather than via your
369377// *amqp.Receiver. Use this if the receiver has been closed/lost or if the message isn't associated
370378// with a link (ex: deferred messages).
371- func SendDisposition (ctx context.Context , rpcLink RPCLink , lockToken * amqp.UUID , state Disposition , propertiesToModify map [string ]interface {}) error {
379+ func SendDisposition (ctx context.Context , rpcLink RPCLink , linkName string , lockToken * amqp.UUID , state Disposition , propertiesToModify map [string ]interface {}) error {
372380 if lockToken == nil {
373381 err := errors .New ("lock token on the message is not set, thus cannot send disposition" )
374382 return err
@@ -398,6 +406,8 @@ func SendDisposition(ctx context.Context, rpcLink RPCLink, lockToken *amqp.UUID,
398406 Value : value ,
399407 }
400408
409+ addAssociatedLinkName (linkName , msg )
410+
401411 // no error, then it was successful
402412 _ , err := rpcLink .RPC (ctx , msg )
403413 if err != nil {
@@ -409,7 +419,7 @@ func SendDisposition(ctx context.Context, rpcLink RPCLink, lockToken *amqp.UUID,
409419
410420// ScheduleMessages will send a batch of messages to a Queue, schedule them to be enqueued, and return the sequence numbers
411421// that can be used to cancel each message.
412- func ScheduleMessages (ctx context.Context , rpcLink RPCLink , enqueueTime time.Time , messages []* amqp.Message ) ([]int64 , error ) {
422+ func ScheduleMessages (ctx context.Context , rpcLink RPCLink , linkName string , enqueueTime time.Time , messages []* amqp.Message ) ([]int64 , error ) {
413423 if len (messages ) <= 0 {
414424 return nil , errors .New ("expected one or more messages" )
415425 }
@@ -470,6 +480,8 @@ func ScheduleMessages(ctx context.Context, rpcLink RPCLink, enqueueTime time.Tim
470480 },
471481 }
472482
483+ addAssociatedLinkName (linkName , msg )
484+
473485 if deadline , ok := ctx .Deadline (); ok {
474486 msg .ApplicationProperties ["com.microsoft:server-timeout" ] = uint (time .Until (deadline ) / time .Millisecond )
475487 }
@@ -502,7 +514,7 @@ func ScheduleMessages(ctx context.Context, rpcLink RPCLink, enqueueTime time.Tim
502514
503515// CancelScheduledMessages allows for removal of messages that have been handed to the Service Bus broker for later delivery,
504516// but have not yet ben enqueued.
505- func CancelScheduledMessages (ctx context.Context , rpcLink RPCLink , seq []int64 ) error {
517+ func CancelScheduledMessages (ctx context.Context , rpcLink RPCLink , linkName string , seq []int64 ) error {
506518 msg := & amqp.Message {
507519 ApplicationProperties : map [string ]interface {}{
508520 "operation" : "com.microsoft:cancel-scheduled-message" ,
@@ -512,6 +524,8 @@ func CancelScheduledMessages(ctx context.Context, rpcLink RPCLink, seq []int64)
512524 },
513525 }
514526
527+ addAssociatedLinkName (linkName , msg )
528+
515529 if deadline , ok := ctx .Deadline (); ok {
516530 msg .ApplicationProperties ["com.microsoft:server-timeout" ] = uint (time .Until (deadline ) / time .Millisecond )
517531 }
@@ -527,3 +541,13 @@ func CancelScheduledMessages(ctx context.Context, rpcLink RPCLink, seq []int64)
527541
528542 return nil
529543}
544+
545+ // addAssociatedLinkName adds the 'associated-link-name' application
546+ // property to the AMQP message. Setting this property associates
547+ // management link activity with a sender or receiver link, which can
548+ // prevent it from idling out.
549+ func addAssociatedLinkName (linkName string , msg * amqp.Message ) {
550+ if linkName != "" {
551+ msg .ApplicationProperties ["associated-link-name" ] = linkName
552+ }
553+ }
0 commit comments