The virtues of the NATS protocol manifest quickly when you experience how easy it is to use NATS. Because the NATS protocol is text-based, you can use NATS across virtually any platform or language. In the following demo we use Telnet.
Trying 107.170.221.32...
Connected to demo.nats.io.
Escape character is '^]'.
INFO {"server_id":"NCXMJZYQEWUDJFLYLSTTE745I2WUNCVG3LJJ3NRKSFJXEG6RGK7753DJ","version":"2.0.0","proto":1,"go":"go1.11.10","host":"0.0.0.0","port":4222,"max_payload":1048576,"client_id":5089}
3. Run the subscriber.
Subscribe to the wildcard subject foo.* with subject ID of 90.
The message includes the command (pub), subject (foo.bar), and length of the payload (5). Press enter and provide the payload (hello), then press enter again.
You can use the UNSUB command to unsubscribe from a message.
Run the subscriber to unsubscribe:
Subscriber result: +OK indicating successful deregistration of interest.
9. Reconnect to server and subscribe.
10. Explore the ping/pong interval.
If you leave your telnet session open for a few minutes, you may notice that your clients receives ping requests from the server. If your client is not active, or does not respond to the server pings within the ping/pong interval, the server disconnects the client. The error message is -ERR 'Stale Connection'.
You can send a ping request to the serve and receive a PONG reply. For example:
Trying 107.170.221.32...
Connected to demo.nats.io.
Escape character is '^]'.
INFO {"server_id":"NCXMJZYQEWUDJFLYLSTTE745I2WUNCVG3LJJ3NRKSFJXEG6RGK7753DJ","version":"2.0.0","proto":1,"go":"go1.11.10","host":"0.0.0.0","port":4222,"max_payload":1048576,"client_id":5089}
pub foo.bar 5
hello
pub foo.bar 5
hello
+OK
sub foo.* 90
+OK
MSG foo.bar 90 5
hello
pub foo.bar optional.reply.subject 5
hello
+OK
MSG foo.bar 90 optional.reply.subject 5
hello
unsub 90
unsub 90
+OK
telnet demo.nats.io 4222
sub foo.* 90
Connected to demo.nats.io.
Escape character is '^]'.
INFO {"server_id":"NCXMJZYQEWUDJFLYLSTTE745I2WUNCVG3LJJ3NRKSFJXEG6RGK7753DJ","version":"2.0.0","proto":1,"go":"go1.11.10","host":"0.0.0.0","port":4222,"max_payload":1048576,"client_id":5089}
ping
PONG