Skip to content

Commit d36f9ed

Browse files
Apply adapter design pattern (#10)
* Refactor event client to remove adapter abstraction Removed the adapter abstraction and related files for event handling. The event client now directly manages in-memory (socket.io) and Kafka backends, simplifying initialization, publishing, and subscription logic. Updated type definitions and streamlined the API. Also improved metrics tracking in the server event implementation. Updated package.json to reflect new entry points and removed obsolete scripts. * Add Prometheus metrics to event system Introduced various Prometheus metrics using prom-client to track event publishing, subscriptions, payload sizes, errors, callback durations, and throughput. Metrics are updated throughout the event publishing and subscription lifecycle to improve observability and monitoring. * Export client from Event.ts Added 'client' to the exports in Event.ts to make it available for import in other modules. * Add disconnect support and improve Kafka handling Introduces an async disconnect() method to the event API for both in-memory and Kafka transports, ensuring proper cleanup of resources. Refactors Kafka consumer logic to use a shared consumer and topic tracking, improving subscription management and resource usage. Updates type definitions and bumps package version to 1.1.8. * Refactor event publish and subscribe logic Improved event publishing by validating event types, tracking metrics, and refactoring Kafka and socket handling. Enhanced subscription management with better metric updates and streamlined callback execution. Cleaned up formatting and removed unnecessary code. * Add Kafka backlog monitoring and metrics Introduces periodic monitoring of Kafka topic backlogs, exposing a Prometheus gauge for the number of unprocessed events per topic. Adds methods to start, stop, and manually check backlog monitoring, and ensures metrics are updated on topic subscription and disconnect. Also refactors some Kafka producer/consumer usage for clarity. * Refactor Kafka consumer management and add metrics Replaces per-topic Kafka consumers with a single shared consumer that dynamically subscribes to topics and restarts as needed. Adds Prometheus metrics for event publishing, subscriptions, callback processing, payload size, error rates, and throughput. Updates API to export Prometheus client and adds restartKafkaConsumer method. Bumps package version to 1.1.11. * Update Event.ts * Fix iteration over subscribedTopics in Kafka metrics Wraps subscribedTopics in Array.from() to ensure proper iteration, likely addressing cases where subscribedTopics is a Set or non-array iterable. * Add Kafka backlog monitoring to event client Introduces functions to monitor Kafka backlog size, including periodic and manual checks, and exposes metrics for events waiting to be processed. Also adjusts consumer concurrency and updates package version. * Refactor event client to modular adapter architecture Replaces monolithic Event implementation with modular EventManager, KafkaAdapter, and SocketAdapter. Event logic and metrics are separated into dedicated files, improving maintainability and extensibility. Updates package.json exports to use new entry points. Removes legacy Event files. * Add event system with Kafka and Socket adapters Introduces a modular event system supporting Kafka and Socket.io adapters, including event publishing, subscription management, metrics collection, and backlog monitoring. Updates build scripts and TypeScript configuration for proper compilation and type declarations. * Enforce object payloads in publish/subscribe methods Updated type signatures for publish and subscribe methods in EventManager and event exports to require payloads to extend object, improving type safety. Also updated package version to 1.1.20. * Refactor event type handling and typing for publish Changed event type handling in publish to merge multiple types into a single string separated by underscores, ensuring consistent event naming. Updated all relevant type signatures to use object instead of any for payloads and callbacks, improving type safety. Also updated the EventAdapter interface and related adapters, and incremented the package version. * Add placeholder test script to package.json Introduced a 'test' script in package.json that outputs a placeholder message. This prepares the project for future test integration. * Add Pushgateway metrics integration Introduces Pushgateway support to EventMetrics, allowing metrics to be periodically pushed to a Prometheus Pushgateway. Adds related methods to EventManager and exposes PushgatewayConfig type in the public API. * Refactor KafkaAdapter to use static topic list KafkaAdapter now receives a static list of topics at construction and no longer manages dynamic topic subscriptions. EventManager provides the topic list and handles callback registration/removal in memory. This simplifies consumer management and improves separation of concerns. * Refactor KafkaAdapter and improve eventManager topic handling Simplifies KafkaAdapter by removing per-topic subscription logic and managing a single consumer for all topics except internal ones. Updates eventManager to use a static list of Kafka topics for backlog monitoring and adapts to the new KafkaAdapter API. This improves efficiency and maintainability by centralizing topic management and reducing redundant consumer restarts. * Add Pushgateway metrics support and refactor KafkaAdapter Introduces Pushgateway integration for metrics reporting, including methods to start, stop, and push metrics to a Prometheus Pushgateway. Refactors KafkaAdapter to remove internal topic tracking, use regex for topic subscription, and improve backlog calculation. Updates type definitions and public API to expose Pushgateway configuration and control methods. * Add Oracle TxEventQ adapter and integration Introduces TxEventQAdapter for Oracle Advanced Queuing event transport, updates EventManager and types to support 'txeventq', and exposes the adapter in the public API. Adds docker-compose-oracle.yml for local Oracle DB setup and includes 'oracledb' as a dependency. * Update package.json * Refactor TxEventQAdapter to remove EventMessage type Replaces usage of the EventMessage type with a generic payload structure in TxEventQAdapter. Updates queue and message handling logic to use 'topic' instead of 'eventType', simplifying type usage and removing dependency on EventMessage. * Add TxEventQAdapter for Oracle AQ event queue support Introduces TxEventQAdapter to support Oracle Advanced Queuing (AQ) as an event adapter. Updates EventManager, types, and exports to allow initialization and usage of TxEventQAdapter. Also increases KafkaAdapter's partitionsConsumedConcurrently to 160 and sets a default consumer name for TxEventQAdapter. Updates package version and dependencies. * Refactor TxEventQAdapter to dynamic queue names Removed static queueName from configuration and refactored TxEventQAdapter to use dynamic queue names based on event type for publish/subscribe. Updated related types and EventManager initialization. Added autoCommit option and improved message consumption logic. Also added pub_test.js and test.js for usage examples. * Refactor TxEventQAdapter to always use deqOne Simplified message dequeuing logic in TxEventQAdapter by removing batch processing and always using deqOne with a fixed wait time of 5000ms. Improved error handling and message processing, and updated package version to 1.1.38. * Remove debug log from TxEventQAdapter Eliminated a console.log statement used for debugging payloads in the message handler. This cleans up console output during normal operation. * Refactor metrics to use dedicated registry Introduces a dedicated client.Registry for EventMetrics and registers all metrics to it. This improves encapsulation and avoids polluting the global registry, ensuring metrics are scoped to the EventMetrics instance. * Refactor EventMetrics to use dedicated registry EventMetrics now uses its own prom-client Registry for metric registration and export, improving isolation and compatibility with multiple metric sources. Also removed a debug log from TxEventQAdapter and bumped package version to 1.1.39. * Add new structure * Add event history tracking and unify backlog metrics Introduces getHistory to TxEventQAdapter for retrieving recent event history per topic. EventManager now supports backlog/history monitoring for both Kafka and TxEventQ adapters, updating a unified backlog metric. Metrics are refactored to use a generic eventBacklog gauge instead of Kafka-specific naming, and Pushgateway integration is improved for periodic metric pushes. * Use then instead of await function * Revert metrics changes * remove await from kafka * Add backlog monitoring for TxEventQ and generalize metrics Implemented backlog calculation for TxEventQAdapter and integrated it into EventManager's backlog monitoring. Refactored metrics to generalize backlog tracking (renamed kafkaBacklog to eventBacklog) and updated related methods to support multiple adapters. Backlog monitoring now supports both Kafka and TxEventQ adapters. * Add backlogs --------- Co-authored-by: Ebubekir Yılmaz <ebu1205ed@gmail.com>
1 parent 5f26aa1 commit d36f9ed

40 files changed

Lines changed: 2054 additions & 886 deletions

client/Event.d.ts

Lines changed: 0 additions & 8 deletions
This file was deleted.

client/Event.js

Lines changed: 0 additions & 135 deletions
This file was deleted.

client/Event.ts

Lines changed: 0 additions & 49 deletions
This file was deleted.

client/adapters/Adapter.d.ts

Lines changed: 0 additions & 7 deletions
This file was deleted.

client/adapters/Adapter.js

Lines changed: 0 additions & 2 deletions
This file was deleted.

client/adapters/Adapter.ts

Lines changed: 0 additions & 10 deletions
This file was deleted.

client/adapters/InMemoryAdapter.d.ts

Lines changed: 0 additions & 9 deletions
This file was deleted.

client/adapters/InMemoryAdapter.js

Lines changed: 0 additions & 128 deletions
This file was deleted.

0 commit comments

Comments
 (0)