rogerweb

rogerweb

How to acknowledge a Broadway message asynchronously?

Hi,

Scenario

I have a SQS queue with messages, each message is targeted to a specific user, each user joins his own Phoenix channel via websocket. I’m using Broadway to keep pulling the messages. In it’s handle_message/3 I use Phoenix’s broadcast/3 to push the message to the user:

Endpoint.broadcast("user:#{user_id}", "message", message)

I would like to make sure the user has received the message before I acknowledge it to Broadway/SQS.

Since the broadcast/3 doesn’t return the delivery result, I’m planning to make my JavaScript library to push an “ACK” back to the channel. I would include Broadway’s message_id in both messages.

The problem

How can I acknowledge the message to Broadway from the Phoenix’s channel handle_in/3?

As a side note, I started wondering if Broadway is the right tool for my use case, given the handle_message/3 documentation says:

Basically, any CPU bounded task that runs against a single message should be processed here.

but my task is more an I/O thing.

Any help is much appreciated.

First Post!

benwilson512

benwilson512

Author of Craft GraphQL APIs in Elixir with Absinthe

Yeah you probably want to do the broadcast in handle_batch because it would let you push a batch of messages from SQS to the end user, and then do a more efficient ACK back to SQS.

As far as getting the ACK from the client side, I think your only option is to block handle_batch until you get a message back from the client. Getting this ack back might be a bit tricky, perhaps you’ll have to have the broadway producer subscribe to an ack topic before pushing the messages out?

Where Next?

Popular in Questions Top

aalberti333
As the title describes, I’m trying to run Enum.map() over a list of key/value pairs, where the value is a map. My data looks like this: ...
New
_russellb
I want to try my hand at web scraping. What tools/libraries do I need to use. I’m hoping to turn this into something professional so don’...
New
New
lk-geimfari
What is most correct way to open, read and parse JSON file with poison? For example if we have example.json file in root of some projec...
New
Phillipp
Hey, I have a NanoPi-M3 and try to install Elixir on their Ubuntu image. I followed the Raspberry Pi installation instructions from the ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
WestKeys
Currently suffering from paralysis by [HTTP client] analysis. This is rather unusual in Elixirland as there tends to be consensus on the ...
New
sabri
Can someone explain the settings of pool_size of Ecto in config file? and what is the recommend size? Thanks
New
romenigld
I am trying to run a deploy with docker and I successfully runned with this command: docker build -t romenigld/blog-prod . but when I t...
New
vrod
I am using the Starship cross-shell prompt – it seems pretty nice, but I get some errors: [WARN] - (starship::utils): Executing command ...
New

Other popular topics Top

openscript
Hello! Sorry for this astonishing simple question, but I’m really stuck. I try to set up the intellij-elixir plugin, but I don’t know ho...
New
jerry
Good day to you all. I have been struggling to get a query involving like and ilike to work. Can anyone assist me on this, please? pro...
New
lastday4you
I wanted to check elixir version in phoenix because i found that my elixir is 1.5 but when i use Enum.chunk_by it said the function is un...
New
danschultzer
None of the current solutions worked well for me, so I went ahead and built a user management system from scratch. This project took far...
548 27727 240
New
minhajuddin
I have seen a lot of code which picks the first element from a list using Enum.at(0) instead of List.first. Is there a reason why people ...
New
chensan
I have a User schema with a :from_id field set to type :string: defmodule TweetBot.Repo.Migrations.CreateUsers do use Ecto.Migration ...
New
shahryarjb
Hello, I have map which I want to convert it to string like this: the map: %{last_name: "tavakkoli", name: "shahryar"} the string I ne...
New
ovidiubadita
Hey all, I discovered Elixir and I love it. I always wanted to learn a functional programming and I intended to go for Haskell, but afte...
New
josevalim
Hi everyone, One of the features added to Elixir early on to help integration with Erlang code was the idea of overridable function defi...
New
lucidguppy
I have a super simple question about elixir - how would I take a file like this foo bar baz and output a new file that enumerates th...
New

We're in Beta

About us Mission Statement