Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dasb 615- Implement RabbitMQ plugin for Local Development #172

Merged
merged 18 commits into from
Sep 3, 2024

Conversation

TeaSmith7
Copy link
Collaborator

This PR includes implementation of the RabbitMQ plugin for local development. The key changes include:

  1. RabbitMQ plugin: setup and configuration of RabbitMQ for local runs as well as Docker Compose Configuration that setup a local RabbitMQ instance with the management UI accessible via port: 15672.
  2. Implemented utils package with schema validation logic to be re-used across supported messaging systems, currently Azure Service Bus, RabbitMQ and eventually AWS SNS/SQS.
  3. Updated README to include instructions and notes for RabbitMQ setup.

Added dependency build.gradle
Added RabbitMQ service as dependency to Docker Compose with rabbitMQ management plugin.
Introduced environment variables for AWS, Azure Service Bus, RabbitMQ to specify which system to use.
Initial work for RabbitMQ plugin that connects to the RabbitMQ, and listens to the queue
updated Readme with environment variables configuration for Messaging Systems, as well as steps to send reports to rabbitMQ server.
Improvements to RabbitMQ plugin: Added exception handling, improved Kdoc comments.
Removed routingKey and ExchangeType from environment variables.
Added utils package and created HelpersFunction for the purpose to re-use functions across asb, rabbitMQ and eventually aws sns/sqs plugins.
Application.kt- added cosmosModule back
RabbitMQ.kt - updated logging
RabbitMQProcessor.kt - updated logging and calling validateJsonSchema() from HelperFunctions.kt to proceed with report validation
HelperFunctions.kt - moved functions for report validation logic to be re-used for all messaging systems
When disableValidation is True and the message is not valid JSON, the message is sent to the DLQ, and a return statement is added to prevent report creation.
…ect their purpose

- Class: RabbitMQUtil() -> RabbitMQService()
- File: HelperFunctions.kt -> SchemaValidationFunctions.kt
refactored service bus plugin to use schema validation related functions from utils package.
Updated log messages and Kdoc comments
…Bus module

the function is called when application goes down.
Copy link
Collaborator

@mkrystof mkrystof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Some changes requested, please. Thanks for updating the readme too!




object Helpers {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's encapsulate all of this in a class called SchemaValidation. Make the contents of the Helpers a companion object of the SchemaValidation class.

}
}
@Throws(BadRequestException::class)
fun createReport(createReportMessage: CreateReportSBMessage) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please generate the missing function header comments?

false
}
}
fun sendToDeadLetter(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing comment header

@@ -52,7 +67,28 @@ fun main(args: Array<String>) {
*/
fun Application.module() {
configureRouting()
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please update the HealthQueryService to selectively check for the health of the messaging service? In other words, right now it is always checking ASB, but needs to check RabbitMQ, etc depending on the config.

}
MessageSystem.RABBITMQ.toString() -> {
single(createdAtStart = true) {
RabbitMQService(environment.config, configurationPath = "rabbitMQ")
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For clarity, similar to the ASB service configuration we may want to rename this to RabbitMQServiceConfiguration. Also, this will align with naming for AzureServiceBusConfiguration.

Update Kdoc comments for functions
Create SchemaValidation class and move contents of Helpers object into a companion object
Rename RabbitMQService to RabbitMQServiceConfiguration'
Note: This PR does not include requested changes for HealthQueryService, will do that next.
Added msgType to Koin module for dependency injection.
Added logic for getting Health of RabbitMQ messaging service.
Updated HealthCheck.kt to retrieve the health status of the messaging service based on the msgType from the config.
removed irrelevant exceptions
`checkAndReplacedDeprecatedFields()`
* @param jsonString to be checked
* @return boolean true if its valid JSON otherwise false
*/
fun isJsonValid(jsonString: String): Boolean {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a general good practice, we should strive to avoid writing functions that aren't part of a class. For example, the isJsonValid could be an Extension of String. See https://kotlinlang.org/docs/extensions.html.

* @param messageAsString message to be checked against depreciated fields.
* @return updated message if depreciated fields were found.
*/
fun checkAndReplaceDeprecatedFields(messageAsString: String): String {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This function might be best if made part of the Report class. It could be a companion object.

* @param message ReceivedMessage(from Azure Service Bus, RabbitMQ Queue or AWS SNS/SQS)
* @throws BadRequestException
*/
fun validateJsonSchema(message: String) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same sentiment as above - can we find a home for all these functions?

removed  SchemaValidationFunctions.kt and merged functions into SchemaValidation.kt
Updated RabbitMQProcessor() and ServiceBusProcessor() to use functions from SchemaValidation.kt
Simplified loadSchemaFile() by removing the schemaDirectoryPath parameter, since the schema is retrieved using javaClass.classLoader.getResource() and folder name is constant schema.
@@ -85,8 +102,12 @@ class HealthQueryService: KoinComponent {
fun getHealth(): HealthCheck {
Copy link
Collaborator Author

@TeaSmith7 TeaSmith7 Sep 3, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sonar cloud tags this function with brain overload, I agree it's too much going on for a single function. I will refactor with private functions for checking health.

import java.util.*
import javax.activation.MimeType

class SchemaValidation {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you please add a class comment header? Description should provide overview of the class - intent, usage, etc.

}


class RabbitMQServiceConfiguration(config: ApplicationConfig, configurationPath: String? = null) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add class comment header.

import org.apache.qpid.proton.TimeoutException
import java.io.IOException

object RMQConstants {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this would be better as a companion object of RabbitMQServiceConfiguration.

RabbitMQ.kt - moved constants to under RabbitMQServiceConfiguration class and added class comment header
SchemaValidation.kt - added class comment header
Copy link
Collaborator

@mkrystof mkrystof left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

Copy link

sonarcloud bot commented Sep 3, 2024

Quality Gate Failed Quality Gate failed

Failed conditions
1 Security Hotspot

See analysis details on SonarCloud

@TeaSmith7 TeaSmith7 merged commit 432ef6a into develop Sep 3, 2024
0 of 2 checks passed
@TeaSmith7 TeaSmith7 deleted the DASB-615 branch September 4, 2024 18:06
@TeaSmith7 TeaSmith7 restored the DASB-615 branch September 4, 2024 18:07
@TeaSmith7 TeaSmith7 deleted the DASB-615 branch September 4, 2024 18:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants