Clients
最后更新于
这有帮助吗?
最后更新于
这有帮助吗?
The nats-server doesn't come bundled with any clients. But most client libraries come with sample programs that allow you to publish, subscribe, send requests and reply messages.
If you have a client library installed, you can try using a bundled client. Otherwise, you can easily install some clients.
You can install pre-built binaries from the
Open a terminal and :
On another terminal session start a subscriber:
Note that when the client connected, the server didn't log anything interesting because server output is relatively quiet unless something interesting happens.
To make the server output more lively, you can specify the -V
flag to enable logging of server protocol tracing messages. Go ahead and <ctrl>+c
the process running the server, and restart the server with the -V
flag:
If you had created a subscriber, you should notice output on the subscriber telling you that it disconnected, and reconnected. The server output above is more interesting. You can see the subscriber send a CONNECT
protocol message and a PING
which was responded to by the server with a PONG
.
On a third terminal, publish your first message:
On the subscriber window you should see:
If the NATS server were running in a different machine or a different port, you'd have to specify that to the client by specifying a NATS URL. NATS URLs take the form of: nats://<server>:<port>
and tls://<server>:<port>
. URLs with a tls
protocol sport a secured TLS connection.
If you want to try on a remote server, the NATS team maintains a demo server you can reach at demo.nats.io
.
You can learn more about the , but more interesting than the protocol description is .