Packages
gnat
1.9.1
1.16.0
1.15.2
1.15.1
1.15.0
1.14.1
1.14.0
1.14.0-rc1
1.14.0-rc0
1.13.1
1.13.0
1.12.1
1.12.0
1.11.1
1.11.0
1.10.2
1.10.2-rc1
1.10.2-rc0
1.10.1
1.10.0
1.9.1
1.9.0
1.8.5
1.8.4
1.8.3
1.8.2
1.8.1
1.7.1
1.7.0
1.6.0
1.5.2
1.5.1
1.5.0
1.4.0
1.3.0
1.3.0-rc0
1.2.1
1.2.0
1.1.3
1.1.2
1.1.1
1.1.0
1.0.1
1.0.0
0.7.0
0.6.1
0.6.0
0.5.5
0.5.4
0.5.3
0.5.2
0.5.1
0.5.0
0.4.2
0.4.1
0.4.0
0.3.4
0.3.3
0.3.2
0.3.1
0.3.0
0.2.0
0.1.3
0.1.2
0.1.1
0.1.0
A nats client in pure elixir. Resilience, Performance, Ease-of-Use.
Current section
Files
Jump to
Current section
Files
lib/gnat/command.ex
defmodule Gnat.Command do
@moduledoc false
@newline "\r\n"
@hpub "HPUB"
@pub "PUB"
@sub "SUB"
@unsub "UNSUB"
def build(:pub, topic, payload, []), do: [@pub, " ", topic, " #{IO.iodata_length(payload)}", @newline, payload, @newline]
def build(:pub, topic, payload, [reply_to: reply]), do: [@pub, " ", topic, " ", reply, " #{IO.iodata_length(payload)}", @newline, payload, @newline]
def build(:pub, topic, payload, [headers: headers]) do
# it takes 10 bytes to add the nats header version line
# and 2 more for the newline between headers and payload
header_len = IO.iodata_length(headers) + 12
total_len = IO.iodata_length(payload) + header_len
[@hpub, " ", topic, " ", Integer.to_string(header_len), " ", Integer.to_string(total_len), "\r\nNATS/1.0\r\n", headers, @newline, payload, @newline]
end
def build(:pub, topic, payload, [headers: headers, reply_to: reply]) do
# it takes 10 bytes to add the nats header version line
# and 2 more for the newline between headers and payload
header_len = IO.iodata_length(headers) + 12
total_len = IO.iodata_length(payload) + header_len
[@hpub, " ", topic, " ", reply, " ", Integer.to_string(header_len), " ", Integer.to_string(total_len), "\r\nNATS/1.0\r\n", headers, @newline, payload, @newline]
end
def build(:sub, topic, sid, []), do: [@sub, " ", topic, " ", Integer.to_string(sid), @newline]
def build(:sub, topic, sid, [queue_group: qg]), do: [@sub, " ", topic, " ", qg, " ", Integer.to_string(sid), @newline]
def build(:unsub, sid, []), do: [@unsub, " #{sid}", @newline]
def build(:unsub, sid, [max_messages: max]), do: [@unsub, " #{sid}", " #{max}", @newline]
end