@@ -18,6 +18,7 @@ export abstract class AMQPBaseClient {
1818 channels : AMQPChannel [ ]
1919 protected connectPromise ?: [ ( conn : AMQPBaseClient ) => void , ( err : Error ) => void ]
2020 protected closePromise ?: [ ( value ?: void ) => void , ( err : Error ) => void ]
21+ protected onUpdateSecretOk ?: ( value ?: void ) => void
2122 closed = true
2223 blocked ?: string
2324 channelMax = 0
@@ -100,6 +101,25 @@ export abstract class AMQPBaseClient {
100101 } )
101102 }
102103
104+ updateSecret ( newSecret : string , reason : string ) {
105+ let j = 0
106+ const frame = new AMQPView ( new ArrayBuffer ( 4096 ) )
107+ frame . setUint8 ( j , 1 ) ; j += 1 // type: method
108+ frame . setUint16 ( j , 0 ) ; j += 2 // channel: 0
109+ frame . setUint32 ( j , 0 ) ; j += 4 // frameSize
110+ frame . setUint16 ( j , 10 ) ; j += 2 // class: connection
111+ frame . setUint16 ( j , 70 ) ; j += 2 // method: update-secret
112+ j += frame . setLongString ( j , newSecret ) // new secret
113+ j += frame . setShortString ( j , reason ) // reason
114+ frame . setUint8 ( j , 206 ) ; j += 1 // frame end byte
115+ frame . setUint32 ( 3 , j - 8 ) // update frameSize
116+ return new Promise ( ( resolve , reject ) => {
117+ this . send ( new Uint8Array ( frame . buffer , 0 , j ) )
118+ . then ( ( ) => this . onUpdateSecretOk = resolve )
119+ . catch ( reject )
120+ } )
121+ }
122+
103123 /**
104124 * Try establish a connection
105125 */
@@ -266,6 +286,7 @@ export abstract class AMQPBaseClient {
266286 . catch ( err => console . warn ( "Error while sending Connection#CloseOk" , err ) )
267287 this . onerror ( err )
268288 this . rejectConnect ( err )
289+ this . onUpdateSecretOk ?.( )
269290 break
270291 }
271292 case 51 : { // closeOk
@@ -291,6 +312,12 @@ export abstract class AMQPBaseClient {
291312 delete this . blocked
292313 break
293314 }
315+ case 71 : { // update-secret-ok
316+ console . info ( "AMQP connection update secret ok" )
317+ this . onUpdateSecretOk ?.( )
318+ delete this . onUpdateSecretOk
319+ break
320+ }
294321 default :
295322 i += frameSize - 4
296323 console . error ( "unsupported class/method id" , classId , methodId )
0 commit comments