Skip to content

Commit

Permalink
Updates to TLS support in the client
Browse files Browse the repository at this point in the history
Adds disconnect, close and reconnect attempt callbacks
which have been adopted in other clients.

Update NATS server used for testing to 0.8.1
  • Loading branch information
Waldemar Quevedo committed Jun 30, 2016
1 parent 2535f94 commit 56b68d1
Show file tree
Hide file tree
Showing 20 changed files with 1,113 additions and 83 deletions.
8 changes: 5 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ rvm:
- 2.2
- 2.3.0

cache:
directories:
- $HOME/gnatsd
# cache:
# directories:
# - $HOME/gnatsd

before_install:
- bash ./scripts/install_gnatsd.sh

before_script:
- export PATH=$HOME/gnatsd:$PATH

sudo: required
dist: trusty
2 changes: 1 addition & 1 deletion Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
PATH
remote: .
specs:
nats (0.6.0)
nats (0.7.0)
daemons (~> 1.1, >= 1.2.2)
eventmachine (~> 1.2, >= 1.2.0)
json_pure (~> 1.8, >= 1.8.1)
Expand Down
54 changes: 54 additions & 0 deletions examples/tls.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
require 'nats/client'

EM.run do
# Set default callbacks
NATS.on_error do |e|
# next if e.kind_of?(NATS::ConnectError)
puts "#{Time.now.to_f } - Error: #{e}"
end

NATS.on_disconnect do
puts "#{Time.now.to_f} - Disconnected from NATS"
end

NATS.on_reconnect do
puts "#{Time.now.to_f} - Reconnected to NATS"
end

NATS.on_close do
puts "#{Time.now.to_f} - Connection to NATS closed"
EM.stop
end

options = {
:servers => [
'nats://secret:deadbeef@127.0.0.1:4443',
'nats://secret:deadbeef@127.0.0.1:4444'
],
:max_reconnect_attempts => 3,
:reconnect_time_wait => 2,
:tls => {
:ssl_version => :TLSv1_2,
:protocols => [:tlsv1_2],
:private_key_file => './spec/configs/certs/key.pem',
:cert_chain_file => './spec/configs/certs/server.pem',
:verify_peer => false
}
}

nc = NATS.connect(options) do
puts "#{Time.now.to_f} - Connected to NATS"
end
messages = []
sid = nc.subscribe("hello") do |msg|
puts "Received: #{msg}"
end
nc.flush do
nc.publish("hello", "world") do
nc.unsubscribe(sid)
nc.flush do
nc.close
end
end
end
end
Loading

0 comments on commit 56b68d1

Please sign in to comment.