<FromGitter>
<damianham> @drujensen how do we get the Amber server to use the WebSockets::Adapters::RedisAdapter instead of the WebSockets::Adapters::MemoryAdapter ?
<FromGitter>
<drujensen> @damianham Nick Franken (https://github.com/fridgerator ) wrote most of the WebSockets code in Amber. My guess at the time there were no Adapters and he just stored them in memory directly. not sure how difficult it would be to introduce them.
<FromGitter>
<drujensen> Actually, it looks like he did have them
<FromGitter>
<drujensen> The property `Amber::Server.pubsub_adapter` can be set to `WebSockets::Adapters::RedisAdapter`
<FromGitter>
<drujensen> and that will use `Amber.settings.redis_url`
<FromGitter>
<drujensen> This seems to compile. Haven’t tested it. unfortunately, it doesn’t look like this was moved over to the `Amber::Server.settings` so you will need to add this in the `config/settings.cr` outside of the settings block.
<FromGitter>
<drujensen> let me know if this worked for you. We can clean this up and have better documentation here.
<FromGitter>
<drujensen> sorry for misleading you here. I should have verified. I was told we didn’t have this feature a while ago but looks like we do.
<FromGitter>
<drujensen> @damianham Thanks for pointing this out! I’m going to test this and verify the `on_message` is working across processes / servers.
<FromGitter>
<damianham> @drujensen my use case is I want to inject messages from a controller to be delivered to connected clients in a specific channel across the set of running processes / servers, e.g. push notifications.
<FromGitter>
<drujensen> right
<FromGitter>
<drujensen> can you get the subscribers in the controller via `subscribers = Amber::WebSockets::ClientSockets.get_subscribers_for_topic(my_topic)`?
<FromGitter>
<drujensen> hhm, but how do you `rebroadcast!`
<FromGitter>
<damianham> yeah... I've been going over the websockets code all day. I think it might need a bit of refactoring.
<FromGitter>
<drujensen> maybe you can do something similar?
<FromGitter>
<damianham> well... in theory if I publish to redis and redis propogates to the other processes the on_message handler should propogate to the clients. I *think* that's they way it is supposed to work.
<FromGitter>
<drujensen> yes, i think each process will get the on_message callback
<FromGitter>
<drujensen> from redis
<FromGitter>
<drujensen> so I guess a better way would be to publish a message from the Controller
<FromGitter>
<drujensen> then redis will pickup the message and send it to all the other processes?
<FromGitter>
<drujensen> if you can get your hands on the Channel instance, there is a `dispatch` method
<FromGitter>
<damianham> I am still checking it out but they I would have thought it *should* work is that a broadcast in 1 client socket should publish to the redis server which will propagate to the other processes.
<FromGitter>
<drujensen> yes, i think that is right
<FromGitter>
<drujensen> the `dispatch` method calls `adapter.publish`
<FromGitter>
<drujensen> For the redis adapter, that sends `publish` to the redis server.
<FromGitter>
<drujensen> which in theory, would trigger the `on_message` in all the processes that are listening
<FromGitter>
<damianham> I put some log statements in the code and I am seeing it being propagated to the redis server, but my issue might have been with the topic name
<FromGitter>
<drujensen> can you see the redis path that the message is published too?
<FromGitter>
<drujensen> `topic_path`?
<FromGitter>
<damianham> ahhhh topic_path, and therein lies an element of confusion
<FromGitter>
<drujensen> each Channel has its own path
<FromGitter>
<damianham> I wasn't using "chatroom:*" as the channel 'name' in the socket. trying that now.
<FromGitter>
<damianham> In the Socket subclass of ClientSocket I am using ⏎ ⏎ ```subscribers = ClientSockets.get_subscribers_for_topic(message["topic"])``` ⏎ ⏎ It could be that the 2 clients are both connected to the other process. [https://gitter.im/amberframework/amber?at=5e89fe45d021c45cc7c71c0e]
<FromGitter>
<damianham> nothing is being propagated to the redis server
<FromGitter>
<drujensen> yeah, you won’t be able to do my first suggestion
<FromGitter>
<drujensen> I think you want to grab an instance of the Channel and send the `dispatch(message)` instead
<FromGitter>
<drujensen> this will `publish` the message to the adapter which in this case is Redis
<FromGitter>
<drujensen> and then all the `subscribers` should get an `on_message` event
<FromGitter>
<drujensen> even in different processes or servers
<FromGitter>
<damianham> Ok I will try that
<FromGitter>
<drujensen> I am running this on my server now and it seems to be working with 4 processes.
<FromGitter>
<drujensen> I will keep testing to verify the messages are being sent
<FromGitter>
<drujensen> I am sending them from the client though, not from a controller
<FromGitter>
<damianham> I think that maybe the difference as when it comes from a client you are already in the subscription manager I thnik
<FromGitter>
<drujensen> yeah, let me see if I can try what you are trying to do. btw, thanks for pointing out the Redis Adapter exists.
<FromGitter>
<drujensen> This is something I wanted to fix for a long time and never looked into it.
<FromGitter>
<drujensen> super happy there is already a Redis Adapter.
<FromGitter>
<andrewc910> Quick question about security. Amber generates a .encryption_key file & puts the file name into the gitignore. This is the key used to decrypt the production.enc file, correct? Why do we also put the key in the development.yml & test.yml? Are we not suppose to check those in?