Nats.io
Column 1 # Creates a new Stream based on the config of another, does not copy data nats stream copy ORDERS ARCHIVE --description "Orders Archive" --subjects ARCHIVE # To publish 100 messages with a random body between 100 and 1000 characters nats pub destination.subject "{{ Random 100 1000 }}" -H Count:{{ Count }} --count 100 # To publish messages from STDIN echo "hello world" | nats pub destination.subject # To publish messages from STDIN in a headless (non-tty) context echo "hello world" | nats pub --force-stdin destination.subject # To subscribe to messages, in a queue group and acknowledge any JetStream ones nats sub source.subject --queue work --ack # To subscribe to a randomly generated inbox nats sub --inbox # To dump all messages to files, 1 file per message nats sub --inbox --dump /tmp/archive # To process all messages using xargs 1 message at a time through a shell command nats sub subject --dump=- | xargs -0 -n 1 -I "{}" sh -c "echo '{}' | wc -c" # To receive new messages received in a stream with the subject ORDERS.new nats sub ORDERS.new --next # To report the number of subjects with message and byte count. The default `--report-top` is 10 nats sub ">" --report-subjects --report-top=20 # To base64 decode message bodies before rendering them nats sub 'encoded.sub' --translate "base64 -d" # To request a response from a server and show just the raw result nats request destination.subject "hello world" -H "Content-type:text/plain" --raw #REPLY # To set up a responder that runs an external command with the 3rd subject token as argument nats reply "service.requests.>" --command "service.sh {{2}}" # To set up basic responder nats reply service.requests "Message {{Count}} @ {{Time}}" nats reply service.requests --echo --sleep 10 Column 2 # Backup and restore nats stream backup ORDERS backups/orders/$(date +%Y-%m-%d) nats stream restore ORDERS backups/orders/$(date +%Y-%m-%d) # Page through a stream nats stream view ORDERS nats stream view --id 1000 nats stream view --since 1h nats stream view --subject one.subject # Purge messages from streams nats stream purge ORDERS # deletes up to, but not including, 1000 nats stream purge ORDERS --seq 1000 nats stream purge ORDERS --keep 100 nats stream purge ORDERS --subject one.subject # Get message 12344, delete a message, delete all messages nats stream get ORDERS 12345 nats stream rmm ORDERS 12345 # Show a list of streams, including basic info or compatible with pipes nats stream list nats stream list -n
# Find all empty streams or streams with messages nats stream find --empty nats stream find --empty --invert # Editing a single property of a stream nats stream edit STREAMNAME --description "new description." # Editing a stream configuration in your editor EDITOR=vi nats stream edit -i STREAMNAME # Adding, Removing, Viewing a Stream nats stream add nats stream info STREAMNAME nats stream rm STREAMNAME Column 3 # Marks a stream as read only nats stream seal ORDERS # Force a cluster leader election nats stream cluster ORDERS down # Evict the stream from a node stream cluster peer-remove ORDERS nats1.example.net # Create or update nats context add development --server nats.dev.example.net:4222 [other standard connection properties] nats context add ngs --description "NGS Connection in Orders Account" --nsc nsc://acme/orders/new nats context edit development [standard connection properties] # View contexts nats context ls nats context info development --json # Validate all connections are valid and that connections can be established nats context validate --connect # Select a new default context nats context select Inbox feature for guaranteed message delivery The inbox feature in Nats.io ensures that messages are delivered even if the subscriber is temporarily offline. This guarantees reliable and persistent messaging regardless of network connectivity. When a subscriber comes back online, it will receive any missed messages from its subscribed channels or subjects automatically. The inbox functionality provides seamless communication between publishers and subscribers, enabling robust message exchange. Acknowledgement modes Nats.io supports two acknowledgement modes: explicit acks or auto-acks based on client preferences. In explicit ack mode, the message receiver must explicitly acknowledge each received message to inform the server that it has been successfully processed. On the other hand, in auto-ack mode, messages are automatically acknowledged by Nats.io without requiring any action from the client. The choice of acknowledgement mode depends on factors such as reliability requirements and desired level of control over message processing. |