Overview
TheTracerService is responsible for managing the OMNI_TRACER package deployment and event listening system in OmniView. It handles:
- Deploying and initializing the Oracle OMNI_TRACER package
- Starting event listeners for subscribers
- Processing batches of tracer messages from Oracle Advanced Queuing (AQ)
- Handling tracer events in a concurrent, non-blocking manner
Service Structure
Database repository for Oracle operations including package deployment and message dequeuing
Configuration repository for BoltDB operations and persistent storage
Mutex to prevent concurrent batch processing and ensure thread-safe dequeue operations
Constructor
NewTracerService
Creates a new instance of TracerService with injected dependencies.Database repository interface for Oracle database operations
Configuration repository interface for BoltDB operations
Returns a pointer to the newly created TracerService instance
Methods
StartEventListener
Starts the event listener for a specific subscriber. This method launches two concurrent goroutines:- Initial processing of any existing messages in the queue
- Blocking consumer loop that continuously listens for new messages
Context for managing the lifecycle of the event listener. Cancelling this context will stop the listener.
Subscriber configuration including name, batch size, and wait time:
Name: Unique subscriber identifier (e.g., “SUB_ABC123”)BatchSize: Number of messages to dequeue per batch (default: 1000)WaitTime: Wait time in seconds for dequeue operations (default: 5)
Oracle schema name where the tracer queue is located
Returns nil on successful start. The actual listener runs asynchronously in goroutines.
DeployAndCheck
Ensures the OMNI_TRACER package is deployed to the Oracle database and properly initialized. This method:- Checks if the package already exists
- Deploys the Omni_Tracer.sql package if not present
- Initializes the package using Omni_Initialize.ins if newly deployed
Returns error if package deployment or initialization fails, nil on success
blockingConsumerLoop
Internal method that runs a continuous loop listening for tracer messages. This method:- Blocks while waiting for messages from Oracle AQ
- Processes batches as they arrive
- Handles context cancellation for graceful shutdown
- Implements error recovery with exponential backoff
Context for cancellation signals
Subscriber configuration for dequeue operations
This is an internal method called by
StartEventListener. It runs indefinitely until the context is cancelled. On errors, it waits 5 seconds before retrying.processBatch
Processes a batch of tracer messages from the Oracle queue. This method:- Acquires a lock to prevent concurrent processing
- Dequeues messages in bulk from Oracle AQ
- Unmarshals JSON message payloads
- Passes each message to the message handler
Subscriber configuration including batch size for dequeue operations
Returns error if dequeue or processing fails, nil on success (including when no messages are available)
domain.QueueMessage structure:
Integration with Oracle Adapter
The TracerService integrates with the Oracle adapter through theports.DatabaseRepository interface, using these key methods:
- PackageExists: Check if OMNI_TRACER_API package is deployed
- DeployFile: Deploy SQL package files to the database
- ExecuteStatement: Execute initialization scripts
- BulkDequeueTracerMessages: Dequeue batches of messages from the Oracle AQ queue
Oracle AQ Configuration
The service works with these Oracle objects:Architecture Pattern
TracerService follows the hexagonal architecture (ports and adapters) pattern:- Core Service (internal/service/tracer): Contains business logic
- Ports (internal/core/ports): Define repository interfaces
- Adapters (internal/adapter/storage/oracle): Implement the ports for Oracle database
- Dependency inversion (service depends on interfaces, not concrete implementations)
- Testability (can mock repository interfaces)
- Flexibility (can swap Oracle for other databases)
Usage Flow
Error Handling
- Package Deployment Errors: Returned immediately to caller, causing application startup failure
- Dequeue Errors: Logged and retried after 5-second delay
- Unmarshal Errors: Logged but processing continues with next message
- Context Cancellation: Gracefully exits the consumer loop
Thread Safety
TheprocessMu mutex ensures that only one batch processing operation occurs at a time, preventing:
- Race conditions in dequeue operations
- Duplicate message processing
- Concurrent access to shared resources
Related Documentation
- SubscriberService - Manages subscriber registration
- PermissionService - Handles database permissions
- Architecture Overview - Learn about the hexagonal pattern
- Oracle Integration - Oracle AQ integration details