yuce / teacup_nats

Teacup based NATS client for Erlang
Apache License 2.0
17 stars 9 forks source link

How to pass username and password? #15

Closed wwhai closed 3 years ago

wwhai commented 3 years ago

I cant't find username and password args:

 {ok, Conn} = nats:connect(<<"demo.nats.io">>, 4222, #{buffer_size => 10}),

How to pass username and password?

yuce commented 3 years ago

Can you try #{user => "USER", pass => "PASS"}? Supported options are here: https://github.com/yuce/teacup_nats#aysnchronous-connection

wwhai commented 3 years ago

Can you try #{user => "USER", pass => "PASS"}? Supported options are here: https://github.com/yuce/teacup_nats#aysnchronous-connection

Thanks,I Found it:

Connection functions:
nats:connect(): Connect to the NATS server at address 127.0.0.1, port 4222,
nats:connect(Host :: binary(), Port :: integer()): Connect to the NATS server at Host and port PORT,
nats:connect(Host :: binary(), Port :: integer(), Opts :: map()): Similar to above, but also takes an Opts map. Currently usable keys:
verbose => true | false: If verbose == true, NATS server sends an acknowledgement message on pub, sub, unsub operations and connect operation becomes synchronous.
user => User :: binary(),
pass => Password :: binary(),
buffer_size => MessageBufferSize :: non_neg_integer(): The number of publish messages to buffer before quitting. The default is 0. Setting MesssageBufferSize to infinity enables unlimited buffering.
reconnect => {Interval :: non_neg_integer(), MaxRetry :: non_neg_integer()}: Specifies reconnect strategy. Interval is the time in milliseconds between retrials, and MaxRetry is the number of retrials before quitting. You can set MaxRetry to infinity to try reconnecting forever. The default is {undefined, 0}, "don't try to reconnect".