-
Notifications
You must be signed in to change notification settings - Fork 0
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
Conversation
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.
There was a problem hiding this 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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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( |
There was a problem hiding this comment.
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() |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM!
Quality Gate failedFailed conditions |
This PR includes implementation of the
RabbitMQ
plugin for local development. The key changes include:RabbitMQ
for local runs as well asDocker Compose Configuration
that setup a localRabbitMQ
instance with the management UI accessible via port: 15672.Azure Service Bus
,RabbitMQ
and eventuallyAWS SNS/SQS
.README
to include instructions and notes forRabbitMQ
setup.