Skip to content

Conversation

@p14n
Copy link
Owner

@p14n p14n commented Oct 25, 2025

Summary by Sourcery

New Features:

  • Add publish(String, TransactionalEvent) method to handle transactional event persistence and real-time distribution

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Oct 25, 2025

Reviewer's Guide

This PR adds an overloaded publish method to EventBusMessageBroker that handles TransactionalEvent by persisting it via the existing Publisher API, then broadcasting it over the EventBus with structured debug and error logging.

Sequence diagram for transactional event publishing in EventBusMessageBroker

sequenceDiagram
    participant EventBusMessageBroker
    participant Publisher
    participant EventBus
    participant Logger
    EventBusMessageBroker->>Logger: log("Publishing event to topic {} with id {}")
    EventBusMessageBroker->>Publisher: publish(event.event(), event.connection(), topic)
    EventBusMessageBroker->>EventBus: publish("events." + topic, event)
    EventBusMessageBroker->>Logger: log("Successfully published event to topic {} with id {}")
    alt Exception occurs
        EventBusMessageBroker->>Logger: log("Failed to publish event to topic {} with id {}", error)
    end
Loading

Class diagram for updated EventBusMessageBroker with TransactionalEvent publishing

classDiagram
    class EventBusMessageBroker {
        +publish(String topic, Event event)
        +publish(String topic, TransactionalEvent event)
    }
    class TransactionalEvent {
        +id()
        +event()
        +connection()
    }
    class Publisher {
        +publish(Event event, Connection connection, String topic)
    }
    EventBusMessageBroker --> TransactionalEvent
    EventBusMessageBroker --> Publisher
Loading

File-Level Changes

Change Details Files
Support transactional event publishing with persistence and real-time distribution
  • Added overloaded publish(String, TransactionalEvent) method
  • Inserted debug logging before and after publishing
  • Used Publisher.publish(...) for database persistence
  • Constructed EventBus address and invoked eventBus.publish(...) for real-time distribution
  • Wrapped operations in try-catch and added error logging on failures
vertx/src/main/java/com/p14n/postevent/vertx/adapter/EventBusMessageBroker.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!

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
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 there - I've reviewed your changes and they look great!

Prompt for AI Agents
Please address the comments from this code review:

## Individual Comments

### Comment 1
<location> `vertx/src/main/java/com/p14n/postevent/vertx/adapter/EventBusMessageBroker.java:173` </location>
<code_context>
+
+            }
+
+            // First, persist to database using existing Publisher
+
+    }
</code_context>

<issue_to_address>
**nitpick:** Comment placement is misleading after the code block.

Move the comment above the Publisher.publish call to better reflect the actual sequence of operations.
</issue_to_address>

### Comment 2
<location> `vertx/src/main/java/com/p14n/postevent/vertx/adapter/EventBusMessageBroker.java:144` </location>
<code_context>
             throw new RuntimeException("Failed to publish event", e);
         }
     }
+    public void publish(String topic, TransactionalEvent event) {
+
+        logger.atDebug()
</code_context>

<issue_to_address>
**issue (complexity):** Consider refactoring the repeated logging and error handling in publish methods into a helper to simplify the code.

Consider extracting the repeated logging + try/catch into a small helper. For example:

```java
@FunctionalInterface
private interface ThrowingRunnable {
  void run() throws Exception;
}

private void doPublish(String topic, String eventId, ThrowingRunnable action) {
  logger.atDebug()
        .addArgument(topic)
        .addArgument(eventId)
        .log("Publishing event to topic {} with id {}");
  try {
    action.run();
    logger.atDebug()
          .addArgument(topic)
          .addArgument(eventId)
          .log("Successfully published event to topic {} with id {}");
  } catch (Exception e) {
    logger.atError()
          .addArgument(topic)
          .addArgument(eventId)
          .setCause(e)
          .log("Failed to publish event to topic {} with id {}");
    throw new RuntimeException("Failed to publish event", e);
  }
}
```

Then your two `publish` overloads become:

```java
public void publish(String topic, Event event) {
  doPublish(topic, event.id(), () -> {
    Publisher.publish(event, topic);
  });
}

public void publish(String topic, TransactionalEvent txEvent) {
  doPublish(topic, txEvent.id(), () -> {
    Publisher.publish(txEvent.event(), txEvent.connection(), topic);
    eventBus.publish("events." + topic, txEvent);
  });
}
```

This removes the duplicated logger invocations, nested try/catch, and the stray comment, while keeping all behavior intact.
</issue_to_address>

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.


}

// First, persist to database using existing Publisher
Copy link
Contributor

Choose a reason for hiding this comment

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

nitpick: Comment placement is misleading after the code block.

Move the comment above the Publisher.publish call to better reflect the actual sequence of operations.

throw new RuntimeException("Failed to publish event", e);
}
}
public void publish(String topic, TransactionalEvent event) {
Copy link
Contributor

Choose a reason for hiding this comment

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

issue (complexity): Consider refactoring the repeated logging and error handling in publish methods into a helper to simplify the code.

Consider extracting the repeated logging + try/catch into a small helper. For example:

@FunctionalInterface
private interface ThrowingRunnable {
  void run() throws Exception;
}

private void doPublish(String topic, String eventId, ThrowingRunnable action) {
  logger.atDebug()
        .addArgument(topic)
        .addArgument(eventId)
        .log("Publishing event to topic {} with id {}");
  try {
    action.run();
    logger.atDebug()
          .addArgument(topic)
          .addArgument(eventId)
          .log("Successfully published event to topic {} with id {}");
  } catch (Exception e) {
    logger.atError()
          .addArgument(topic)
          .addArgument(eventId)
          .setCause(e)
          .log("Failed to publish event to topic {} with id {}");
    throw new RuntimeException("Failed to publish event", e);
  }
}

Then your two publish overloads become:

public void publish(String topic, Event event) {
  doPublish(topic, event.id(), () -> {
    Publisher.publish(event, topic);
  });
}

public void publish(String topic, TransactionalEvent txEvent) {
  doPublish(topic, txEvent.id(), () -> {
    Publisher.publish(txEvent.event(), txEvent.connection(), topic);
    eventBus.publish("events." + topic, txEvent);
  });
}

This removes the duplicated logger invocations, nested try/catch, and the stray comment, while keeping all behavior intact.

@p14n p14n merged commit ddbc9ba into main Oct 25, 2025
2 of 4 checks 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.

2 participants