Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add optional for setting name from client #129

Merged
merged 3 commits into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/nats-pub
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ msg ||= 'Hello World'

NATS.on_error { |err| puts "Server Error: #{err}"; exit! }

NATS.start(:uri => $nats_server, :autostart => true) do
NATS.start(:uri => $nats_server) do
NATS.publish(subject, msg) { NATS.stop }
end

Expand Down
2 changes: 1 addition & 1 deletion bin/nats-queue
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ end

NATS.on_error { |err| puts "Server Error: #{err}"; exit! }

NATS.start(:uri => $nats_server, :autostart => true) do
NATS.start(:uri => $nats_server) do
puts "Listening on [#{subject}], queue group [#{queue_group}]" unless $show_raw
NATS.subscribe(subject, :queue => queue_group) { |msg, _, sub|
puts decorate(sub, msg)
Expand Down
2 changes: 1 addition & 1 deletion bin/nats-request
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ end

NATS.on_error { |err| puts "Server Error: #{err}"; exit! }

NATS.start(:uri => $nats_server, :autostart => true) do
NATS.start(:uri => $nats_server) do
NATS.request(subject, msg) { |(msg, reply)|
puts decorate(msg)
exit! if $responses && ($responses-=1) < 1
Expand Down
2 changes: 1 addition & 1 deletion bin/nats-sub
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ end

NATS.on_error { |err| puts "Server Error: #{err}"; exit! }

NATS.start(:uri => $nats_server, :autostart => true) do
NATS.start(:uri => $nats_server) do
puts "Listening on [#{subject}]" unless $show_raw
NATS.subscribe(subject) { |msg, _, sub| puts decorate(sub, msg) }
end
1 change: 1 addition & 0 deletions lib/nats/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ def connect_command #:nodoc:
cs[:user] = @uri.user
cs[:pass] = @uri.password
end
cs[:name] = @options[:name] if @options[:name]
cs[:ssl_required] = @ssl if @ssl
cs[:tls_required] = true if @tls

Expand Down
8 changes: 8 additions & 0 deletions spec/client/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,14 @@ def c.send_ping
end
end

it 'should allowing setting name for the client on connect' do
with_em_timeout do
connect_command = "CONNECT {\"verbose\":false,\"pedantic\":false,\"lang\":\"ruby\",\"version\":\"#{NATS::VERSION}\",\"protocol\":1,\"name\":\"hello\"}\r\n"
conn = NATS.connect(:name => "hello")
expect(conn.connect_command).to eql(connect_command)
end
end

it 'should not repeat SUB commands when connecting' do
pending_commands = "CONNECT {\"verbose\":false,\"pedantic\":true,\"lang\":\"ruby\",\"version\":\"#{NATS::VERSION}\",\"protocol\":1}\r\n"
pending_commands += "PING\r\n"
Expand Down