-
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
feat: idsse-897 rabbitmq_utils Rpc #87
Conversation
Co-authored-by: Geary Layne <[email protected]>
… _blocking_publish methods out of Publisher so Rpc can use them
Update: unit tests exist now. |
I found a bug that I thought I'd fix in your PR. Setting prefetch_count must be done before calling basic_consume.
Update rabbitmq_utils.py
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.
Looks good. Would you please create a task to make sure we have good test coverage for Publisher/Consumer.
@@ -98,6 +98,12 @@ class PublishMessageParams(NamedTuple): | |||
route_key: str | None = None | |||
|
|||
|
|||
class RpcResponse(NamedTuple): |
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.
Do we need this class in addition to PublishMessageParams?
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.
Technically no, but PublishMessageParams
is used for outbound RMQ messages and RpcResponse
was originally written for inbound responses. I just don't know what to name the class if it's used for both.
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.
Maybe "RabbitMqMessage"?
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.
That works, or RmqMessage if you want shorter.
@@ -117,7 +117,6 @@ def exec_cmd(commands: Sequence[str], timeout: int | None = None) -> Sequence[st | |||
|
|||
def to_iso(date_time: datetime) -> str: | |||
"""Format a datetime instance to an ISO string""" | |||
logger.debug('Datetime (%s) to iso', datetime) |
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've wondered if these need to be here a few times.
RpcResponse | None: The response message (body and properties), or None on request | ||
timeout or error handling response. | ||
""" | ||
if not self.is_open: |
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 like that this gets handled
Co-authored-by: Geary Layne <[email protected]>
NOTE: depends on PR #88<-- mergedLinear Issue
IDSSE-897
Changes
Rpc
class in rabbitmq_utilsConsumer
Publisher
logic to blocking_publish messages to an exchange, but reuses the Consumer's thread which is a constraint of Direct Reply-toConsumer
then listens to responses coming back over RabbitMQ's built-in Direct Reply-to queue and returns the response message to the caller when it is receivedCallers can simple instantiate an Rpc class (providing the params of the exchange to publish to), call
start()
, then publish messages withsend_request()
. This method will block until the receiving RMQ service sends a response (or times out), formatted as anRpcResponse
(containing the body and properties of the message).Explanation
This type of logic existed in Risk Processor (called "RpcClient"), but moving it here and correctly using these newer rabbitmq_utils classes helps standardize behavior across IDSSe services.