-
-
Notifications
You must be signed in to change notification settings - Fork 526
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #221 from tulios/220-handle-unsubscribed-assignments
Handle receiving assignments for unsubscribed topics
- Loading branch information
Showing
7 changed files
with
107 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
src/consumer/__tests__/assignmentForUnsubscribedTopic.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const createConsumer = require('../index') | ||
|
||
const { | ||
secureRandom, | ||
createCluster, | ||
createTopic, | ||
newLogger, | ||
waitForConsumerToJoinGroup, | ||
} = require('testHelpers') | ||
|
||
describe('Consumer', () => { | ||
let topicNames, groupId, consumer1, consumer2 | ||
|
||
beforeEach(async () => { | ||
topicNames = [`test-topic-${secureRandom()}`, `test-topic-${secureRandom()}`] | ||
groupId = `consumer-group-id-${secureRandom()}` | ||
|
||
await Promise.all(topicNames.map(topicName => createTopic({ topic: topicName }))) | ||
|
||
consumer1 = createConsumer({ | ||
cluster: createCluster({ metadataMaxAge: 50 }), | ||
groupId, | ||
heartbeatInterval: 100, | ||
maxWaitTimeInMs: 100, | ||
logger: newLogger(), | ||
}) | ||
}) | ||
|
||
afterEach(async () => { | ||
consumer1 && (await consumer1.disconnect()) | ||
consumer2 && (await consumer2.disconnect()) | ||
}) | ||
|
||
it('handles receiving assignments for unsubscribed topics', async () => { | ||
await consumer1.connect() | ||
await Promise.all( | ||
topicNames.map(topicName => consumer1.subscribe({ topic: topicName, fromBeginning: true })) | ||
) | ||
|
||
consumer1.run({ eachMessage: () => {} }) | ||
await waitForConsumerToJoinGroup(consumer1) | ||
|
||
// Second consumer re-uses group id but only subscribes to one of the topics | ||
consumer2 = createConsumer({ | ||
cluster: createCluster({ metadataMaxAge: 50 }), | ||
groupId, | ||
heartbeatInterval: 100, | ||
maxWaitTimeInMs: 100, | ||
logger: newLogger(), | ||
}) | ||
await consumer2.subscribe({ topic: topicNames[0], fromBeginning: true }) | ||
|
||
consumer2.run({ eachMessage: () => {} }) | ||
await waitForConsumerToJoinGroup(consumer2) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters