Skip to content

Implement Annotation-driven Event Observer Framework for Reactive Network Monitoring #81

@Twiineenock

Description

@Twiineenock

Problem

Building reactive applications on the Hiero network currently requires developers to implement significant boilerplate code. When a developer needs to monitor an account for transactions or a topic for messages, they are forced to manually handle polling, state tracking, and error recovery.

This friction prevents developers from easily fulfilling common enterprise requirements such as:

  • Treasury Monitoring: "As a treasury manager, I want to be notified instantly when my account receives funds so I can trigger automated internal accounting."
  • HCS Coordination: "As a DeFi developer, I want to monitor HCS messages for real-time coordination signals without writing custom polling loops."
  • ERP Integration: "As an enterprise integrator, I want to react to successful settlements on the network to update our external ERP system in real-time."

I'm always frustrated when I have to rewrite this "plumbing" code for every new project. The current SDK provides great low-level primitives, but it lacks a high-level, declarative way to "just listen" to network events.

Solution

I propose adding a high-level Event Observer Framework that abstracts away the polling and state management logic, enabling a "plug-and-play" experience for the user stories mentioned above.

Key components of the solution:

  • AbstractPollingObserver: A core background engine in hiero-enterprise-base that handles interval-based polling against the Mirror Node REST API.
  • Deduplication Logic: Built-in tracking of consensus_timestamp to ensure events are delivered exactly once and in chronological order.
  • Declarative Annotations: Introduction of @HieroTransactionListener and @HieroTopicListener to allow developers to subscribe to events by simply annotating a method.
  • Spring Integration: A HieroListenerProcessor that automatically discovers annotated beans and manages the observer lifecycles.
  • Repository Enhancements: Added timestamp-based filtering to TransactionRepository and TopicRepository to support efficient delta-polling.

Example Usage:

@HieroTransactionListener(account = "0.0.1234", interval = 5000)
public void onTreasuryUpdate(TransactionInfo tx) {
    log.info("Treasury received funds. Transaction ID: {}", tx.transactionId());
}
\```


### Alternatives

1.  **Raw gRPC Streaming**: While the SDK supports `TopicMessageQuery` via gRPC, it can be fragile for long-running observers in enterprise environments due to connection resets and the need for complex retry logic. The REST-based polling approach is often more stable for "always-on" background monitoring.
2.  **Manual Polling**: Developers can continue to write their own `Scheduled` tasks, but this leads to inconsistent implementations and high maintenance overhead across different teams.
3.  **Reactive Streams (Project Reactor)**: We considered a full `Flux/Mono` implementation, but decided that a simple annotation-driven model provides a much lower barrier to entry for the majority of enterprise developers while still being compatible with reactive stacks.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions