[erlang-questions] Multiple websocket subscribers to Kafka topic using Cowboy and Brod

Noah Silverman noah@REDACTED
Fri Nov 16 14:41:23 CET 2018


Hi,

I'm building an application where people can use websocket connections to receive streaming data from Kafka topics. 

Currently, I use Cowboy 2.5 to manage the websockets.  It works great!

However, I can only have ONE websocket subscribe to a Kafka topic using brod.  When The second person connects and subscribes, brod returns an error: {error,{already_subscribed_by,<0.1374.0>}}

In the Cowboy websocket handler, I handle subscription requests with a simple brod subscribe call:
brod:subscribe(api_brod_client, self(), Topic, 0, [])
Perhaps that's not the optimal way.
I did read that brod has a higher level call:  brod_topic_subscriber:start_link.  However, that wants a module it can callback with an init.  Since there is already a websocket process running from Cowboy, I don't want broad to start it again.
does anybody know of a simple way to have each websocket process just subscribe to the Kafka topic.  The brod_topic_subscriber might work, if there is a way to just feed the mssages back to the cowboy process calling it.

Thoughts?

--
Noah
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181116/d30ff2f7/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: publickey - noah@REDACTED - 0xBCEFA873.asc
Type: application/pgp-keys
Size: 3136 bytes
Desc: not available
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181116/d30ff2f7/attachment.bin>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 855 bytes
Desc: OpenPGP digital signature
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20181116/d30ff2f7/attachment-0001.bin>


More information about the erlang-questions mailing list