Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,21 +20,29 @@ Simple NATS client for the [Crystal](https://crystal-lang.org) programming langu
## Usage

```crystal
require "nats"
require "nats/client"

nc = NATS::Connection.new("demo.nats.io")
nc.subscribe("foo") { |msg| puts "Received '#{msg}'"}
nc.publish("foo", "Hello!")
client = NATS::Client.new("nats://localhost:4222")
client.connect

sub = nc.subscribe("req") do |msg|
msg.respond("ANSWER is 42")
client.subscribe("foo") do |msg|
puts "Received message on subject #{msg.subject}: #{msg.payload}"
end

answer = nc.request("req", "Help!")
puts "Received a response '#{answer}'!"
client.publish("foo", "Hello, NATS!")

sub.close
nc.close
client.subscribe("bar") do |msg|
msg.reply "Received your message on bar: #{msg.payload}"
end

response = client.request("bar", "Hello, bar!")
puts "Received response: #{response.payload}"

client.request("bar") do |msg|
puts "Recieved async response: #{msg.payload}"
end

client.close
```

## License
Expand Down
13 changes: 5 additions & 8 deletions TODO
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
1. auto-unsub, max messages
2. Multiple URLs/Servers
3. Reconnect logic
4. Async INFO processing
5. Multiple servers, state logic CONNECTED/RECONNECTING/DISCONNECTED/CLOSED
6. msgs/bytes stats for connections and subscriptions
7. async request?
8. NATS 2.0 security/auth
1. Reconnect logic
2. Handle multiple servers
3. State change callbacks
4. auto-unsub, max messages (https://docs.nats.io/using-nats/developer/receiving/unsub_after)
5. msgs/bytes stats for connections and subscriptions
44 changes: 0 additions & 44 deletions bin/nats-pub.cr

This file was deleted.

41 changes: 0 additions & 41 deletions bin/nats-req.cr

This file was deleted.

57 changes: 0 additions & 57 deletions bin/nats-sub.cr

This file was deleted.

192 changes: 192 additions & 0 deletions docs/404.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,192 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="generator" content="Crystal Docs 1.15.1">
<meta name="crystal_docs.project_version" content="main-dev">
<meta name="crystal_docs.project_name" content="nats">



<link href="css/style.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="js/doc.js"></script>

<meta name="repository-name" content="nats">
<title>nats main-dev</title>
<script type="text/javascript">
CrystalDocs.base_path = "";
</script>
</head>
<body>

<svg class="hidden">
<symbol id="octicon-link" viewBox="0 0 16 16">
<path fill="currentColor" fill-rule="evenodd" d="M4 9h1v1H4c-1.5 0-3-1.69-3-3.5S2.55 3 4 3h4c1.45 0 3 1.69 3 3.5 0 1.41-.91 2.72-2 3.25V8.59c.58-.45 1-1.27 1-2.09C10 5.22 8.98 4 8 4H4c-.98 0-2 1.22-2 2.5S3 9 4 9zm9-3h-1v1h1c1 0 2 1.22 2 2.5S13.98 12 13 12H9c-.98 0-2-1.22-2-2.5 0-.83.42-1.64 1-2.09V6.25c-1.09.53-2 1.84-2 3.25C6 11.31 7.55 13 9 13h4c1.45 0 3-1.69 3-3.5S14.5 6 13 6z"></path>
</symbol>
</svg>
<input type="checkbox" id="sidebar-btn">
<label for="sidebar-btn" id="sidebar-btn-label">
<svg class="open" xmlns="http://www.w3.org/2000/svg" height="2em" width="2em" viewBox="0 0 512 512"><title>Open Sidebar</title><path fill="currentColor" d="M80 96v64h352V96H80zm0 112v64h352v-64H80zm0 112v64h352v-64H80z"></path></svg>
<svg class="close" xmlns="http://www.w3.org/2000/svg" width="2em" height="2em" viewBox="0 0 512 512"><title>Close Sidebar</title><path fill="currentColor" d="m118.6 73.4-45.2 45.2L210.7 256 73.4 393.4l45.2 45.2L256 301.3l137.4 137.3 45.2-45.2L301.3 256l137.3-137.4-45.2-45.2L256 210.7Z"></path></svg>
</label>
<div class="sidebar">
<div class="sidebar-header">
<div class="search-box">
<input type="search" class="search-input" placeholder="Search..." spellcheck="false" aria-label="Search">
</div>

<div class="project-summary">
<h1 class="project-name">
<a href="index.html">
nats
</a>
</h1>

<span class="project-version">
main-dev
</span>
</div>
</div>

<div class="search-results hidden">
<ul class="search-list"></ul>
</div>

<div class="types-list">
<ul>

<li class="parent " data-id="nats/NATS" data-name="nats">
<a href="NATS.html">NATS</a>

<ul>

<li class=" " data-id="nats/NATS/AuthenticationError" data-name="nats::authenticationerror">
<a href="NATS/AuthenticationError.html">AuthenticationError</a>

</li>

<li class="parent " data-id="nats/NATS/Client" data-name="nats::client">
<a href="NATS/Client.html">Client</a>

<ul>

<li class=" " data-id="nats/NATS/Client/Status" data-name="nats::client::status">
<a href="NATS/Client/Status.html">Status</a>

</li>

</ul>


</li>

<li class=" " data-id="nats/NATS/ClientClosedError" data-name="nats::clientclosederror">
<a href="NATS/ClientClosedError.html">ClientClosedError</a>

</li>

<li class=" " data-id="nats/NATS/ERRError" data-name="nats::errerror">
<a href="NATS/ERRError.html">ERRError</a>

</li>

<li class=" " data-id="nats/NATS/Error" data-name="nats::error">
<a href="NATS/Error.html">Error</a>

</li>

<li class="parent " data-id="nats/NATS/Message" data-name="nats::message">
<a href="NATS/Message.html">Message</a>

<ul>

<li class=" " data-id="nats/NATS/Message/CONNECT" data-name="nats::message::connect">
<a href="NATS/Message/CONNECT.html">CONNECT</a>

</li>

<li class=" " data-id="nats/NATS/Message/INFO" data-name="nats::message::info">
<a href="NATS/Message/INFO.html">INFO</a>

</li>

<li class=" " data-id="nats/NATS/Message/MSG" data-name="nats::message::msg">
<a href="NATS/Message/MSG.html">MSG</a>

</li>

<li class=" " data-id="nats/NATS/Message/PUB" data-name="nats::message::pub">
<a href="NATS/Message/PUB.html">PUB</a>

</li>

<li class=" " data-id="nats/NATS/Message/SUB" data-name="nats::message::sub">
<a href="NATS/Message/SUB.html">SUB</a>

</li>

<li class=" " data-id="nats/NATS/Message/UNSUB" data-name="nats::message::unsub">
<a href="NATS/Message/UNSUB.html">UNSUB</a>

</li>

</ul>


</li>

<li class=" " data-id="nats/NATS/MSGError" data-name="nats::msgerror">
<a href="NATS/MSGError.html">MSGError</a>

</li>

<li class=" " data-id="nats/NATS/NUID" data-name="nats::nuid">
<a href="NATS/NUID.html">NUID</a>

</li>

<li class=" " data-id="nats/NATS/Options" data-name="nats::options">
<a href="NATS/Options.html">Options</a>

</li>

<li class=" " data-id="nats/NATS/Subscription" data-name="nats::subscription">
<a href="NATS/Subscription.html">Subscription</a>

</li>

<li class=" " data-id="nats/NATS/TimeoutError" data-name="nats::timeouterror">
<a href="NATS/TimeoutError.html">TimeoutError</a>

</li>

</ul>


</li>

</ul>

</div>
</div>


<div class="main-content">
<h1 class="type-name">
404 Not Found
</h1>

<p>
This page is unavailable in this version of the API docs.
</p>

<p>
You can use the sidebar to search for your page, or try a different
Crystal version.
</p>

</div>
</body>
</html>
Loading