-
-
Notifications
You must be signed in to change notification settings - Fork 16
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: add RabbitMQ publisher #137
feat: add RabbitMQ publisher #137
Conversation
@@ -15,28 +15,81 @@ func ${operation}(msg *message.Message) error { | |||
} | |||
`; | |||
|
|||
function SubscriptionHandlers({ channels }) { | |||
export function SubscriptionHandlers({ channels }) { | |||
return Object.entries(channels) | |||
.map(([channelName, channel]) => { | |||
if (channel.hasPublish()) { | |||
const operation = pascalCase(channel.publish().id()); |
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.
operationId
is not mandatory so can be empty. I didn't realize the fact we were using it for generating the method names.
I think we should generate one if it's empty. Maybe channel name + operation type.
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.
Exactly! Either:
- Some method (handler function) name is auto generated (and have it documented). Currently, nothing is included, and ofc, we have a syntax error in two (declaration and usage) places.
- Or the docs of this generator should explicit that
operationId
should be used to properly define your handler name.- For a good UX, I would prefer to output the fact that some generated names where included, since no explicit
operationId
exists in the spec.
- For a good UX, I would prefer to output the fact that some generated names where included, since no explicit
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.
And there is also $id
property of payload
, based on which the proper Go struct
naming is done.
That's another useful and optional thing (without it you get a name, but it's something like AnonymousSchema
which is not that not that great. It's ok that it is generated, no syntax errors, but the naming can be improved).
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.
@smoya @dxps thanks for noticing this.
I am tempted to generate a method name based if operationId
is not present.
But as @dxps mentions we would have to make sure there are no duplicate names.
Another thing I notice is that channel names can have special characters. So we would have to remove all special characters.
I like @dxps's suggestion to mandate an operationId
for this spec. Meanwhile I can also check other generators on how they handle this scenario
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.
@anandsunderraman I reviewed the code again and I noticed you didn't add a guard checking if the operationId
is present, forcing the user to set it or throwing an error otherwise. You have an example in nodejs-ws-template.
Also, I would mention this in the README file as for example java-spring-template does.
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.
Good catch! Forgot about operationId
, although I mentioned it initially.
The other part that could get improved is related to the $id
property of payload
, based on which the proper Go struct naming is done. That's another useful and optional thing, without specifying it you get a name like AnonymousSchema
which is not that great or useful.
@anandsunderraman Could you please react on the provided feedback? |
@dxps I was waiting for all reviewers to provide feedback, so that I can make my changes all at once, preventing multiple back and forth |
@anandsunderraman While just testing it with the spec mentioned here, which the spec does not yet declare any
Used |
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.
Just a heads-up for now (for the 1st one, I'll look into it myself as well, to see how harmful it can be):
- In
payloads.go
, there is this warning:
- In
main.go
, there is this warning:
This can easily be solved by checking for that error, by introducing these after that call:if err != nil { return err }
- In
handlers.go
,context
package is being used, but not included in theimport
section.
This is another easy to solve one.
Besides these, I tested the generated code and is functionally working.
So, thank you for doing this! 🙏
Ok, I understand the 1st warning ( To solve it, the code should be slightly updated as follows:
|
Last but not least, some small improvements that can be included in
|
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 did not look into logic code as I see others already did it.
I only left one comment about one script name. Also please change PR title to feat: add RabbitMQ publisher
. I also think it would be worth extending the readme overview with some more info on what users can generate with this template. Also good to add development
section and explain the dev
script.
One curiosity question: why did you add dependency related to babel?
@dxps again thanks for finding this issue I will look to address it |
@dxps Completely agree with this suggestion. However I feel this needs more investigation to be done in the watermill.io fashion. I will create a separate issue to handle this |
18be24d
to
abe6d3b
Compare
If I did not add babel I was getting the error:
|
abe6d3b
to
cacb656
Compare
With these recently introduced updates, the generated code for the publisher looks good and it works. |
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.
Pasting here as the conversation was marked as solved (now I unresolved).
https://github.com/asyncapi/go-watermill-template/pull/137/files#r847178655
@anandsunderraman I reviewed the code again and I noticed you didn't add a guard checking if the operationId is present, forcing the user to set it or throwing an error otherwise. You have an example in nodejs-ws-template.
Also, I would mention this in the README file as for example java-spring-template does.
abe94d8
to
1e21991
Compare
@smoya apologies. Thanks for pointing out to the other generator examples. |
1e21991
to
d0b9812
Compare
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.
Superb work @anandsunderraman! Thanks for such an effort; It has been a pleasure to review this PR :)
LGTM!🚀 🌔
thanks @smoya !! |
🎉 This PR is included in version 0.2.0 🎉 The release is available on: Your semantic-release bot 📦🚀 |
Description
Creating a amqp publisher from asyncapi file
Related issue(s)
#132
Summary of Changes
amqp
publishers undercomponents/Handlers.js
amqpPublisher
undercomponents/Publisher.js
components/common.js
template/asyncapi/payload.js
main.go
file intemplate/index.js