Publish project.created NATS event on project creation#190
Merged
jeroenrinzema merged 6 commits intomainfrom Mar 6, 2026
Merged
Publish project.created NATS event on project creation#190jeroenrinzema merged 6 commits intomainfrom
jeroenrinzema merged 6 commits intomainfrom
Conversation
- Add EventProjectCreated constant and ProjectEvent schema - Add ProjectEventsProcess subject function - Add StreamProjects and ConsumerProjectEventsProcess constants - Bootstrap project events stream and consumer - Add pubsub.Publisher to ProjectsController - Publish project.created event in CreateProject handler - Add test for NATS event publication on project creation Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
The project is already committed to the database when the NATS event is published, so a publish failure should not fail the HTTP response. Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
Copilot
AI
changed the title
[WIP] Check NATS event publication on new project creation
Publish project.created NATS event on project creation
Mar 6, 2026
jeroenrinzema
requested changes
Mar 6, 2026
The publish now happens inside the transaction scope. If it fails, the handler returns an error and the deferred tx.Rollback() cleans up. Added TestCreateProjectRollbackOnPublishFailure to verify this behavior. Co-authored-by: jeroenrinzema <3440116+jeroenrinzema@users.noreply.github.com>
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
No NATS event was published when a project was created, preventing async processes from reacting to project creation.
Changes
internal/pubsub/schemas/events.go): AddedEventProjectCreatedconstant,ProjectEventstruct, andProjectEventsProcess(organizationID)subject functioninternal/pubsub/consumer/bootstrap.go,consumer.go): Addedprojectsstream andprojects-events-processconsumerinternal/http/controllers/v1/management/projects.go): Addedpubsub.PublishertoProjectsController; publishesproject.createdbeforetx.Commit(). If the publish fails, the request fails and the transaction is rolled back, ensuring consistency between NATS and the database.TestCreateProjectPublishesNATSEventusing a recording publisher to verify event subject, name, and payload. AddedTestCreateProjectRollbackOnPublishFailureto verify that a publish failure rolls back the transaction and returns an error.Event payload
Published to subject
projects.events.<organization_id>:{ "id": "<project_id>", "name": "project.created", "organization_id": "<org_id>", "data": { "name": "My Project", "timezone": "America/New_York", "locale": "en-US" } }Original prompt
💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.