Skip to content
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

feature: Pass message subject as header #102

Conversation

KernelMrex
Copy link
Contributor

@KernelMrex KernelMrex commented Dec 1, 2023

Reason for This PR

Sometimes consumer needs to know from which subject message is consumed.

For example: pipeline subscribed on nats-message-subject-as-header.*, but we have to route message deserialization by subject nats-message-subject-as-header.current-subject

Description of Changes

Added x-nats-subject pass as header to the job through task.

License Acceptance

By submitting this pull request, I confirm that my contribution is made under
the terms of the MIT license.

PR Checklist

[Author TODO: Meet these criteria.]
[Reviewer TODO: Verify that these criteria are met. Request changes if not]

  • All commits in this PR are signed (git commit -s).
  • The reason for this PR is clearly provided (issue no. or explanation).
  • The description of changes is clear and encompassing.
  • Any required documentation changes (code and docs) are included in this PR.
  • Any user-facing changes are mentioned in CHANGELOG.md.
  • All added/changed functionality is tested.

Summary by CodeRabbit

  • New Features

    • Implemented a new CI/CD pipeline trigger for specific branch operations.
    • Introduced message subject headers in NATS job options for enhanced message tracking.
    • Added server and NATS configurations for improved development and testing environments.
    • Created a new test function to validate NATS message subject header functionality.
  • Bug Fixes

    • Ensured proper task completion handling in PHP test files with subject header checks.
  • Documentation

    • Updated test configurations to reflect new NATS message subject header usage.
  • Refactor

    • Standardized the use of a constant header key across the application for consistent NATS message handling.

Copy link

coderabbitai bot commented Dec 1, 2023

Walkthrough

A new feature has been integrated into a CI/CD pipeline and a NATS-based job system, allowing the passage of message subjects as headers. This includes a new trigger for the CI/CD pipeline, updates to the Options struct and message handling in the job system, and additional test configurations and cases to ensure functionality. The changes are aimed at enhancing message processing capabilities and improving the integration with NATS messaging.

Changes

File Path Change Summary
.github/workflows/.../linux.yml Added new CI/CD trigger for "feature/pass-message-subject-as-header" branch.
natsjobs/item.go Added subject field to Options struct.
natsjobs/listener.go Added NatsSubjectHeaderKey constant and logic to pass subject as a header.
tests/configs/.../.rr-nats-message-subject-as-header.yaml Added YAML configuration for server and NATS with debug logging and job settings.
tests/jobs_nats_test.go Added TestNATSMessageSubjectAsHeader function for NATS test environment setup.
tests/php_test_files/jobs/... Updated PHP test files to handle 'x-nats-subject' header.

🐇✨
In the burrows of the code, a feature new,
Through pipelines and tests, it flew.
"x-nats-subject" in headers we weave,
A rabbit's touch, in tech we believe. 🌟🚀
🐇✨


Tips

Chat with CodeRabbit Bot (@coderabbitai)

  • If you reply to a review comment from CodeRabbit, the bot will automatically respond.
  • To engage with CodeRabbit bot directly around the specific lines of code in the PR, mention @coderabbitai in your review comment
  • Note: Review comments are made on code diffs or files, not on the PR overview.
  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.

CodeRabbit Commands (invoked as PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger a review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai help to get help.

Note: For conversation with the bot, please use the review comments on code diffs or files.

CodeRabbit Configration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • The JSON schema for the configuration file is available here.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/coderabbit-overrides.v2.json

@KernelMrex KernelMrex changed the title Feature/pass message subject as header Pass message subject as header Dec 1, 2023
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 6

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 48cd6e9 and 6afc4a5.
Files ignored due to filter (1)
  • go.work.sum
Files selected for processing (6)
  • .github/workflows/linux.yml (1 hunks)
  • natsjobs/item.go (1 hunks)
  • natsjobs/listener.go (2 hunks)
  • tests/configs/.rr-nats-message-subject-as-header.yaml (1 hunks)
  • tests/jobs_nats_test.go (1 hunks)
  • tests/php_test_files/jobs/jobs_ok_with_subject_header.php (1 hunks)
Additional comments: 3
.github/workflows/linux.yml (1)
  • 5-11: The addition of the "feature/pass-message-subject-as-header" branch to the CI/CD pipeline triggers is correctly implemented.
natsjobs/item.go (1)
  • 49-49: Verify that the subject field is being used appropriately in natsjobs/listener.go as mentioned in the pull request summary, and ensure that any new code handling this field is thread-safe if accessed concurrently.
tests/configs/.rr-nats-message-subject-as-header.yaml (1)
  • 1-34: The configuration file appears to be correctly set up to support the new feature of passing the NATS message subject as a header. It specifies the server command, NATS address, logging settings, job settings, and the NATS pipeline configuration, including the subject pattern to subscribe to and the stream name.

tests/jobs_nats_test.go Outdated Show resolved Hide resolved
natsjobs/listener.go Outdated Show resolved Hide resolved
natsjobs/listener.go Outdated Show resolved Hide resolved
tests/php_test_files/jobs/jobs_ok_with_subject_header.php Outdated Show resolved Hide resolved
natsjobs/item.go Outdated Show resolved Hide resolved
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Review Status

Actionable comments generated: 0

Configuration used: CodeRabbit UI

Commits Files that changed from the base of the PR and between 6afc4a5 and fdc8109.
Files selected for processing (1)
  • tests/php_test_files/jobs/jobs_ok_with_subject_header.php (1 hunks)
Additional comments: 2
tests/php_test_files/jobs/jobs_ok_with_subject_header.php (2)
  • 18-18: Verify that the value of EXPECTED_SUBJECT matches the intended subject used in the NATS configuration for this test to ensure the test is valid.

  • 22-27: The code correctly checks for the presence of the x-nats-subject header and throws a RuntimeException if it does not match the expected subject. This is a good practice for ensuring the feature works as intended.

@KernelMrex KernelMrex changed the title Pass message subject as header feature: Pass message subject as header Dec 1, 2023
@rustatian rustatian self-requested a review December 1, 2023 21:44
@rustatian rustatian added the enhancement New feature or request label Dec 1, 2023
Copy link
Member

@rustatian rustatian left a comment

Choose a reason for hiding this comment

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

LGTM, just a minor changes required.

natsjobs/listener.go Outdated Show resolved Hide resolved
natsjobs/config.go Outdated Show resolved Hide resolved
@KernelMrex KernelMrex requested a review from rustatian December 4, 2023 08:11
Copy link
Member

@rustatian rustatian left a comment

Choose a reason for hiding this comment

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

LGTM, thanks @KernelMrex 👍

@rustatian rustatian merged commit d339b39 into roadrunner-server:master Dec 4, 2023
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants