Skip to content

Commit fe1df1e

Browse files
committed
Address feedback
1 parent 38ec400 commit fe1df1e

File tree

2 files changed

+9
-10
lines changed

2 files changed

+9
-10
lines changed

src/kafkaProducerManager.js

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ export class KafkaProducerManager {
1010
timeout
1111
)
1212
if (!kafkaInstance.isConnected) await kafkaInstance.connect()
13-
if (!kafkaInstance.isConnected)
14-
throw new Error('Kafka Producer failed to connect.')
1513

1614
return kafkaInstance.producer
1715
}
@@ -20,7 +18,7 @@ export class KafkaProducerManager {
2018
let kafkaInstance = this.getKafkaInstance(channelName, clientId, timeout)
2119
if (!kafkaInstance) {
2220
kafkaInstance = new KafkaProducer(clientId, timeout)
23-
this.kafkaSet[`${channelName}${clientId}${timeout}`] = kafkaInstance
21+
this.kafkaSet[`urn:${channelName}:${clientId}:${timeout}`] = kafkaInstance
2422
}
2523

2624
return kafkaInstance
@@ -31,11 +29,11 @@ export class KafkaProducerManager {
3129

3230
if (kafkaInstance) {
3331
if (kafkaInstance.isConnected) await kafkaInstance.disconnect()
34-
delete this.kafkaSet[`${channelName}${clientId}${timeout}`]
32+
delete this.kafkaSet[`urn:${channelName}:${clientId}:${timeout}`]
3533
}
3634
}
3735

3836
static getKafkaInstance(channelName, clientId, timeout) {
39-
return this.kafkaSet[`${channelName}${clientId}${timeout}`]
37+
return this.kafkaSet[`urn:${channelName}:${clientId}:${timeout}`]
4038
}
4139
}

src/model/channels.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -244,13 +244,14 @@ ChannelSchema.pre('save', async function (next) {
244244
}
245245
])
246246

247+
let originalKafkaItem
247248
// We need to cross reference the original, not-yet modified, routes
248249
// against the incoming dirty routes to see if any were removed and if so remove them from the manager
249250
if (Array.isArray(originalKafkaDetails))
250-
originalKafkaDetails = originalKafkaDetails[0]
251-
if (originalKafkaDetails && originalKafkaDetails.routes.length > 0) {
252-
for (let route of originalKafkaDetails.routes) {
253-
const isTimeoutUpdated = originalKafkaDetails.timeout !== this.timeout
251+
originalKafkaItem = originalKafkaDetails[0]
252+
if (originalKafkaItem && originalKafkaItem.routes.length > 0) {
253+
for (let route of originalKafkaItem.routes) {
254+
const isTimeoutUpdated = originalKafkaItem.timeout !== this.timeout
254255
const matchingRoute = kafkaRoutes.find(
255256
e => e.kafkaClientId === route.kafkaClientId && e.name === route.name
256257
)
@@ -263,7 +264,7 @@ ChannelSchema.pre('save', async function (next) {
263264
// if timeout is null on the original document, it was set to the default
264265
// so pull that out from the config before trying to remove connections
265266
const originalTimeout =
266-
originalKafkaDetails.timeout ?? +config.router.timeout
267+
originalKafkaItem.timeout ?? +config.router.timeout
267268
await KafkaProducerManager.removeConnection(
268269
this.name,
269270
route.kafkaClientId,

0 commit comments

Comments
 (0)