Skip to content

Refactor kafka integration samples - #133

Open
PasinduGunarathne wants to merge 4 commits into
wso2:mainfrom
PasinduGunarathne:pasindug-patch-1
Open

Refactor kafka integration samples#133
PasinduGunarathne wants to merge 4 commits into
wso2:mainfrom
PasinduGunarathne:pasindug-patch-1

Conversation

@PasinduGunarathne

@PasinduGunarathne PasinduGunarathne commented May 8, 2026

Copy link
Copy Markdown

Purpose

This PR refactors the publisher and consumer flows of the Kafka Connector to improve maintainability and error tracking.

  • The integration sample now utilizes an OrderEvent record type for end-to-end testing.
  • Integrated best practices for message tracking.
  • Users can now easily identify specific messages by inspecting Offset and Partition IDs during failures.

Goals

Describe the solutions that this feature/fix will introduce to resolve the problems described above

Approach

Describe how you are implementing the solutions. Include an animated GIF or screenshot if the change affects the UI (email documentation@wso2.com to review all UI text). Include a link to a Markdown file or Google doc if the feature write-up is too long to paste here.

User stories

Summary of user stories addressed by this change>

Release note

Brief description of the new feature or bug fix as it will appear in the release notes

Documentation

Link(s) to product documentation that addresses the changes of this PR. If no doc impact, enter “N/A” plus brief explanation of why there’s no doc impact

Training

Link to the PR for changes to the training content in https://github.com/wso2/WSO2-Training, if applicable

Certification

Type “Sent” when you have provided new/updated certification questions, plus four answers for each question (correct answer highlighted in bold), based on this change. Certification questions/answers should be sent to certification@wso2.com and NOT pasted in this PR. If there is no impact on certification exams, type “N/A” and explain why.

Marketing

Link to drafts of marketing content that will describe and promote this feature, including product page changes, technical articles, blog posts, videos, etc., if applicable

Automation tests

  • Unit tests

    Code coverage information

  • Integration tests

    Details about the test cases and coverage

Security checks

Samples

Provide high-level details about the samples related to this feature

Related PRs

List any other related PRs

Migrations (if applicable)

Describe migration steps and platforms on which migration has been tested

Test environment

List all JDK versions, operating systems, databases, and browser/versions on which this feature/fix was tested

Learning

Describe the research phase and any blog posts, patterns, libraries, or add-ons you used to solve the problem.

@coderabbitai

coderabbitai Bot commented May 8, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Rate limit exceeded

@PasinduGunarathne has exceeded the limit for the number of commits that can be reviewed per hour. Please wait 22 minutes and 38 seconds before requesting another review.

You’ve run out of usage credits. Purchase more in the billing tab.

⌛ How to resolve this issue?

After the wait time has elapsed, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

We recommend that you space out your commits to avoid hitting the rate limit.

🚦 How do rate limits work?

CodeRabbit enforces hourly rate limits for each developer per organization.

Our paid plans have higher rate limits than the trial, open-source and free plans. In all cases, we re-allow further reviews after a brief timeout.

Please see our FAQ for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: b1a8eff6-24e9-4432-9ccd-ef5e6e5e8899

📥 Commits

Reviewing files that changed from the base of the PR and between 64290be and 45b9b55.

📒 Files selected for processing (1)
  • integrator-default-profile/connectors/kafka_consumer_connector_sample/main.bal
📝 Walkthrough

Walkthrough

This pull request adds Kafka producer and consumer connector samples for the integration platform. The changes introduce a shared OrderEvent record type with order identification, customer information, amount, and timestamp fields. The producer sample sends constructed OrderEvent records to a configurable Kafka topic as JSON bytes, while the consumer sample implements a listener that receives batches of records, deserializes them into OrderEvent objects, processes each one via a dedicated function, handles per-message errors, and manages offsets explicitly after batch completion.

🚥 Pre-merge checks | ✅ 4 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Description check ⚠️ Warning The description provides the Purpose section with clear context, but most other required sections (Goals, Approach, User stories, Release note, Documentation, Training, Certification, Marketing, Automation tests, Security checks, Samples, Related PRs, Migrations, Test environment, Learning) remain as unfilled template placeholders. Complete the remaining template sections with specific details about implementation approach, test coverage, documentation impact, security verification, and test environments used.
✅ Passed checks (4 passed)
Check name Status Explanation
Title check ✅ Passed The title 'Refactor kafka integration samples' directly relates to the main change: refactoring Kafka connector samples (producer and consumer) with improved structure and error tracking.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🧹 Nitpick comments (1)
integrator-default-profile/connectors/kafka_consumer_connector_sample/functions.bal (1)

3-6: ⚡ Quick win

Make processOrder return error? to preserve explicit failure propagation.

At Line 3, returning error? will let the caller use check and keep processing/commit behavior aligned with actual per-message outcome once TODO logic is added.

Proposed change
-public isolated function processOrder(OrderEvent orderEvent) {
+public isolated function processOrder(OrderEvent orderEvent) returns error? {
     // TODO: Implement the logic to process the order
     log:printInfo("Processing order..", orderId = orderEvent.orderId);
 }

And update the call site in integrator-default-profile/connectors/kafka_consumer_connector_sample/main.bal:

-                processOrder(orderEvent); // Implement a processing logic under processOrder() method in functions.bal file
+                check processOrder(orderEvent); // Implement processing logic in functions.bal
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@integrator-default-profile/connectors/kafka_consumer_connector_sample/functions.bal`
around lines 3 - 6, Change the processOrder function signature to return error?
(public isolated function processOrder(OrderEvent orderEvent) returns error?) so
failures can be propagated instead of swallowed; inside processOrder return any
errors from the TODO logic (or nil on success). Then update the caller in
main.bal that invokes processOrder to use check (or otherwise handle the
returned error) so per-message processing/commit semantics reflect actual
success/failure.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In
`@integrator-default-profile/connectors/kafka_consumer_connector_sample/main.bal`:
- Around line 25-30: The code unconditionally calls caller->commit() after
iterating records, which will commit offsets for failed messages caught in the
"on fail error e" block and prevent redelivery; modify the logic so you only
commit offsets for successfully processed records (e.g., track the highest
successfully processed msg.offset.offset per partition during the loop and call
a targeted commit for those offsets or skip commit entirely if any record
failed), updating the commit call that currently uses caller->commit() to use
per-partition/per-offset commits or conditional commit based on the tracked
lastSuccessfulOffset; ensure references in the "on fail error e" handler
(msg.offset.offset and msg.offset.partition.partition) are used to update
failure state so you can avoid committing failed messages.

---

Nitpick comments:
In
`@integrator-default-profile/connectors/kafka_consumer_connector_sample/functions.bal`:
- Around line 3-6: Change the processOrder function signature to return error?
(public isolated function processOrder(OrderEvent orderEvent) returns error?) so
failures can be propagated instead of swallowed; inside processOrder return any
errors from the TODO logic (or nil on success). Then update the caller in
main.bal that invokes processOrder to use check (or otherwise handle the
returned error) so per-message processing/commit semantics reflect actual
success/failure.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: bf819f8e-a1c7-48ff-ba4a-84eaa22e6009

📥 Commits

Reviewing files that changed from the base of the PR and between 3fb3d75 and e862492.

📒 Files selected for processing (6)
  • integrator-default-profile/connectors/kafka_consumer_connector_sample/functions.bal
  • integrator-default-profile/connectors/kafka_consumer_connector_sample/main.bal
  • integrator-default-profile/connectors/kafka_consumer_connector_sample/types.bal
  • integrator-default-profile/connectors/kafka_producer_connector_sample/automation.bal
  • integrator-default-profile/connectors/kafka_producer_connector_sample/config.bal
  • integrator-default-profile/connectors/kafka_producer_connector_sample/types.bal

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR refactors the Kafka producer/consumer connector samples to send and consume a structured OrderEvent payload (JSON), adds configurable topic support on the producer side, and improves message observability by logging message identifiers (orderId) and (on failures) Kafka offset/partition metadata.

Changes:

  • Introduces an OrderEvent record type and uses it for producer serialization and consumer deserialization.
  • Makes the producer topic configurable and updates the producer automation flow to publish OrderEvent JSON.
  • Updates the consumer flow to parse OrderEvent, invoke a processOrder() hook, and log failure context (offset/partition).

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
integrator-default-profile/connectors/kafka_producer_connector_sample/types.bal Adds OrderEvent record type for producer sample payloads.
integrator-default-profile/connectors/kafka_producer_connector_sample/config.bal Adds configurable kafkaTopic for producer sample.
integrator-default-profile/connectors/kafka_producer_connector_sample/automation.bal Publishes OrderEvent JSON to Kafka and logs the sent orderId.
integrator-default-profile/connectors/kafka_consumer_connector_sample/types.bal Adds public OrderEvent record type for consumer deserialization.
integrator-default-profile/connectors/kafka_consumer_connector_sample/main.bal Implements listener-based consumption, parses OrderEvent, logs offsets/partitions on failure, and commits manually.
integrator-default-profile/connectors/kafka_consumer_connector_sample/functions.bal Adds processOrder() hook used by the consumer service.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread integrator-default-profile/connectors/kafka_consumer_connector_sample/main.bal Outdated
Comment thread integrator-default-profile/connectors/kafka_consumer_connector_sample/main.bal Outdated
Comment thread integrator-default-profile/connectors/kafka_producer_connector_sample/config.bal Outdated
PasinduGunarathne and others added 2 commits May 8, 2026 17:52
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants