Overview
TheSubscriberService is responsible for managing subscriber information in OmniView. A subscriber is a unique identifier that represents an Oracle Advanced Queuing (AQ) listener registered to receive tracer events from the OMNI_TRACER_QUEUE.
Key responsibilities:
- Generating unique subscriber identifiers using UUID v4
- Persisting subscriber information to BoltDB
- Registering subscribers with Oracle AQ
- Retrieving existing subscriber configurations
Service Structure
Database repository for Oracle operations, used to register subscribers with Oracle AQ
Configuration repository for BoltDB operations, used to persist subscriber information locally
Subscriber Entity
Unique subscriber identifier (e.g., “SUB_A1B2C3D4_E5F6_7890_ABCD_EF1234567890”)
Number of messages to dequeue in a single batch operation (default: 1000)
Wait time in seconds for dequeue operations before timing out (default: 5)
Constructor
NewSubscriberService
Creates a new instance of SubscriberService with injected dependencies.Database repository interface for Oracle database operations
Configuration repository interface for BoltDB operations
Returns a pointer to the newly created SubscriberService instance
Methods
RegisterSubscriber
Retrieves an existing subscriber from BoltDB or creates a new one if not found. After ensuring a subscriber exists locally, it registers the subscriber as a listener in the Oracle database. This is the primary method used during application startup to ensure a valid subscriber is available for event listening.The registered subscriber with Name, BatchSize, and WaitTime populated
Returns error if retrieval, creation, or registration fails, nil on success
- Attempt to retrieve existing subscriber from BoltDB
- If subscriber not found (
ErrSubscriberNotFound), create a new subscriber - Register the subscriber with Oracle AQ
- Return the subscriber configuration
NewSubscriber
Generates a new unique subscriber with a UUID-based name and stores it in BoltDB.Newly created subscriber with:
Name: UUID v4-based unique identifier (format: “SUB_[UUID]”)BatchSize: 1000 (default)WaitTime: 5 seconds (default)
Returns error if storage to BoltDB fails, nil on success
- Prefix:
SUB_ - UUID v4 with hyphens replaced by underscores
- Uppercase
- Example:
SUB_A1B2C3D4_E5F6_7890_ABCD_EF1234567890
SetSubscriber
Stores the subscriber configuration in BoltDB.Subscriber configuration to store persistently
Returns error if storage operation fails, nil on success
GetSubscriber
Retrieves the subscriber configuration from BoltDB.Pointer to the stored subscriber configuration, or nil if not found
Returns
domain.ErrSubscriberNotFound if no subscriber exists, or other errors on storage failuresIntegration with Oracle AQ
The SubscriberService integrates with Oracle Advanced Queuing through the Oracle adapter’sRegisterNewSubscriber method. This creates a subscription in Oracle that allows the application to receive messages from the OMNI_TRACER_QUEUE.
Oracle Subscription Details
When a subscriber is registered with Oracle:- A subscription is created with the subscriber name
- The subscription is linked to the OMNI_TRACER_QUEUE
- The subscriber can then dequeue messages specific to that subscription
- Multiple subscribers can listen to the same queue independently
internal/adapter/storage/oracle) and handles the Oracle-specific subscription creation using Oracle AQ procedures.
Integration with BoltDB
Subscriber information is persisted to BoltDB to ensure:- The same subscriber ID is reused across application restarts
- No duplicate subscriptions are created in Oracle
- Fast retrieval without database queries
Usage Flow
Error Handling
ErrSubscriberNotFound
RegisterSubscriber method specifically handles this error to trigger new subscriber creation.
Example Error Handling:
Why UUID-based Subscriber Names?
The service uses UUID v4 for subscriber name generation to ensure:- Uniqueness: No naming conflicts even with multiple OmniView instances
- No Central Coordination: Each instance can generate its own unique ID
- Oracle Compatibility: Uses underscores instead of hyphens to comply with Oracle naming conventions
- Traceability: The SUB_ prefix makes it easy to identify OmniView subscribers in Oracle
Architecture Pattern
SubscriberService follows the hexagonal architecture (ports and adapters) pattern:- Core Service (internal/service/subscribers): Contains business logic
- Ports (internal/core/ports): Define repository interfaces
- Adapters:
internal/adapter/storage/boltdb: Implements ConfigRepositoryinternal/adapter/storage/oracle: Implements DatabaseRepository
- Clear separation of concerns
- Dependency inversion
- Easy testing with mock repositories
- Flexibility to change storage implementations
Related Documentation
- TracerService - Uses subscribers to listen for events
- PermissionService - Handles database permissions
- Architecture Overview - Learn about the hexagonal pattern
- Oracle Integration - Oracle AQ subscription details