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

Add message producer #125

Merged
merged 3 commits into from
Nov 7, 2024
Merged

Add message producer #125

merged 3 commits into from
Nov 7, 2024

Conversation

meandnano
Copy link
Contributor

@meandnano meandnano commented Oct 13, 2024

What

This PR implements the producer side of the Cloudflare Queues feature.

Motivation

#53

@meandnano meandnano marked this pull request as ready for review October 14, 2024 20:58
@syumai
Copy link
Owner

syumai commented Oct 16, 2024

I'll check this later, thanks!

@meandnano
Copy link
Contributor Author

Just wanted to mention it: since queues require paid plan, it might be uncomfortable to test this remotely. But I now use this implementation of queues api in my worked on a paid plan it works as expected. I'll create consumer api PR once this one is merged.

//
// - https://developers.cloudflare.com/queues/configuration/javascript-apis/#producer
// - https://developers.cloudflare.com/queues/configuration/javascript-apis/#queuesendoptions
func (p *Producer) Send(content any, opts ...SendOption) error {
Copy link
Owner

Choose a reason for hiding this comment

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

In Go, Send method with any content type doesn't seem useful enough.
I think ContentType send option should be removed and separated Send methods should be declared.

e.g.

func (p *Producer) SendText(content string, opts ...SendOption) error {}
func (p *Producer) SendBytes(content []byte, opts ...SendOption) error {}
func (p *Producer) SendJSON(content any, opts ...SendOption) error {}
func (p *Producer) SendV8(content js.Value, opts ...SendOption) error {}

I'll separate current implementation after.

}

// SendBatch sends multiple messages to a queue. This function allows setting options for each message.
func (p *Producer) SendBatch(messages []*BatchMessage, opts ...BatchSendOption) error {
Copy link
Owner

Choose a reason for hiding this comment

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

I think BatchMessage should not just be a struct with any values, but a common type or interface constructed in the following form:

func NewTextBatchMessage(content string, opts ...SendOption) BatchMessage
func NewBytesBatchMessage(content []byte, opts ...SendOption) BatchMessage
func NewJSONBatchMessage(content any, opts ...SendOption) BatchMessage
func NewV8BatchMessage(content js.Value, opts ...SendOption) BatchMessage

I'll try to change the current implementation after.

Copy link
Owner

@syumai syumai left a comment

Choose a reason for hiding this comment

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

I'll do some changes after merging this.
Thank you for great implementation!

@syumai syumai merged commit dfdd7e7 into syumai:main Nov 7, 2024
2 checks passed
@syumai
Copy link
Owner

syumai commented Nov 9, 2024

@meandnano This feature has been released as v0.27.0, thanks!
https://github.com/syumai/workers/releases/tag/v0.27.0

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