amber icon indicating copy to clipboard operation
amber copied to clipboard

Allow Amber to handle multiple channels in Amber Redis Websockets Adapter

Open mixflame opened this issue 4 years ago • 5 comments

Description of the Change

  • Build a list of channels as channels are initialized
  • Subscribe in adapter initialize method in addition to on_message setup callback
  • Build a list of listeners in a hash which are differentiated by @topic_path (channel name)
  • Call the correct listener on message on published message
  • Make sure via a boolean that we only ever subscribe loop once
  • Honor crystal-redis and resubscribe via a crystal channel on message like it was before but with multiple channel support

Alternate Designs

Tried a bunch of stuff which didn't work but helped me build this

Benefits

Amber Redis Adapter for Websockets will now be able to serve pub sub subscriptions on multiple channels

Also now it cannot be unsubscribed because it will resubscribe on message like it used to

Possible Drawbacks (How to Use)

None. The style can maybe be refactored. I used a constant. There are no drawbacks.

Amber::Server.pubsub_adapter = Amber::WebSockets::Adapters::RedisAdapter

Tests included.

mixflame avatar Jun 16 '21 02:06 mixflame

+1 thank you for this codes

any time! :)

mixflame avatar Jul 06 '21 11:07 mixflame

Thanks Elias.... I will have the cleanup ASAP

mixflame avatar Aug 05 '21 01:08 mixflame

Elias,

Thanks for your review.

I cleaned up the code.

We can test it for production usage.

Thanks, Jon

mixflame avatar Aug 05 '21 02:08 mixflame

This is blocked by a crystal-redis merge confirming a vulnerability (that is patched) to an exploit (RCE) that I don't have the code for. With my crystal-redis patch, this cannot be exploited. I'm suspecting incorrect type routing through crystal-redis casts via strange inputs. This can be merged and the custom code can be used, but I hope to resolve the problem with crystal-redis and get an official OK for the entire deployment.

mixflame avatar Sep 04 '21 04:09 mixflame

I have confirmation that this is solid code from a while of testing on production. The error in crystal-redis was an error in my own Amber project. This can be merged. It's also now back to using the default crystal-redis from @steffanwille.

mixflame avatar Sep 10 '21 01:09 mixflame

This is a really ancient PR. A lot has changed in the redis ecosystem since then, it might be worth considering switching to https://github.com/jgaskins/redis -- it has much more stable connection management, uses the stdlib pool implementation, and is still actively maintained to boot. There was a bunch of discussion on Mosquito about this, and @jgaskins provided a lot of detailed comparison points about the two libraries.

Unfortunately during the course of that discussion I could not find a way to support both libraries -- one of them is module Redis and the other is class Redis which means both cannot even be installed in the same project and there is no obvious way to stub it out generically that doesn't pile on a bunch of maintainer overhead.

robacarp avatar Nov 14 '22 20:11 robacarp

@robacarp Ok, I am going to close this out. Thanks for providing the discussion about Redis. That will have impact on Amber for sure. We should open an issue to address that separately.

drujensen avatar Nov 14 '22 20:11 drujensen