manageplaces / Stompex

A STOMP client for Elixir
MIT License
12 stars 7 forks source link

SSL connection to stomp server #5

Open rosacris opened 7 years ago

rosacris commented 7 years ago

Hi,

in our project we are using Stompex to connect to ActiveMQ and so far it works wonderfully. Howerver, when deploying the app in the production environment, we discovered that ActiveMQ only accept SSL connections. Is there a way to enable SSL to Stompex?

Thanks!

pareeohnos commented 7 years ago

Hey, sorry for the delay, I was on annual leave. There isn't currently built in support for this, but definitely something I'd be interested in getting added.

I'll have a look around at the various options, but are there any specific ones that your ActiveMQ server requires that you'll need to be configuring?

rosacris commented 7 years ago

Hi,

no problem for the delay, lucky you! We found a workaround using a dirty hack. Basically, we've implemented a TCPWrapper module that dynamically delegates the :gen_tcp functions to :ssl module depending on a configuration variable. I do not like it much, but it was the fastest way. You can check my fork https://github.com/rosacris/Stompex/commits/master

What I really do not like is the fact that Erlang exposes SSL support through an external app, instead of implementing it as an option to the :gen_tcp module. This makes building apps with SSL support more complex.

pareeohnos commented 7 years ago

hm yeah it is a bit messy, not entirely sure why it's been done like that, but guessing they have their reasons. I imagine its related to the fact that the SSL module implements a cache for PEM files, but would've thought there was a better approach.

I'll do some digging and see if there are any less hacky options but I imagine it's going to end up with some wrapper or logic to switch between the two, and it certainly looks like the ssl module only supports SSL connections, and gen_tcp only supports non SSL which is a shame.

pareeohnos commented 7 years ago

OK so I've pushed a new branch ssl if you want to try it out. I've not updated the documentation on github just yet (although in the code it's updated) but to use it you can basically supply any option that the :ssl module accepts in erlang. For basic usage though, you should be able to use

Stompex.connect(host, port, login, pass, headers, secure: true)

And that SHOULD in theory work.

If you could test it and report back that would be great, as I don't have an SSL server to test this out with, but the refactoring seems to be working fine with a non SSL server, so hopefully should work with SSL but who knows :)

rosacris commented 7 years ago

Hi,

Great! I'll test it out tomorrow and let you know. Thanks!

Cristian

2017-04-12 17:03 GMT-03:00 pareeohnos notifications@github.com:

OK so I've pushed a new branch ssl if you want to try it out. I've not updated the documentation on github just yet (although in the code it's updated) but to use it you can basically supply any option that the :ssl module accepts in erlang. For basic usage though, you should be able to use

Stompex.connect(host, port, login, pass, headers, secure: true)

And that SHOULD in theory work.

If you could test it and report back that would be great, as I don't have an SSL server to test this out with, but the refactoring seems to be working fine with a non SSL server, so hopefully should work with SSL but who knows :)

— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub https://github.com/manageplaces/Stompex/issues/5#issuecomment-293691392, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqjkttLoQYkChKz30pz7DJr9Yj58tGDks5rvS4DgaJpZM4MvvEJ .

pareeohnos commented 7 years ago

@rosacris did you get a chance to test this out?

rosacris commented 7 years ago

Hey, I'm sorry for the delay, we finally ended up scrapping out stomp and switched to mqtt, mainly for the lack of heartbeats (all Elixir/Erlang clients lacked either SSL or heartbeats). Tomorrow I'll create a test project with Stompex as a dep and try to connect.

I'm sorry for the lack of input.

Best C

El jun. 6, 2017 6:23 PM, "pareeohnos" notifications@github.com escribió:

@rosacris https://github.com/rosacris did you get a chance to test this out?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/manageplaces/Stompex/issues/5#issuecomment-306621600, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqjkugJBiXEypSbTFfjrD49oNxlhPP6ks5sBcNhgaJpZM4MvvEJ .

pareeohnos commented 7 years ago

no problem. In terms of heartbeats, I assume you mean the sending of them from the client side? Something that needs to be added at some point :)

rosacris commented 7 years ago

El jun. 6, 2017 6:30 PM, "pareeohnos" notifications@github.com escribió:

no problem. In terms of heartbeats, I assume you mean the sending of them from the client side?

Exactly, in our domain it is very important to detect if the connection with the broker was lost asap. We had an issue were the tcp connections were not being dropped but no stomp frames were being received.

Something that needs to be added at some point :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/manageplaces/Stompex/issues/5#issuecomment-306623262, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqjkmV_OyRFHW_0k4tOzP7lxqTnzhzvks5sBcUAgaJpZM4MvvEJ .

pareeohnos commented 7 years ago

ah ok, sorry about that. There's an open issue to add heartbeats that will hopefully be resolved at some point, but I didn't realise it was something that was needed by anyone at the time. Hopefully we can get this sorted for future users in a similar situation.

shymega commented 7 years ago

Hi Cristian,

Cristian Rosa notifications@github.com writes:

Hey, I'm sorry for the delay, we finally ended up scrapping out stomp and switched to mqtt, mainly for the lack of heartbeats (all Elixir/Erlang clients lacked either SSL or heartbeats). Tomorrow I'll create a test project with Stompex as a dep and try to connect.

I'm making a Elixir project that uses MQTT for communication (ACOM-XP project) between phones and the "router" - which library did you use for MQTT comms, if you used Elixir/Erlang?

(I'm really finding it hard to find a decent client for Elixir....)

Thanks!

-- Kind regards, Dom Rodriguez (shymega/dzr{_,})

"Freedom is the freedom to say two plus two make four. If that is granted, all else follows." -- George Orwell, Nineteen Eighty-Four.

shymega commented 7 years ago

Hi there,

pareeohnos notifications@github.com writes:

ah ok, sorry about that. There's an open issue to add heartbeats that will hopefully be resolved at some point, but I didn't realise it was something that was needed by anyone at the time.

I'm the person who opened issue #3 for adding STOMP heartbeats. I'm working on it, but I'm also studying at college for a qualification, so I'm juggling a lot of stuff around right now :smile:

My sincere apologies that it took this long for heartbeats in Stompex, however.

Hopefully we can get this sorted for future users in a similar situation.

Agreed. Perhaps we should make #3 more of a priority. I can increase the priority in my Taskwarrior list.

-- Kind regards, Dom Rodriguez (shymega/dzr{_,})

"Freedom is the freedom to say two plus two make four. If that is granted, all else follows." -- George Orwell, Nineteen Eighty-Four.

rosacris commented 7 years ago

Hi,

we are using https://github.com/emqtt/emqttc It's written in Erlang, but we use it from Elixir without any issues. We've taken a look at the code and it seems to very well designed/organized. @pareeohnos I'm sorry for advertising another project :S

Best Cristian

2017-06-08 3:58 GMT-03:00 Dom Rodriguez notifications@github.com:

Hi there,

pareeohnos notifications@github.com writes:

ah ok, sorry about that. There's an open issue to add heartbeats that will hopefully be resolved at some point, but I didn't realise it was something that was needed by anyone at the time.

I'm the person who opened issue #3 for adding STOMP heartbeats. I'm working on it, but I'm also studying at college for a qualification, so I'm juggling a lot of stuff around right now :smile:

My sincere apologies that it took this long for heartbeats in Stompex, however.

Hopefully we can get this sorted for future users in a similar situation.

Agreed. Perhaps we should make #3 more of a priority. I can increase the priority in my Taskwarrior list.

-- Kind regards, Dom Rodriguez (shymega/dzr{_,})

"Freedom is the freedom to say two plus two make four. If that is granted, all else follows." -- George Orwell, Nineteen Eighty-Four.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/manageplaces/Stompex/issues/5#issuecomment-307016626, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqjkmKYbRTRFPFCI_05mWiROVuMzHZgks5sB5uOgaJpZM4MvvEJ .

shymega commented 7 years ago

Hello,

Cristian Rosa notifications@github.com writes:

Hi,

we are using https://github.com/emqtt/emqttc It's written in Erlang, but we use it from Elixir without any issues. We've taken a look at the code and it seems to very well designed/organized.

Oh, I see. I've seen that, but I've never managed to get a client working. I found the docs to be a bit poor, IMHO.

@pareeohnos I'm sorry for advertising another project :S

Regarding this, I'm sure that will be OK. As this is a STOMP project, and that's a MQTT project, I don't think, personally, there's any issues here.

Thanks Cristian!

-- Kind regards, Dom Rodriguez (shymega/dzr{_,})

"Freedom is the freedom to say two plus two make four. If that is granted, all else follows." -- George Orwell, Nineteen Eighty-Four.

pareeohnos commented 7 years ago

@rosacris not to worry. As @shymega said, different project with different goals :)

rosacris commented 7 years ago

@shymega by the way, we also struggled at first trying to connect emqttc to the broker. The reason was that being an erlang library, it expects the host parameter to be a charlist and not an Elixir string (binary). i.e [host: to_charlist("mqtt.myserver.com")]

Hope that helps C

2017-06-08 13:22 GMT-03:00 pareeohnos notifications@github.com:

@rosacris https://github.com/rosacris not to worry. As @shymega https://github.com/shymega said, different project with different goals :)

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/manageplaces/Stompex/issues/5#issuecomment-307154758, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqjknVELql720Ps1bLjXiH28EGNrrAbks5sCB_GgaJpZM4MvvEJ .

shymega commented 7 years ago

@rosacris Yeah, I found that out pretty quickly. At the moment I'm using Emqttc in Erlang directly as an Erlang app, as I - for the life of me - can't figure out how to get a handle_info working.. :/

rosacris commented 7 years ago

https://gist.github.com/rosacris/9d693a4a604f218655261ebefcdf2437

that's what we have in production right now.

2017-06-08 15:42 GMT-03:00 Dom Rodriguez notifications@github.com:

@rosacris https://github.com/rosacris Yeah, I found that out pretty quickly. At the moment I'm using Emqttc in Erlang directly as an Erlang app, as I - for the life of me - can't figure out how to get a handle_info working.. :/

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/manageplaces/Stompex/issues/5#issuecomment-307192038, or mute the thread https://github.com/notifications/unsubscribe-auth/AAqjko5A6DsLq1ap_JWQJMxmjMmA-j1dks5sCECugaJpZM4MvvEJ .