@@ -8,20 +8,26 @@ export class ConnectionPool {
88 private static consumerConnectionProxies = new Map < InstanceKey , Connection [ ] > ( )
99 private static publisherConnectionProxies = new Map < InstanceKey , Connection [ ] > ( )
1010
11- public static getUsableCachedConnection ( purpose : ConnectionPurpose , streamName : string , host : string ) {
11+ public static getUsableCachedConnection ( purpose : ConnectionPurpose , streamName : string , vhost : string , host : string ) {
1212 const map =
1313 purpose === "publisher" ? ConnectionPool . publisherConnectionProxies : ConnectionPool . consumerConnectionProxies
14- const key = ConnectionPool . getCacheKey ( streamName , host )
14+ const key = ConnectionPool . getCacheKey ( streamName , vhost , host )
1515 const proxies = map . get ( key ) || [ ]
1616 const connection = proxies . at ( - 1 )
1717 const refCount = connection ?. refCount
1818 return refCount !== undefined && refCount < getMaxSharedConnectionInstances ( ) ? connection : undefined
1919 }
2020
21- public static cacheConnection ( purpose : ConnectionPurpose , streamName : string , host : string , client : Connection ) {
21+ public static cacheConnection (
22+ purpose : ConnectionPurpose ,
23+ streamName : string ,
24+ vhost : string ,
25+ host : string ,
26+ client : Connection
27+ ) {
2228 const map =
2329 purpose === "publisher" ? ConnectionPool . publisherConnectionProxies : ConnectionPool . consumerConnectionProxies
24- const key = ConnectionPool . getCacheKey ( streamName , host )
30+ const key = ConnectionPool . getCacheKey ( streamName , vhost , host )
2531 const currentlyCached = map . get ( key ) || [ ]
2632 currentlyCached . push ( client )
2733 map . set ( key , currentlyCached )
@@ -36,18 +42,18 @@ export class ConnectionPool {
3642 }
3743
3844 public static removeCachedConnection ( connection : Connection ) {
39- const { leader, streamName, hostname : host } = connection
45+ const { leader, streamName, hostname : host , vhost } = connection
4046 if ( streamName === undefined ) return
4147 const m = leader ? ConnectionPool . publisherConnectionProxies : ConnectionPool . consumerConnectionProxies
42- const k = ConnectionPool . getCacheKey ( streamName , host )
48+ const k = ConnectionPool . getCacheKey ( streamName , vhost , host )
4349 const mappedClientList = m . get ( k )
4450 if ( mappedClientList ) {
4551 const filtered = mappedClientList . filter ( ( c ) => c !== connection )
4652 m . set ( k , filtered )
4753 }
4854 }
4955
50- private static getCacheKey ( streamName : string , host : string ) {
51- return `${ streamName } @${ host } `
56+ private static getCacheKey ( streamName : string , vhost : string , host : string ) {
57+ return `${ streamName } @${ vhost } @ ${ host } `
5258 }
5359}
0 commit comments