Skip to content

Human refactor 2#31

Merged
p14n merged 17 commits intomainfrom
human-refactor-2
Mar 24, 2025
Merged

Human refactor 2#31
p14n merged 17 commits intomainfrom
human-refactor-2

Conversation

@p14n
Copy link
Copy Markdown
Owner

@p14n p14n commented Mar 15, 2025

Also closes #32

@sourcery-ai
Copy link
Copy Markdown
Contributor

sourcery-ai bot commented Mar 15, 2025

Reviewer's Guide by Sourcery

This pull request introduces several enhancements and refactorings to the post-event system. It introduces generics to DefaultMessageBroker and PersistentBroker to support different input and output message types. It refactors the Publisher class to be a utility class with static methods. It updates LocalConsumer to implement AutoCloseable and use generics. It adds a method to create a connection pool from PostEventConfig. It also introduces new classes such as EventMessageBroker, TransactionalBroker, and TransactionalEvent to support transactional message processing. Finally, it adds example classes to demonstrate the usage of the new features.

No diagrams generated as the changes look simple and do not need a visual representation.

File-Level Changes

Change Details Files
Introduce generics to DefaultMessageBroker to support different input and output message types, and implement AutoCloseable.
  • Add generics InT and OutT to DefaultMessageBroker.
  • Implement AutoCloseable interface.
  • Add canProcess method to determine if a message can be processed.
  • Add convert method to convert the input message to the output message type.
  • Update publish method to use the converted message.
  • Update subscribe and unsubscribe methods to use the output message type.
  • Update onError method in close to use the output message type.
src/main/java/com/p14n/postevent/broker/DefaultMessageBroker.java
Update PersistentBroker to use generics and implement AutoCloseable.
  • Add generic type OutT to PersistentBroker.
  • Implement AutoCloseable interface.
  • Update constructor to accept a MessageBroker with the new generic type.
  • Update subscribe and unsubscribe methods to use the new generic type.
  • Implement the convert method.
src/main/java/com/p14n/postevent/catchup/PersistentBroker.java
Refactor Publisher class to be a utility class with static methods.
  • Make the publish method static.
  • Add a private constructor to prevent instantiation.
  • Add a publish method that takes a DataSource as an argument.
src/main/java/com/p14n/postevent/Publisher.java
src/test/java/com/p14n/postevent/PublisherTest.java
Update LocalConsumer to implement AutoCloseable and use generics.
  • Implement AutoCloseable interface.
  • Add generic type OutT to LocalConsumer.
  • Update constructor to accept a MessageBroker with the new generic type.
  • Initialize DatabaseSetup with PostEventConfig.
  • Call db.setupAll in the start method.
  • Implement the close method to stop the Debezium server.
src/main/java/com/p14n/postevent/LocalConsumer.java
Add method to create a connection pool from PostEventConfig.
  • Add createPool method to create a HikariCP DataSource.
src/main/java/com/p14n/postevent/db/DatabaseSetup.java
Update CatchupServiceTest to use EventMessageBroker.
  • Replace DefaultMessageBroker with EventMessageBroker.
src/test/java/com/p14n/postevent/CatchupServiceTest.java
Add EventMessageBroker class.
  • Create EventMessageBroker class that extends DefaultMessageBroker and sets the generic types to <Event, Event>.
src/main/java/com/p14n/postevent/broker/EventMessageBroker.java
Add TransactionalBroker class.
  • Create TransactionalBroker class that extends DefaultMessageBroker and sets the generic types to <Event, TransactionalEvent>.
  • Override the publish method to process messages in a transaction.
  • Implement the convert method.
src/main/java/com/p14n/postevent/broker/TransactionalBroker.java
Add TransactionalEvent record.
  • Create TransactionalEvent record that contains a Connection and an Event.
src/main/java/com/p14n/postevent/broker/TransactionalEvent.java
Add example classes.
  • Create LocalConsumerExample class to demonstrate the usage of LocalConsumer.
  • Create LocalPersistentConsumerExample class to demonstrate the usage of LocalConsumer with PersistentBroker.
  • Create ExampleUtil class to provide utility methods for the examples.
src/test/java/com/p14n/postevent/example/LocalConsumerExample.java
src/test/java/com/p14n/postevent/example/LocalPersistentConsumerExample.java
src/test/java/com/p14n/postevent/example/ExampleUtil.java

Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!
  • Generate a plan of action for an issue: Comment @sourcery-ai plan on
    an issue to generate a plan of action for it.

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

Copy link
Copy Markdown
Contributor

@sourcery-ai sourcery-ai bot left a comment

Choose a reason for hiding this comment

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

Hey @p14n - I've reviewed your changes and found some issues that need to be addressed.

Blocking issues:

  • Looks like a hardcoded database password. (link)
  • Looks like a hardcoded database username. (link)

Overall Comments:

  • Consider providing a default implementation of the convert method in DefaultMessageBroker to avoid forcing subclasses to implement it when no conversion is needed.
  • It looks like Publisher is a utility class, so it should have a private constructor to prevent instantiation.
Here's what I looked at during the review
  • 🟢 General issues: all looks good
  • 🔴 Security: 2 blocking issues
  • 🟢 Testing: all looks good
  • 🟢 Complexity: all looks good
  • 🟢 Documentation: all looks good

Sourcery is free for open source - if you like our reviews please consider sharing them ✨
Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.

HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(cfg.jdbcUrl());
ds.setUsername(cfg.dbUser());
ds.setPassword(cfg.dbPassword());
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.

🚨 issue (security): Looks like a hardcoded database password.

Please ensure this password is not a production password and is properly secured.

public static DataSource createPool(PostEventConfig cfg){
HikariDataSource ds = new HikariDataSource();
ds.setJdbcUrl(cfg.jdbcUrl());
ds.setUsername(cfg.dbUser());
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.

🚨 issue (security): Looks like a hardcoded database username.

Please ensure this username is not a production username and is properly secured.

@p14n p14n merged commit 5b623e9 into main Mar 24, 2025
1 check passed
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.

Create a reprocessor

1 participant