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
Rewrite BrokerClient and RPC system #10
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- Remove shutdown hook in favor of manual `destroy()` call - Always send messages async - Properly synchronize topic creation - Fix vanilla build - Generalize consumerGroupId name - Remove unused BrokerClient properties
They can't have any value other than null.
ShindouMihou
approved these changes
Jan 31, 2024
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.
Did a quick scan on this, and it looks good to me 🔥
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Over time, the previous implementation of the BrokerClient system showed some flaws:
request
and aresponse
field, and populating one of them depending on the message direction.There were some more minor issues, but those three are the big ones which always caused headaches trying to implement new clients. Given that we plan to switch from Kafka to RabbitMQ soon, which is a breaking change anyways, I took this opportunity to (almost) completely rewrite our generic BrokerClient system to be a lot more flexible and to solve the aforementioned issues.
As before, new clients have to be subclesses of
BrokerClient
. This time, however, they do not need to immediately specify a topic and message type. Instead, the newBrokerClient
is just a shell object, which allows you to create a form of "subclient" using the convenientconsumer
,producer
and, most commonly,rpc
method. An example implementation looks as follows:This BrokerClient creates an RPC client using the
rpc()
method, which receives the request message type, response message type, and the target topic and key (the same topic can be used by multiple clients using different keys for different message objects). A single BrokerClient can house multiple RPC clients, eahc of which can use different message types, topics, and keys. An RPC client also contains the suspending callback which is invoked upon receiving a matching message, and, in this example, returns the calculated result using a default success status, or, when receiving an unsupported operation, throws an RpcException with a predefined error code.Below that,
calculateSum
invokes this RPC client with the passed request object. If the receive throws an RpcException, that exception will be re-thrown here. Thecall
method optionally allows specifying the target service that should receive the requests, as well as a specific instance within that service cluster. What service or instance a specific client belongs to is determinded by theBrokerConnection
. There is also astream
method on the RPC client which allows reading multiple response messages in response to a single request using a Kotlin Flow.Note
At the present, this rewrite only applies to the JVM implementation. The TypeScript port in Water will have to be updated as well before we can connect TS services to JVM services that are already using the new structure. Given we aren't yet using any TS services in production, this shouldn't be a big problem for now.