-
Notifications
You must be signed in to change notification settings - Fork 131
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updates to TLS support in the client
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
Showing
20 changed files
with
1,113 additions
and
83 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
Oops, something went wrong.