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

Disable automatic call to handle_batch/4 #305

Closed
rogerweb opened this issue Jul 11, 2022 · 2 comments
Closed

Disable automatic call to handle_batch/4 #305

rogerweb opened this issue Jul 11, 2022 · 2 comments

Comments

@rogerweb
Copy link

Hi,

Would it be possible to prevent Broadway from automatically calling handle_batch/4 and let the user do it when ready? Even better if it could take only the message_id instead of the whole message (not sure Broadway or the producer keeps the message to itself somewhere).

The problem I'm trying to solve is: I'm consuming messages from SQS and delivering each one to the respective target user via his own Phoenix channel (user:123), but I would like to be sure the message got delivered before acknowledging it (i.e., removing it from SQS). Since Phoenix's broadcast/3 return value is not an actual "ack", I'm planning to make the browser to push an "ack" message back to the channel, with the Broadway's message_id. However, how can I make Broadway to wait for it (or timeout) from the handle_message/3?

@josevalim
Copy link
Member

I think in your case, then you don't want to use Broadway's buitin ack at all. You can disable it and then ack from the channel once you receive the client message. You can set the ack to noop here: https://hexdocs.pm/broadway_sqs/BroadwaySQS.Producer.html#module-acknowledgments

@rogerweb
Copy link
Author

Thanks @josevalim for the quick reply. I managed to do it the naive way, a single GenServer accumulates the receipts from the clients and uses ExAws to delete the messages once the batch size is reached or times out. Now I'm trying to figure out how many processes should I start and how to distribute the receipts to them. Do you think I should have one process per partition? Should I try to leverage any existing module from Broadway?

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

No branches or pull requests

2 participants