-
Notifications
You must be signed in to change notification settings - Fork 18
List offsets api implemented #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
04a2321
describeTopics api implemented
PratRanj07 872fed0
List offsets api implemented
PratRanj07 2c218e4
reverting some indentation changes
PratRanj07 24aec93
Merge master
PratRanj07 f1b405f
comment
PratRanj07 1cf7b42
relative changes
PratRanj07 51707f3
reverting
PratRanj07 e2c51ad
Merge master
PratRanj07 47af3a2
requested changes
PratRanj07 2977d15
Merge master
PratRanj07 aaaf45d
requested changes
PratRanj07 1b2c054
Merge master
PratRanj07 a2ba6dd
Change log changes
PratRanj07 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,77 @@ | ||
const { Kafka, IsolationLevel } = require('@confluentinc/kafka-javascript').KafkaJS; | ||
const { parseArgs } = require('node:util'); | ||
|
||
async function fetchOffsets() { | ||
// Parse command-line arguments | ||
const args = parseArgs({ | ||
allowPositionals: true, | ||
options: { | ||
'bootstrap-servers': { | ||
type: 'string', | ||
short: 'b', | ||
default: 'localhost:9092', | ||
}, | ||
'timeout': { | ||
type: 'string', | ||
short: 't', | ||
default: '5000', | ||
}, | ||
'isolation-level': { | ||
type: 'string', | ||
short: 'i', | ||
default: '0', // Default to '0' for read_uncommitted | ||
}, | ||
}, | ||
}); | ||
|
||
const { | ||
'bootstrap-servers': bootstrapServers, | ||
timeout, | ||
'isolation-level': isolationLevel, | ||
} = args.values; | ||
|
||
const [topic] = args.positionals; | ||
|
||
if (!topic) { | ||
console.error('Topic name is required'); | ||
process.exit(1); | ||
} | ||
|
||
// Determine the isolation level | ||
let isolationLevelValue; | ||
if (isolationLevel === '0') { | ||
isolationLevelValue = IsolationLevel.READ_UNCOMMITTED; | ||
} else if (isolationLevel === '1') { | ||
isolationLevelValue = IsolationLevel.READ_COMMITTED; | ||
} else { | ||
console.error('Invalid isolation level. Use 0 for READ_UNCOMMITTED or 1 for READ_COMMITTED.'); | ||
process.exit(1); | ||
} | ||
|
||
const kafka = new Kafka({ | ||
kafkaJS: { | ||
brokers: [bootstrapServers], | ||
}, | ||
}); | ||
|
||
const admin = kafka.admin(); | ||
await admin.connect(); | ||
|
||
try { | ||
// Fetch offsets for the specified topic | ||
const offsets = await admin.fetchTopicOffsets( | ||
topic, | ||
{ | ||
isolationLevel: isolationLevelValue, // Use determined isolation level | ||
timeout: Number(timeout), // Convert timeout to a number | ||
}); | ||
|
||
console.log(`Offsets for topic "${topic}":`, JSON.stringify(offsets, null, 2)); | ||
} catch (err) { | ||
console.error('Error fetching topic offsets:', err); | ||
} finally { | ||
await admin.disconnect(); | ||
} | ||
} | ||
|
||
fetchOffsets(); |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.