RabbitMQ Architecture Restructuring & Key Updates
What developments have taken place today?
Today’s work focused on significantly restructuring the RabbitMQ consumer architecture for increased modularity, testability, and maintainability. Key changes include:
- Generic Consumer Pattern: A new
GenericConsumer
struct and function were introduced to standardize message handling across different RabbitMQ message types (email, checker, certificate). This allows for flexible message processing through a registry object and handler interface. - RabbitMQ Helper Package: The core RabbitMQ logic was moved into the
helper_rabbitmq
package, promoting separation of concerns with new functions likeNewRabbitMQ
,QueueMessage
, and interfaces such asRabbitConsumerDataEmail
. - Specific Consumer Structs: Separate consumer structs (
CertificateConsumer
,CheckerConsumer
,EmailConsumer
) were created for each message type, inheriting from theGenericConsumer
and utilizing the registry object to access relevant data. - JSON Message Serialization: Functions were added to marshal and unmarshal RabbitMQ messages into JSON format, facilitating easier communication between components.
- Refactoring of Existing Functions: The
CheckLightHouse
andInsertWebsiteUrlToRabbitMQ
functions were refactored to utilize the new generic consumer pattern andQueueMessage
method respectively. Email verification and registration handlers now leverage the new consumer functions for message publishing. - Configuration Updates: The RabbitMQ queue naming conventions were updated in the configuration file (e.g.,
checker
,lighthouse
,email
,certificate
). - Enhanced Admin Dashboard: The admin dashboard was updated with a loading indicator and placeholder element to provide visual feedback during data fetching, improving user experience.
This commit makes several changes related to RabbitMQ integration within the application. Here’s a breakdown of the modifications:
- RabbitMQ Configuration Updates: The
Config
struct now includes fields for various queues under the"rabbit_queues"
section, centralizing queue names in configuration and theRabbitMQ
struct accepts a RabbitMQ address during initialization. NewRabbitMQ
Function: A new functionNewRabbitMQ
simplifies RabbitMQ instance creation by taking the RabbitMQ address as an argument, promoting code reusability.SendMessageToRabbitMQ
Function Updates: TheSendMessageToRabbitMQ
function now takes a queue name and message body as inputs, making it more versatile. It uses the provided queue name to declare and publish messages to the correct RabbitMQ queues, with improved error handling via logging.InsertWebsiteUrlToRabbitMQ
Function: This function remains largely unchanged but now leverages theNewRabbitMQ
function for RabbitMQ instance creation, improving code clarity. It also uses the correct queue name from configuration.- Changes in Consumer Logic (Checker & Lighthouse): The
StartCheckerConsumer
andCheckLightHouse
functions were updated to use the newNewRabbitMQ
function to instantiate RabbitMQ clients and send messages to appropriate queues based on configuration settings. - Email Verification and Registration Handler Changes: The
StartCertificateC
function was updated to utilize the new RabbitMQ consumer structure and message publishing logic when sending email verification messages.
This commit modifies the code related to displaying website expiration information in a table.
Here’s a breakdown of the changes:
- API Response Types: The
WebsiteCertificate
struct is updated to allow for optional (nullable) string values for expiration dates and certification expiration dates, replacing them with pointers totime.Time
. This accommodates cases where an expiration date might be unavailable or not yet set. - API Response Data: The
ApiResponseDomainExpiration
struct is adjusted to accommodate the new nullable time types. It now usesstring | null
forexpiration_date
andcertification_expiration_date
, and includes logic within the constructor to format these times into RFC3339 strings when available, otherwise leaving them blank. - Database Model: The
Website
struct is updated to usesql.NullTime
instead ofsql.NullString
forCertificationExpiration
. - Database Save Operation: The database save operation now uses
UTC_TIMESTAMP()
instead of the previous timestamp method. - Rendering Row Logic: Changes were made to rendering the rows in the table, including using conditional logic and CSS classes based on the expiration dates and days remaining to expire, to visually indicate certification status (green, orange, red).
This commit refactors the code to improve certificate expiration handling within the CertificateConsumer.
Specifically, it replaces the helper_domain.NewDomain
function with a new one that takes a WhoisClient
and CertificateFetcher
as arguments. The NewDomain
function now injects
rabbitmq consumer architecture refactoring json serialization configuration updates api response certificate expiration