mirror of
https://github.com/taigrr/nats.docs
synced 2025-01-18 04:03:23 -08:00
Cleaned up how examples are handled to reduce thrashing in git
Examples are no longer in the final html as solo files, only in their container file
This commit is contained in:
parent
e8e306c8a8
commit
57db99feba
@ -1,5 +1,6 @@
|
|||||||
|
|
||||||
_book/
|
_book/
|
||||||
|
_examples/
|
||||||
tools/
|
tools/
|
||||||
|
|
||||||
Makefile
|
Makefile
|
||||||
|
2
Makefile
2
Makefile
@ -8,4 +8,4 @@ serve:
|
|||||||
gitbook serve
|
gitbook serve
|
||||||
|
|
||||||
examples:
|
examples:
|
||||||
go run tools/examplecompiler/main.go -o developer/examples -r tools/examplecompiler/example_repos.json -t tools/examplecompiler/example_template.tmp
|
go run tools/examplecompiler/main.go -o _examples -r tools/examplecompiler/example_repos.json -t tools/examplecompiler/example_template.tmp
|
||||||
|
@ -1,24 +1,24 @@
|
|||||||
# Connecting to NATS
|
# Connecting to NATS
|
||||||
|
|
||||||
Most client libraries provide several ways to connect to the NATS server, gnatsd. The server itself is identified by a standard URL with the `nats` protocol. Throughout these examples we will rely on a test server, provided by [nats.io](https://nats.io), at `nats://demo.nats.io:4222`, where `4222` is the default port for NATS.
|
Most client libraries provide several ways to connect to the NATS server, gnatsd. The server itself is identified by a standard URL with the `nats` protocol. Throughout these ../_examples we will rely on a test server, provided by [nats.io](https://nats.io), at `nats://demo.nats.io:4222`, where `4222` is the default port for NATS.
|
||||||
|
|
||||||
## Connecting to a Specific Server
|
## Connecting to a Specific Server
|
||||||
|
|
||||||
For example, to connect to the demo server with a URL:
|
For example, to connect to the demo server with a URL:
|
||||||
|
|
||||||
!INCLUDE "examples/connect_url.html"
|
!INCLUDE "../_examples/connect_url.html"
|
||||||
|
|
||||||
## Connecting to the Default Server
|
## Connecting to the Default Server
|
||||||
|
|
||||||
Some libraries also provide a special way to connect to a *default* url, which is general `nats://localhost:4222`:
|
Some libraries also provide a special way to connect to a *default* url, which is general `nats://localhost:4222`:
|
||||||
|
|
||||||
!INCLUDE "examples/connect_default.html"
|
!INCLUDE "../_examples/connect_default.html"
|
||||||
|
|
||||||
## Setting a Connect Timeout
|
## Setting a Connect Timeout
|
||||||
|
|
||||||
Each library has its own, language preferred way, to pass connection options. For example, to set the maximum time to connect to a server to 10 seconds:
|
Each library has its own, language preferred way, to pass connection options. For example, to set the maximum time to connect to a server to 10 seconds:
|
||||||
|
|
||||||
!INCLUDE "examples/connect_options.html"
|
!INCLUDE "../_examples/connect_options.html"
|
||||||
|
|
||||||
The available options are discussed more below, in other pages, and in the documentation for your client library.
|
The available options are discussed more below, in other pages, and in the documentation for your client library.
|
||||||
|
|
||||||
@ -33,7 +33,7 @@ When connecting to a cluster, there are a few things to think about.
|
|||||||
|
|
||||||
When a client connects to the server, the server may provide a list of URLs for additional known servers. This allows a client to connect to one server and still have other servers available during reconnect. However, the initial connection cannot depend on these additional servers. Rather, the additional connection will try to connect to each of the URLs provided in the connect call and will fail if it is unable to connect to any of them. *Note, failure behavior is library dependent, please check the documentation for your client library on information about what happens if the connect fails.*
|
When a client connects to the server, the server may provide a list of URLs for additional known servers. This allows a client to connect to one server and still have other servers available during reconnect. However, the initial connection cannot depend on these additional servers. Rather, the additional connection will try to connect to each of the URLs provided in the connect call and will fail if it is unable to connect to any of them. *Note, failure behavior is library dependent, please check the documentation for your client library on information about what happens if the connect fails.*
|
||||||
|
|
||||||
!INCLUDE "examples/connect_multiple.html"
|
!INCLUDE "../_examples/connect_multiple.html"
|
||||||
|
|
||||||
## Reconnecting
|
## Reconnecting
|
||||||
|
|
||||||
@ -43,37 +43,37 @@ Most, if not all, of the client libraries will reconnect to the server if they a
|
|||||||
|
|
||||||
For example, you can disable reconnect:
|
For example, you can disable reconnect:
|
||||||
|
|
||||||
!INCLUDE "examples/reconnect_none.html"
|
!INCLUDE "../_examples/reconnect_none.html"
|
||||||
|
|
||||||
### Set the Number of Reconnect Attempts
|
### Set the Number of Reconnect Attempts
|
||||||
|
|
||||||
Applications can set the maximum reconnect attempts. Generally, this will limit the actual number of attempts total, but check your library documentation. For example, in Java, if the client knows about 3 servers and the maximum reconnects is set to 2, it will not try all of the servers. On the other hand, if the maximum is set to 6 it will try all of the servers twice before considering the reconnect a failure and closing.
|
Applications can set the maximum reconnect attempts. Generally, this will limit the actual number of attempts total, but check your library documentation. For example, in Java, if the client knows about 3 servers and the maximum reconnects is set to 2, it will not try all of the servers. On the other hand, if the maximum is set to 6 it will try all of the servers twice before considering the reconnect a failure and closing.
|
||||||
|
|
||||||
!INCLUDE "examples/reconnect_10x.html"
|
!INCLUDE "../_examples/reconnect_10x.html"
|
||||||
|
|
||||||
### Pausing Between Reconnect Attempts
|
### Pausing Between Reconnect Attempts
|
||||||
|
|
||||||
It doesn’t make much sense to try to connect to the same server over and over. To prevent this sort of thrashing, and wasted reconnect attempts, libraries provide a wait setting. This setting will pause the reconnect logic if the same server is being tried multiple times. In the previous example, if you have 3 servers and 6 attempts, the Java library would loop over the three servers. If none were connectable, it will then try all three again. However, the Java client doesn’t wait between each attempt, only when trying the same server again, so in that example the library may never wait. If on the other hand, you only provide a single server URL and 6 attempts, the library will wait between each attempt.
|
It doesn’t make much sense to try to connect to the same server over and over. To prevent this sort of thrashing, and wasted reconnect attempts, libraries provide a wait setting. This setting will pause the reconnect logic if the same server is being tried multiple times. In the previous example, if you have 3 servers and 6 attempts, the Java library would loop over the three servers. If none were connectable, it will then try all three again. However, the Java client doesn’t wait between each attempt, only when trying the same server again, so in that example the library may never wait. If on the other hand, you only provide a single server URL and 6 attempts, the library will wait between each attempt.
|
||||||
|
|
||||||
!INCLUDE "examples/reconnect_10s.html"
|
!INCLUDE "../_examples/reconnect_10s.html"
|
||||||
|
|
||||||
### Avoiding the Thundering Herd
|
### Avoiding the Thundering Herd
|
||||||
|
|
||||||
When a server goes down, there is a possible anti-pattern called the *Thundering Herd* where all of the clients try to reconnect immediately creating a denial of service attack. In order to prevent this, most NATS client libraries randomize the servers they attempt to connect to. This setting has no effect if only a single server is used, but in the case of a cluster, randomization, or shuffling, will ensure that no one server bears the brunt of the client reconnect attempts.
|
When a server goes down, there is a possible anti-pattern called the *Thundering Herd* where all of the clients try to reconnect immediately creating a denial of service attack. In order to prevent this, most NATS client libraries randomize the servers they attempt to connect to. This setting has no effect if only a single server is used, but in the case of a cluster, randomization, or shuffling, will ensure that no one server bears the brunt of the client reconnect attempts.
|
||||||
|
|
||||||
!INCLUDE "examples/reconnect_no_random.html"
|
!INCLUDE "../_examples/reconnect_no_random.html"
|
||||||
|
|
||||||
### Listening for Reconnect Events
|
### Listening for Reconnect Events
|
||||||
|
|
||||||
Because reconnect is primarily under the covers many libraries provide an event listener you can use to be notified of reconnect events. This event can be especially important for applications sending a lot of messages.
|
Because reconnect is primarily under the covers many libraries provide an event listener you can use to be notified of reconnect events. This event can be especially important for applications sending a lot of messages.
|
||||||
|
|
||||||
!INCLUDE "examples/reconnect_event.html"
|
!INCLUDE "../_examples/reconnect_event.html"
|
||||||
|
|
||||||
|
|
||||||
### Buffering Messages During Reconnect Attempts
|
### Buffering Messages During Reconnect Attempts
|
||||||
|
|
||||||
There is another setting that comes in to play during reconnection. This setting controls how much memory the client library will hold in the form of outgoing messages while it is disconnected. During a short reconnect, the client will generally allow applications to publish messages but because the server is offline, will be cached in the client. The library will then send those messages on reconnect. When the maximum reconnect buffer is reached, messages will no longer be publishable by the client.
|
There is another setting that comes in to play during reconnection. This setting controls how much memory the client library will hold in the form of outgoing messages while it is disconnected. During a short reconnect, the client will generally allow applications to publish messages but because the server is offline, will be cached in the client. The library will then send those messages on reconnect. When the maximum reconnect buffer is reached, messages will no longer be publishable by the client.
|
||||||
|
|
||||||
!INCLUDE "examples/reconnect_5mb.html"
|
!INCLUDE "../_examples/reconnect_5mb.html"
|
||||||
|
|
||||||
> *As mentioned throughout this document, each client library may behave slightly differently. Please check the documentation for the library you are using.*
|
> *As mentioned throughout this document, each client library may behave slightly differently. Please check the documentation for the library you are using.*
|
@ -4,11 +4,11 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||||
<title>Connecting · GitBook</title>
|
<title>Connecting · NATS</title>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="generator" content="GitBook 3.2.3">
|
<meta name="generator" content="GitBook 3.2.3">
|
||||||
|
<meta name="author" content="The NATS Maintainers">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -240,7 +240,7 @@
|
|||||||
<section class="normal markdown-section">
|
<section class="normal markdown-section">
|
||||||
|
|
||||||
<h1 id="connecting-to-nats">Connecting to NATS</h1>
|
<h1 id="connecting-to-nats">Connecting to NATS</h1>
|
||||||
<p>Most client libraries provide several ways to connect to the NATS server, gnatsd. The server itself is identified by a standard URL with the <code>nats</code> protocol. Throughout these examples we will rely on a test server, provided by <a href="https://nats.io" target="_blank">nats.io</a>, at <code>nats://demo.nats.io:4222</code>, where <code>4222</code> is the default port for NATS. </p>
|
<p>Most client libraries provide several ways to connect to the NATS server, gnatsd. The server itself is identified by a standard URL with the <code>nats</code> protocol. Throughout these ../_examples we will rely on a test server, provided by <a href="https://nats.io" target="_blank">nats.io</a>, at <code>nats://demo.nats.io:4222</code>, where <code>4222</code> is the default port for NATS. </p>
|
||||||
<h2 id="connecting-to-a-specific-server">Connecting to a Specific Server</h2>
|
<h2 id="connecting-to-a-specific-server">Connecting to a Specific Server</h2>
|
||||||
<p>For example, to connect to the demo server with a URL:</p>
|
<p>For example, to connect to the demo server with a URL:</p>
|
||||||
<div class="tab-wrap">
|
<div class="tab-wrap">
|
||||||
@ -1421,7 +1421,7 @@ nc<span class="token punctuation">.</span><span class="token function">close</sp
|
|||||||
<script>
|
<script>
|
||||||
var gitbook = gitbook || [];
|
var gitbook = gitbook || [];
|
||||||
gitbook.push(function() {
|
gitbook.push(function() {
|
||||||
gitbook.page.hasChanged({"page":{"title":"Connecting","level":"1.3.1","depth":2,"previous":{"title":"Developing with NATS","level":"1.3","depth":1,"path":"developer/README.md","ref":"developer/README.md","articles":[{"title":"Connecting","level":"1.3.1","depth":2,"path":"developer/connecting.md","ref":"developer/connecting.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["prism","-highlight","include-html"],"pluginsConfig":{"prism":{},"include-html":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"developer/connecting.md","mtime":"2019-05-14T20:24:14.369Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-15T17:32:34.308Z"},"basePath":"..","book":{"language":""}});
|
gitbook.page.hasChanged({"page":{"title":"Connecting","level":"1.3.1","depth":2,"previous":{"title":"Developing with NATS","level":"1.3","depth":1,"path":"developer/README.md","ref":"developer/README.md","articles":[{"title":"Connecting","level":"1.3.1","depth":2,"path":"developer/connecting.md","ref":"developer/connecting.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["prism","-highlight","include-html"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{},"include-html":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"The NATS Maintainers","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"NATS","gitbook":"*","description":"Administrative, developer and conceptual documentation for the NATS messaging system."},"file":{"path":"developer/connecting.md","mtime":"2019-05-15T17:40:53.874Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-15T17:41:03.846Z"},"basePath":"..","book":{"language":""}});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
@ -1,115 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_default_go" name="connect_default" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_default_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_default_java" name="connect_default" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_default_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_default_js" name="connect_default" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_default_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_default_py" name="connect_default" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_default_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_default_ruby" name="connect_default" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_default_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_default_ts" name="connect_default" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_default_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_default_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_default/main.go#L10-19"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect(nats.DefaultURL)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_default_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectToDefaultServer.java#L10-16"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect();
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_default_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/connection_samples.js#L22-33"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect();
|
|
||||||
nc.on('connect', (c) => {
|
|
||||||
// Do something with the connection
|
|
||||||
doSomething();
|
|
||||||
// When done close it
|
|
||||||
nc.close();
|
|
||||||
});
|
|
||||||
nc.on('error', (err) => {
|
|
||||||
failed(err);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_default_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_default.py#L5-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
await nc.connect()
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_default_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_default.rb#L1-10"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start do |nc|
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
# Close the connection
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_default_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/connection_samples.ts#L16-34"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect();
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
// When done close it
|
|
||||||
nc.close();
|
|
||||||
|
|
||||||
|
|
||||||
// alternatively, you can use the Promise pattern
|
|
||||||
let nc1: Client;
|
|
||||||
connect()
|
|
||||||
.then((c) => {
|
|
||||||
nc1 = c;
|
|
||||||
// Do something with the connection
|
|
||||||
nc1.close();
|
|
||||||
});
|
|
||||||
// add a .catch/.finally
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,129 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_multiple_go" name="connect_multiple" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_multiple_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_multiple_java" name="connect_multiple" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_multiple_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_multiple_js" name="connect_multiple" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_multiple_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_multiple_py" name="connect_multiple" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_multiple_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_multiple_ruby" name="connect_multiple" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_multiple_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_multiple_ts" name="connect_multiple" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_multiple_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_multiple_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_multiple/main.go#L11-25"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">servers := []string{"nats://localhost:1222",
|
|
||||||
"nats://localhost:1223",
|
|
||||||
"nats://localhost:1224",
|
|
||||||
}
|
|
||||||
|
|
||||||
nc, err := nats.Connect(strings.Join(servers, ","))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_multiple_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectToMultipleServers.java#L11-22"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://localhost:1222").
|
|
||||||
server("nats://localhost:1223").
|
|
||||||
server("nats://localhost:1224").
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_multiple_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/connection_samples.js#L67-84"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
servers: [
|
|
||||||
"nats://demo.nats.io:4222",
|
|
||||||
"nats://localhost:4222"
|
|
||||||
]}
|
|
||||||
);
|
|
||||||
|
|
||||||
nc.on('connect', (c) => {
|
|
||||||
// Do something with the connection
|
|
||||||
doSomething();
|
|
||||||
// When done close it
|
|
||||||
nc.close();
|
|
||||||
});
|
|
||||||
nc.on('error', (err) => {
|
|
||||||
failed(err);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_multiple_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_multiple.py#L5-17"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
await nc.connect(servers=[
|
|
||||||
"nats://127.0.0.1:1222",
|
|
||||||
"nats://127.0.0.1:1223",
|
|
||||||
"nats://127.0.0.1:1224"
|
|
||||||
])
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_multiple_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_multiple.rb#L1-10"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"]) do |nc|
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
# Close the connection
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_multiple_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/connection_samples.ts#L53-65"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
servers: [
|
|
||||||
"nats://demo.nats.io:4222",
|
|
||||||
"nats://localhost:4222"
|
|
||||||
]
|
|
||||||
});
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
// When done close it
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,109 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_name_go" name="connect_name" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_name_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_name_java" name="connect_name" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_name_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_name_js" name="connect_name" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_name_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_name_py" name="connect_name" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_name_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_name_ruby" name="connect_name" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_name_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_name_ts" name="connect_name" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_name_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_name_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_name/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set a connection name
|
|
||||||
nc, err := nats.Connect("demo.nats.io", nats.Name("my-connection"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_name_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectName.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
connectionName("my-connection"). // Set a connection name
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_name_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L73-79"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
name: "my-connection"
|
|
||||||
});
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_name_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_name.py#L6-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"], name="my-connection")
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_name_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_name.rb#L1-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://demo.nats.io:4222"], name: "my-connection") do |nc|
|
|
||||||
nc.on_reconnect do
|
|
||||||
puts "Got reconnected to #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "Got disconnected! #{reason}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_name_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L55-63"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
name: "my-connection"
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,102 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_options_go" name="connect_options" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_options_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_options_java" name="connect_options" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_options_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_options_js" name="connect_options" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_options_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_options_py" name="connect_options" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_options_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_options_ruby" name="connect_options" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_options_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_options_ts" name="connect_options" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_options_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_options_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_options/main.go#L11-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect(nats.DefaultURL, nats.Timeout(10*time.Second))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_options_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectWithOptions.java#L13-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
connectionTimeout(Duration.ofSeconds(10)). // Set timeout
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_options_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L121-123"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// connection timeout is not supported on node-nats
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_options_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_options.py#L5-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
await nc.connect(connect_timeout=2)
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_options_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_options.rb#L1-14"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby"># There is currently no connect timeout as part of the Ruby NATS client API, but you can use a timer to mimic it.
|
|
||||||
require 'nats/client'
|
|
||||||
|
|
||||||
timer = EM.add_timer(5) do
|
|
||||||
NATS.connect do |nc|
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
# Close the connection
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
end
|
|
||||||
EM.cancel_timer(timer)
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_options_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L89-95"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = await connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
timeout: 1000
|
|
||||||
});
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,112 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_pedantic_go" name="connect_pedantic" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_pedantic_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_pedantic_java" name="connect_pedantic" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_pedantic_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_pedantic_js" name="connect_pedantic" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_pedantic_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_pedantic_py" name="connect_pedantic" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_pedantic_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_pedantic_ruby" name="connect_pedantic" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_pedantic_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_pedantic_ts" name="connect_pedantic" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_pedantic_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_pedantic_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_pedantic/main.go#L10-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">opts := nats.GetDefaultOptions()
|
|
||||||
opts.Url = "demo.nats.io"
|
|
||||||
// Turn on Pedantic
|
|
||||||
opts.Pedantic = true
|
|
||||||
nc, err := opts.Connect()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_pedantic_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectPedantic.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
pedantic(). // Turn on pedantic
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_pedantic_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L39-45"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
pedantic: true
|
|
||||||
});
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_pedantic_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_pedantic.py#L6-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"], pedantic=True)
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_pedantic_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_pedantic.rb#L1-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(pedantic: true) do |nc|
|
|
||||||
nc.on_reconnect do
|
|
||||||
puts "Got reconnected to #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "Got disconnected! #{reason}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_pedantic_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L29-37"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
pedantic: true
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,144 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_status_go" name="connect_status" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_status_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_status_java" name="connect_status" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_status_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_status_js" name="connect_status" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_status_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_status_py" name="connect_status" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_status_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_status_ruby" name="connect_status" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_status_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_status_ts" name="connect_status" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_status_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_status_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_status/main.go#L10-33"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
getStatusTxt := func(nc *nats.Conn) string {
|
|
||||||
switch nc.Status() {
|
|
||||||
case nats.CONNECTED:
|
|
||||||
return "Connected"
|
|
||||||
case nats.CLOSED:
|
|
||||||
return "Closed"
|
|
||||||
default:
|
|
||||||
return "Other"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
log.Printf("The connection is %v\n", getStatusTxt(nc))
|
|
||||||
|
|
||||||
nc.Close()
|
|
||||||
|
|
||||||
log.Printf("The connection is %v\n", getStatusTxt(nc))
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_status_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/GetConnectionStatus.java#L10-18"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
System.out.println("The Connection is: " + nc.getStatus());
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
|
|
||||||
System.out.println("The Connection is: " + nc.getStatus());
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_status_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/event_samples.js#L99-113"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// on node you *must* register an error listener. If not registered
|
|
||||||
// the library emits an 'error' event, the node process will exit.
|
|
||||||
nc.on('error', (err) => {
|
|
||||||
t.log('client got an error:', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
if(nc.closed) {
|
|
||||||
t.log('client is closed');
|
|
||||||
} else {
|
|
||||||
t.log('client is not closed');
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_status_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_status.py#L6-27"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(
|
|
||||||
servers=["nats://demo.nats.io:4222"],
|
|
||||||
)
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
print("The connection is connected?", nc.is_connected)
|
|
||||||
|
|
||||||
while True:
|
|
||||||
if nc.is_reconnecting:
|
|
||||||
print("Reconnecting to NATS...")
|
|
||||||
break
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
print("The connection is closed?", nc.is_closed)
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_status_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_status.rb#L3-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">NATS.start(max_reconnect_attempts: 2) do |nc|
|
|
||||||
puts "Connect is connected?: #{nc.connected?}"
|
|
||||||
|
|
||||||
timer = EM.add_periodic_timer(1) do
|
|
||||||
if nc.closing?
|
|
||||||
puts "Connection closed..."
|
|
||||||
EM.cancel_timer(timer)
|
|
||||||
NATS.stop
|
|
||||||
end
|
|
||||||
|
|
||||||
if nc.reconnecting?
|
|
||||||
puts "Reconnecting to NATS..."
|
|
||||||
next
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_status_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/event_samples.ts#L62-68"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">if(nc.isClosed()) {
|
|
||||||
t.log('the client is closed');
|
|
||||||
} else {
|
|
||||||
t.log('the client is running');
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,213 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_go" name="connect_tls" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_tls_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_java" name="connect_tls" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_js" name="connect_tls" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_py" name="connect_tls" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_ruby" name="connect_tls" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_ts" name="connect_tls" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_tls/main.go#L10-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("localhost",
|
|
||||||
nats.ClientCert("resources/certs/cert.pem", "resources/certs/key.pem"),
|
|
||||||
nats.RootCAs("resources/certs/ca.pem"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectTLS.java#L18-81"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">class SSLUtils {
|
|
||||||
public static String KEYSTORE_PATH = "src/main/resources/keystore.jks";
|
|
||||||
public static String TRUSTSTORE_PATH = "src/main/resources/cacerts";
|
|
||||||
public static String STORE_PASSWORD = "password";
|
|
||||||
public static String KEY_PASSWORD = "password";
|
|
||||||
public static String ALGORITHM = "SunX509";
|
|
||||||
|
|
||||||
public static KeyStore loadKeystore(String path) throws Exception {
|
|
||||||
KeyStore store = KeyStore.getInstance("JKS");
|
|
||||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(path));
|
|
||||||
|
|
||||||
try {
|
|
||||||
store.load(in, STORE_PASSWORD.toCharArray());
|
|
||||||
} finally {
|
|
||||||
if (in != null) {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return store;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static KeyManager[] createTestKeyManagers() throws Exception {
|
|
||||||
KeyStore store = loadKeystore(KEYSTORE_PATH);
|
|
||||||
KeyManagerFactory factory = KeyManagerFactory.getInstance(ALGORITHM);
|
|
||||||
factory.init(store, KEY_PASSWORD.toCharArray());
|
|
||||||
return factory.getKeyManagers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TrustManager[] createTestTrustManagers() throws Exception {
|
|
||||||
KeyStore store = loadKeystore(TRUSTSTORE_PATH);
|
|
||||||
TrustManagerFactory factory = TrustManagerFactory.getInstance(ALGORITHM);
|
|
||||||
factory.init(store);
|
|
||||||
return factory.getTrustManagers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SSLContext createSSLContext() throws Exception {
|
|
||||||
SSLContext ctx = SSLContext.getInstance(Options.DEFAULT_SSL_PROTOCOL);
|
|
||||||
ctx.init(createTestKeyManagers(), createTestTrustManagers(), new SecureRandom());
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ConnectTLS {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
SSLContext ctx = SSLUtils.createSSLContext();
|
|
||||||
Options options = new Options.Builder().
|
|
||||||
server("nats://localhost:4222").
|
|
||||||
sslContext(ctx). // Set the SSL context
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/tls_samples.js#L44-56"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let caCert = fs.readFileSync(caCertPath);
|
|
||||||
let clientCert = fs.readFileSync(clientCertPath);
|
|
||||||
let clientKey = fs.readFileSync(clientKeyPath);
|
|
||||||
let nc = NATS.connect({
|
|
||||||
url: url,
|
|
||||||
tls: {
|
|
||||||
ca: [caCert],
|
|
||||||
key: [clientKey],
|
|
||||||
cert: [clientCert]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_tls.py#L7-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
ssl_ctx = ssl.create_default_context(purpose=ssl.Purpose.SERVER_AUTH)
|
|
||||||
ssl_ctx.load_verify_locations('ca.pem')
|
|
||||||
ssl_ctx.load_cert_chain(certfile='client-cert.pem',
|
|
||||||
keyfile='client-key.pem')
|
|
||||||
await nc.connect(io_loop=loop, tls=ssl_ctx)
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"], tls=ssl_ctx)
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_tls.rb#L3-51"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">EM.run do
|
|
||||||
|
|
||||||
options = {
|
|
||||||
:servers => [
|
|
||||||
'nats://localhost:4222',
|
|
||||||
],
|
|
||||||
:tls => {
|
|
||||||
:private_key_file => './spec/configs/certs/key.pem',
|
|
||||||
:cert_chain_file => './spec/configs/certs/server.pem'
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
NATS.connect(options) do |nc|
|
|
||||||
puts "#{Time.now.to_f} - Connected to NATS at #{nc.connected_server}"
|
|
||||||
|
|
||||||
nc.subscribe("hello") do |msg|
|
|
||||||
puts "#{Time.now.to_f} - Received: #{msg}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.flush do
|
|
||||||
nc.publish("hello", "world")
|
|
||||||
end
|
|
||||||
|
|
||||||
EM.add_periodic_timer(0.1) do
|
|
||||||
next unless nc.connected?
|
|
||||||
nc.publish("hello", "hello")
|
|
||||||
end
|
|
||||||
|
|
||||||
# Set default callbacks
|
|
||||||
nc.on_error do |e|
|
|
||||||
puts "#{Time.now.to_f } - Error: #{e}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "#{Time.now.to_f} - Disconnected: #{reason}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_reconnect do |nc|
|
|
||||||
puts "#{Time.now.to_f} - Reconnected to NATS server at #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_close do
|
|
||||||
puts "#{Time.now.to_f} - Connection to NATS closed"
|
|
||||||
EM.stop
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/tls_samples.ts#L40-52"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let caCert = readFileSync(caCertPath);
|
|
||||||
let clientCert = readFileSync(clientCertPath);
|
|
||||||
let clientKey = readFileSync(clientKeyPath);
|
|
||||||
let nc = await connect({
|
|
||||||
url: url,
|
|
||||||
tls: {
|
|
||||||
ca: [caCert],
|
|
||||||
key: [clientKey],
|
|
||||||
cert: [clientCert]
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,191 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_url_go" name="connect_tls_url" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_tls_url_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_url_java" name="connect_tls_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_url_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_url_js" name="connect_tls_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_url_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_url_py" name="connect_tls_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_url_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_url_ruby" name="connect_tls_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_url_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_tls_url_ts" name="connect_tls_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_tls_url_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_url_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_tls_url/main.go#L10-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("localhost",
|
|
||||||
nats.Secure(),
|
|
||||||
nats.RootCAs("resources/certs/ca.pem")) // May need this if server is using self-signed certificate
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_url_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectTLSURL.java#L18-80"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">class SSLUtils2 {
|
|
||||||
public static String KEYSTORE_PATH = "src/main/resources/keystore.jks";
|
|
||||||
public static String TRUSTSTORE_PATH = "src/main/resources/cacerts";
|
|
||||||
public static String STORE_PASSWORD = "password";
|
|
||||||
public static String KEY_PASSWORD = "password";
|
|
||||||
public static String ALGORITHM = "SunX509";
|
|
||||||
|
|
||||||
public static KeyStore loadKeystore(String path) throws Exception {
|
|
||||||
KeyStore store = KeyStore.getInstance("JKS");
|
|
||||||
BufferedInputStream in = new BufferedInputStream(new FileInputStream(path));
|
|
||||||
|
|
||||||
try {
|
|
||||||
store.load(in, STORE_PASSWORD.toCharArray());
|
|
||||||
} finally {
|
|
||||||
if (in != null) {
|
|
||||||
in.close();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return store;
|
|
||||||
}
|
|
||||||
|
|
||||||
public static KeyManager[] createTestKeyManagers() throws Exception {
|
|
||||||
KeyStore store = loadKeystore(KEYSTORE_PATH);
|
|
||||||
KeyManagerFactory factory = KeyManagerFactory.getInstance(ALGORITHM);
|
|
||||||
factory.init(store, KEY_PASSWORD.toCharArray());
|
|
||||||
return factory.getKeyManagers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static TrustManager[] createTestTrustManagers() throws Exception {
|
|
||||||
KeyStore store = loadKeystore(TRUSTSTORE_PATH);
|
|
||||||
TrustManagerFactory factory = TrustManagerFactory.getInstance(ALGORITHM);
|
|
||||||
factory.init(store);
|
|
||||||
return factory.getTrustManagers();
|
|
||||||
}
|
|
||||||
|
|
||||||
public static SSLContext createSSLContext() throws Exception {
|
|
||||||
SSLContext ctx = SSLContext.getInstance(Options.DEFAULT_SSL_PROTOCOL);
|
|
||||||
ctx.init(createTestKeyManagers(), createTestTrustManagers(), new SecureRandom());
|
|
||||||
return ctx;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ConnectTLSURL {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
SSLContext.setDefault(SSLUtils2.createSSLContext()); // Set the default context
|
|
||||||
Options options = new Options.Builder().
|
|
||||||
server("tls://localhost:4222"). // Use the TLS protocol
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_url_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/tls_samples.js#L26-31"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
url: "tls://demo.nats.io:4443",
|
|
||||||
tls: true
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_url_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_tls_url.py#L1-37"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">import asyncio
|
|
||||||
import ssl
|
|
||||||
import certifi
|
|
||||||
from nats.aio.client import Client as NATS
|
|
||||||
from nats.aio.errors import ErrTimeout
|
|
||||||
|
|
||||||
async def run(loop):
|
|
||||||
nc = NATS()
|
|
||||||
|
|
||||||
# If using Python 3.7 in OS X and getting SSL errors, run first:
|
|
||||||
#
|
|
||||||
# /Applications/Python\ 3.7/Install\ Certificates.command
|
|
||||||
#
|
|
||||||
# Setting the tls as the scheme will use same defaults as `ssl.create_default_context()`
|
|
||||||
#
|
|
||||||
await nc.connect("tls://demo.nats.io:4443", loop=loop)
|
|
||||||
|
|
||||||
async def message_handler(msg):
|
|
||||||
subject = msg.subject
|
|
||||||
reply = msg.reply
|
|
||||||
data = msg.data.decode()
|
|
||||||
print("Received a message on '{subject} {reply}': {data}".format(
|
|
||||||
subject=subject, reply=reply, data=data))
|
|
||||||
|
|
||||||
# Simple publisher and async subscriber via coroutine.
|
|
||||||
sid = await nc.subscribe("foo", cb=message_handler)
|
|
||||||
await nc.flush()
|
|
||||||
|
|
||||||
# Stop receiving after 2 messages.
|
|
||||||
await nc.auto_unsubscribe(sid, 2)
|
|
||||||
await nc.publish("foo", b'Hello')
|
|
||||||
await nc.publish("foo", b'World')
|
|
||||||
await nc.publish("foo", b'!!!!!')
|
|
||||||
await asyncio.sleep(1, loop=loop)
|
|
||||||
await nc.close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_url_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_tls_url.rb#L3-19"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">EM.run do
|
|
||||||
|
|
||||||
# In order to use TLS with the Ruby NATS client, use the :tls option
|
|
||||||
# when customizing the connection with an empty block.
|
|
||||||
options = {
|
|
||||||
:servers => [
|
|
||||||
'nats://demo.nats.io:4443',
|
|
||||||
],
|
|
||||||
:tls => {}
|
|
||||||
}
|
|
||||||
|
|
||||||
NATS.connect(options) do |nc|
|
|
||||||
puts :connected
|
|
||||||
end
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_tls_url_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/tls_samples.ts#L26-33"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
url: "tls://demo.nats.io:4443"
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,89 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_go" name="connect_token" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_token_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_java" name="connect_token" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_js" name="connect_token" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_py" name="connect_token" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_ruby" name="connect_token" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_ts" name="connect_token" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_token/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set a token
|
|
||||||
nc, err := nats.Connect("localhost", nats.Token("mytoken"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectToken.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://localhost:4222").
|
|
||||||
token("mytoken"). // Set a token
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/auth_examples.js#L81-83"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({url: `nats://127.0.0.1:${port}`, token: "mytoken!"});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_token.py#L6-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://mytoken@demo.nats.io:4222"])
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_token.rb#L3-7"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">NATS.start(token: "deadbeef") do |nc|
|
|
||||||
puts "Connected using token"
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/auth_examples.ts#L58-60"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = await connect({url: server.nats, token: "mytoken"});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,87 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_url_go" name="connect_token_url" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_token_url_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_url_java" name="connect_token_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_url_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_url_js" name="connect_token_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_url_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_url_py" name="connect_token_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_url_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_url_ruby" name="connect_token_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_url_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_token_url_ts" name="connect_token_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_token_url_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_url_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_token_url/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Token in URL
|
|
||||||
nc, err := nats.Connect("mytoken@localhost")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_url_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectTokenURL.java#L10-16"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://mytoken@localhost:4222");//Token in URL
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_url_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/auth_examples.js#L63-66"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let url = `nats://mytoken!@127.0.0.1:${port}`;
|
|
||||||
let nc = NATS.connect({url: url});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_url_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_token_url.py#L6-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://mytoken@demo.nats.io:4222"])
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_url_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_token_url.rb#L3-7"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">NATS.start("deadbeef@127.0.0.1:4222") do |nc|
|
|
||||||
puts "Connected using token!"
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_token_url_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/auth_examples.ts#L47-50"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let url = `nats://:mytoken!@127.0.0.1:${port}`;
|
|
||||||
let nc = await connect({url: url});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,108 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_url_go" name="connect_url" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_url_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_url_java" name="connect_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_url_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_url_js" name="connect_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_url_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_url_py" name="connect_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_url_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_url_ruby" name="connect_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_url_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_url_ts" name="connect_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_url_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_url_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_url/main.go#L10-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// If connecting to the default port, the URL can be simplified
|
|
||||||
// to just the hostname/IP.
|
|
||||||
// That is, the connect below is equivalent to:
|
|
||||||
// nats.Connect("nats://demo.nats.io:4222")
|
|
||||||
nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_url_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectToServerURL.java#L10-16"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_url_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/connection_samples.js#L45-56"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect("nats://demo.nats.io:4222");
|
|
||||||
nc.on('connect', (c) => {
|
|
||||||
// Do something with the connection
|
|
||||||
doSomething();
|
|
||||||
// When done close it
|
|
||||||
nc.close();
|
|
||||||
});
|
|
||||||
nc.on('error', (err) => {
|
|
||||||
failed(err);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_url_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_url.py#L5-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_url_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_url.rb#L1-10"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers: ["nats://demo.nats.io:4222"]) do |nc|
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
# Close the connection
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_url_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/connection_samples.ts#L40-47"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect("nats://demo.nats.io:4222");
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,103 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_go" name="connect_userpass" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_userpass_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_java" name="connect_userpass" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_js" name="connect_userpass" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_py" name="connect_userpass" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_ruby" name="connect_userpass" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_ts" name="connect_userpass" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_userpass/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set a user and plain text password
|
|
||||||
nc, err := nats.Connect("localhost", nats.UserInfo("myname", "password"))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectUserPassword.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://localhost:4222").
|
|
||||||
userInfo("myname","password"). // Set a user and plain text password
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/auth_examples.js#L19-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({url: server.nats, user: "myname", pass: "password"});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_userpass.py#L6-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://myname:password@demo.nats.io:4222"])
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_userpass.rb#L1-19"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://myname:password@127.0.0.1:4222"], name: "my-connection") do |nc|
|
|
||||||
nc.on_error do |e|
|
|
||||||
puts "Error: #{e}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_reconnect do
|
|
||||||
puts "Got reconnected to #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "Got disconnected! #{reason}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/auth_examples.ts#L21-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = await connect({url: server.nats, user: "myname", pass: "password"});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,101 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_url_go" name="connect_userpass_url" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_userpass_url_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_url_java" name="connect_userpass_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_url_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_url_js" name="connect_userpass_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_url_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_url_py" name="connect_userpass_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_url_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_url_ruby" name="connect_userpass_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_url_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_userpass_url_ts" name="connect_userpass_url" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_userpass_url_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_url_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_userpass_url/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set a user and plain text password
|
|
||||||
nc, err := nats.Connect("myname:password@localhost")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_url_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectUserPasswordURL.java#L10-16"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://myname:password@localhost:4222");
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_url_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/auth_examples.js#L40-43"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let url = `nats://myname:password@127.0.0.1:${port}`;
|
|
||||||
let nc = NATS.connect(url);
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_url_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_userpass_url.py#L6-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://myname:password@demo.nats.io:4222"])
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_url_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_userpass_url.rb#L1-19"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://myname:password@127.0.0.1:4222"], name: "my-connection") do |nc|
|
|
||||||
nc.on_error do |e|
|
|
||||||
puts "Error: #{e}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_reconnect do
|
|
||||||
puts "Got reconnected to #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "Got disconnected! #{reason}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_userpass_url_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/auth_examples.ts#L34-37"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let url = `nats://myname:password@127.0.0.1:${port}`;
|
|
||||||
let nc = await connect({url: url});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,112 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_verbose_go" name="connect_verbose" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connect_verbose_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_verbose_java" name="connect_verbose" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_verbose_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_verbose_js" name="connect_verbose" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_verbose_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_verbose_py" name="connect_verbose" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_verbose_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_verbose_ruby" name="connect_verbose" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_verbose_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connect_verbose_ts" name="connect_verbose" class="tab">
|
|
||||||
|
|
||||||
<label for="connect_verbose_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_verbose_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/connect_verbose/main.go#L10-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">opts := nats.GetDefaultOptions()
|
|
||||||
opts.Url = "demo.nats.io"
|
|
||||||
// Turn on Verbose
|
|
||||||
opts.Verbose = true
|
|
||||||
nc, err := opts.Connect()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_verbose_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectVerbose.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
verbose(). // Turn on verbose
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_verbose_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L56-62"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
verbose: true
|
|
||||||
});
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_verbose_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/connect_verbose.py#L6-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"], verbose=True)
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_verbose_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/connect_verbose.rb#L1-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(verbose: true) do |nc|
|
|
||||||
nc.on_reconnect do
|
|
||||||
puts "Got reconnected to #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "Got disconnected! #{reason}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connect_verbose_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L42-50"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
verbose: true
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,178 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connection_listener_go" name="connection_listener" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="connection_listener_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connection_listener_java" name="connection_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="connection_listener_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connection_listener_js" name="connection_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="connection_listener_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connection_listener_py" name="connection_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="connection_listener_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connection_listener_ruby" name="connection_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="connection_listener_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="connection_listener_ts" name="connection_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="connection_listener_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connection_listener_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/notapplicable.txt#L5-14"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// There is not a single listener for connection events in the NATS Go Client.
|
|
||||||
// Instead, you can set individual event handlers using:
|
|
||||||
|
|
||||||
DisconnectHandler(cb ConnHandler)
|
|
||||||
ReconnectHandler(cb ConnHandler)
|
|
||||||
ClosedHandler(cb ConnHandler)
|
|
||||||
DiscoveredServersHandler(cb ConnHandler)
|
|
||||||
ErrorHandler(cb ErrHandler)
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connection_listener_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SetConnectionListener.java#L8-33"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">class MyConnectionListener implements ConnectionListener {
|
|
||||||
public void connectionEvent(Connection natsConnection, Events event) {
|
|
||||||
System.out.println("Connection event - "+event);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SetConnectionListener {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
connectionListener(new MyConnectionListener()). // Set the listener
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connection_listener_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/event_samples.js#L11-41"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
nc.on('error', (err) => {
|
|
||||||
t.log('error', err);
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('connect', () => {
|
|
||||||
t.log('client connected');
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('disconnect', () => {
|
|
||||||
t.log('client disconnected');
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('reconnecting', () => {
|
|
||||||
t.log('client reconnecting');
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('reconnect', () => {
|
|
||||||
t.log('client reconnected');
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('close', () => {
|
|
||||||
t.log('client closed');
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('permission_error', (err) => {
|
|
||||||
t.log('permission_error', err);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connection_listener_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/notapplicable.txt#L17-42"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python"># Asyncio NATS client can be defined a number of event callbacks
|
|
||||||
async def disconnected_cb():
|
|
||||||
print("Got disconnected!")
|
|
||||||
|
|
||||||
async def reconnected_cb():
|
|
||||||
# See who we are connected to on reconnect.
|
|
||||||
print("Got reconnected to {url}".format(url=nc.connected_url.netloc))
|
|
||||||
|
|
||||||
async def error_cb(e):
|
|
||||||
print("There was an error: {}".format(e))
|
|
||||||
|
|
||||||
async def closed_cb():
|
|
||||||
print("Connection is closed")
|
|
||||||
|
|
||||||
# Setup callbacks to be notified on disconnects and reconnects
|
|
||||||
options["disconnected_cb"] = disconnected_cb
|
|
||||||
options["reconnected_cb"] = reconnected_cb
|
|
||||||
|
|
||||||
# Setup callbacks to be notified when there is an error
|
|
||||||
# or connection is closed.
|
|
||||||
options["error_cb"] = error_cb
|
|
||||||
options["closed_cb"] = closed_cb
|
|
||||||
|
|
||||||
await nc.connect(**options)
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connection_listener_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/notapplicable.txt#L29-44"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby"># There is not a single listener for connection events in the Ruby NATS Client.
|
|
||||||
# Instead, you can set individual event handlers using:
|
|
||||||
|
|
||||||
NATS.on_disconnect do
|
|
||||||
end
|
|
||||||
|
|
||||||
NATS.on_reconnect do
|
|
||||||
end
|
|
||||||
|
|
||||||
NATS.on_close do
|
|
||||||
end
|
|
||||||
|
|
||||||
NATS.on_error do
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="connection_listener_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/event_samples.ts#L7-27"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// connect will happen once - the first connect
|
|
||||||
nc.on('connect', (nc) => {
|
|
||||||
// nc is the connection that connected
|
|
||||||
t.log('client connected');
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('disconnect', (url) => {
|
|
||||||
// nc is the connection that reconnected
|
|
||||||
t.log('disconnected from', url);
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('reconnecting', (url) => {
|
|
||||||
t.log('reconnecting to', url);
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('reconnect', (nc, url) => {
|
|
||||||
// nc is the connection that reconnected
|
|
||||||
t.log('reconnected to', url);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,79 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="control_2k_go" name="control_2k" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="control_2k_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="control_2k_java" name="control_2k" class="tab">
|
|
||||||
|
|
||||||
<label for="control_2k_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="control_2k_js" name="control_2k" class="tab">
|
|
||||||
|
|
||||||
<label for="control_2k_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="control_2k_py" name="control_2k" class="tab">
|
|
||||||
|
|
||||||
<label for="control_2k_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="control_2k_ruby" name="control_2k" class="tab">
|
|
||||||
|
|
||||||
<label for="control_2k_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="control_2k_ts" name="control_2k" class="tab">
|
|
||||||
|
|
||||||
<label for="control_2k_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="control_2k_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/notapplicable.txt#L1-3"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// This does not apply to the NATS Go Client
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="control_2k_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectControl2k.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
maxControlLine(2 * 1024). // Set the max control line to 2k
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="control_2k_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L90-97"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// set this option before creating a connection
|
|
||||||
NATS.MAX_CONTROL_LINE_SIZE = 1024*2;
|
|
||||||
let nc = NATS.connect({
|
|
||||||
url: "nats://demo.nats.io:4222"
|
|
||||||
});
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="control_2k_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/notapplicable.txt#L5-7"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python"># Asyncio NATS client does not allow custom control lines
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="control_2k_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/notapplicable.txt#L5-7"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby"># There is no need to customize this in the Ruby NATS client.
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="control_2k_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L68-70"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// control line size is not configurable on ts-nats
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,185 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_conn_go" name="drain_conn" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="drain_conn_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_conn_java" name="drain_conn" class="tab">
|
|
||||||
|
|
||||||
<label for="drain_conn_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_conn_py" name="drain_conn" class="tab">
|
|
||||||
|
|
||||||
<label for="drain_conn_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_conn_ruby" name="drain_conn" class="tab">
|
|
||||||
|
|
||||||
<label for="drain_conn_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_conn_ts" name="drain_conn" class="tab">
|
|
||||||
|
|
||||||
<label for="drain_conn_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_conn_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/drain_conn/main.go#L12-61"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">wg := sync.WaitGroup{}
|
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
errCh := make(chan error, 1)
|
|
||||||
|
|
||||||
// To simulate a timeout, you would set the DrainTimeout()
|
|
||||||
// to a value less than the time spent in the message callback,
|
|
||||||
// so say: nats.DrainTimeout(10*time.Millisecond).
|
|
||||||
|
|
||||||
nc, err := nats.Connect("demo.nats.io",
|
|
||||||
nats.DrainTimeout(10*time.Second),
|
|
||||||
nats.ErrorHandler(func(_ *nats.Conn, _ *nats.Subscription, err error) {
|
|
||||||
errCh <- err
|
|
||||||
}),
|
|
||||||
nats.ClosedHandler(func(_ *nats.Conn) {
|
|
||||||
wg.Done()
|
|
||||||
}))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Subscribe, but add some delay while processing.
|
|
||||||
if _, err := nc.Subscribe("foo", func(_ *nats.Msg) {
|
|
||||||
time.Sleep(200 * time.Millisecond)
|
|
||||||
}); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Publish a message
|
|
||||||
if err := nc.Publish("foo", []byte("hello")); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Drain the connection, which will close it when done.
|
|
||||||
if err := nc.Drain(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the connection to be closed.
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// Check if there was an error
|
|
||||||
select {
|
|
||||||
case e := <-errCh:
|
|
||||||
log.Fatal(e)
|
|
||||||
default:
|
|
||||||
}
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_conn_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/DrainConn.java#L16-40"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Use a latch to wait for a message to arrive
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
|
||||||
|
|
||||||
// Create a dispatcher and inline message handler
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
String str = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
System.out.println(str);
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
d.subscribe("updates");
|
|
||||||
|
|
||||||
// Wait for a message to come in
|
|
||||||
latch.await();
|
|
||||||
|
|
||||||
// Drain the connection, which will close it
|
|
||||||
CompletableFuture<Boolean> drained = nc.drain(Duration.ofSeconds(10));
|
|
||||||
|
|
||||||
// Wait for the drain to complete
|
|
||||||
drained.get();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_conn_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/drain_conn.py#L1-34"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">import asyncio
|
|
||||||
from nats.aio.client import Client as NATS
|
|
||||||
|
|
||||||
async def example(loop):
|
|
||||||
nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect("nats://127.0.0.1:4222", loop=loop)
|
|
||||||
|
|
||||||
async def handler(msg):
|
|
||||||
print("[Received] ", msg)
|
|
||||||
await nc.publish(msg.reply, b'I can help')
|
|
||||||
|
|
||||||
# Can check whether client is in draining state
|
|
||||||
if nc.is_draining:
|
|
||||||
print("Connection is draining")
|
|
||||||
|
|
||||||
await nc.subscribe("help", "workers", cb=handler)
|
|
||||||
await nc.flush()
|
|
||||||
|
|
||||||
requests = []
|
|
||||||
for i in range(0, 10):
|
|
||||||
request = nc.request("help", b'help!', timeout=1)
|
|
||||||
requests.append(request)
|
|
||||||
|
|
||||||
# Wait for all the responses
|
|
||||||
responses = []
|
|
||||||
responses = await asyncio.gather(*requests)
|
|
||||||
|
|
||||||
# Gracefully close the connection.
|
|
||||||
await nc.drain()
|
|
||||||
|
|
||||||
print("Received {} responses".format(len(responses)))
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_conn_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/drain_conn.rb#L3-26"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">NATS.start(drain_timeout: 1) do |nc|
|
|
||||||
NATS.subscribe('foo', queue: "workers") do |msg, reply, sub|
|
|
||||||
nc.publish(reply, "ACK:#{msg}")
|
|
||||||
end
|
|
||||||
|
|
||||||
NATS.subscribe('bar', queue: "workers") do |msg, reply, sub|
|
|
||||||
nc.publish(reply, "ACK:#{msg}")
|
|
||||||
end
|
|
||||||
|
|
||||||
NATS.subscribe('quux', queue: "workers") do |msg, reply, sub|
|
|
||||||
nc.publish(reply, "ACK:#{msg}")
|
|
||||||
end
|
|
||||||
|
|
||||||
EM.add_timer(2) do
|
|
||||||
next if NATS.draining?
|
|
||||||
|
|
||||||
# Drain gracefully closes the connection.
|
|
||||||
NATS.drain do
|
|
||||||
puts "Done draining. Connection is closed."
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_conn_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/connection_samples.ts#L73-83"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let sub = await nc.subscribe('updates', (err, msg) => {
|
|
||||||
t.log('worker got message', msg.data);
|
|
||||||
}, {queue: "workers"});
|
|
||||||
// [end drain_sub]
|
|
||||||
nc.flush();
|
|
||||||
|
|
||||||
await nc.drain();
|
|
||||||
// client must close when the connection drain resolves
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,166 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_sub_go" name="drain_sub" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="drain_sub_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_sub_java" name="drain_sub" class="tab">
|
|
||||||
|
|
||||||
<label for="drain_sub_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_sub_js" name="drain_sub" class="tab">
|
|
||||||
|
|
||||||
<label for="drain_sub_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_sub_py" name="drain_sub" class="tab">
|
|
||||||
|
|
||||||
<label for="drain_sub_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_sub_ruby" name="drain_sub" class="tab">
|
|
||||||
|
|
||||||
<label for="drain_sub_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="drain_sub_ts" name="drain_sub" class="tab">
|
|
||||||
|
|
||||||
<label for="drain_sub_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_sub_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/drain_sub/main.go#L13-67"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">
|
|
||||||
nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
done := sync.WaitGroup{}
|
|
||||||
done.Add(1)
|
|
||||||
|
|
||||||
count := 0
|
|
||||||
errCh := make(chan error, 1)
|
|
||||||
|
|
||||||
msgAfterDrain := "not this one"
|
|
||||||
|
|
||||||
// This callback will process each message slowly
|
|
||||||
sub, err := nc.Subscribe("updates", func(m *nats.Msg) {
|
|
||||||
if string(m.Data) == msgAfterDrain {
|
|
||||||
errCh <- fmt.Errorf("Should not have received this message")
|
|
||||||
return
|
|
||||||
}
|
|
||||||
time.Sleep(100 * time.Millisecond)
|
|
||||||
count++
|
|
||||||
if count == 2 {
|
|
||||||
done.Done()
|
|
||||||
}
|
|
||||||
})
|
|
||||||
|
|
||||||
// Send 2 messages
|
|
||||||
for i := 0; i < 2; i++ {
|
|
||||||
nc.Publish("updates", []byte("hello"))
|
|
||||||
}
|
|
||||||
|
|
||||||
// Call Drain on the subscription. It unsubscribes but
|
|
||||||
// wait for all pending messages to be processed.
|
|
||||||
if err := sub.Drain(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send one more message, this message should not be received
|
|
||||||
nc.Publish("updates", []byte(msgAfterDrain))
|
|
||||||
|
|
||||||
// Wait for the subscription to have processed the 2 messages.
|
|
||||||
done.Wait()
|
|
||||||
|
|
||||||
// Now check that the 3rd message was not received
|
|
||||||
select {
|
|
||||||
case e := <-errCh:
|
|
||||||
log.Fatal(e)
|
|
||||||
case <-time.After(200 * time.Millisecond):
|
|
||||||
// OK!
|
|
||||||
}
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_sub_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/DrainSub.java#L16-43"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Use a latch to wait for a message to arrive
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
|
||||||
|
|
||||||
// Create a dispatcher and inline message handler
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
String str = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
System.out.println(str);
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
d.subscribe("updates");
|
|
||||||
|
|
||||||
// Wait for a message to come in
|
|
||||||
latch.await();
|
|
||||||
|
|
||||||
// Messages that have arrived will be processed
|
|
||||||
CompletableFuture<Boolean> drained = d.drain(Duration.ofSeconds(10));
|
|
||||||
|
|
||||||
// Wait for the drain to complete
|
|
||||||
drained.get();
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_sub_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L232-234"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// Drain subscription is not supported.
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_sub_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/drain_sub.py#L1-24"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">import asyncio
|
|
||||||
from nats.aio.client import Client as NATS
|
|
||||||
|
|
||||||
async def example(loop):
|
|
||||||
nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect("nats://127.0.0.1:4222", loop=loop)
|
|
||||||
|
|
||||||
async def handler(msg):
|
|
||||||
print("[Received] ", msg)
|
|
||||||
await nc.publish(msg.reply, b'I can help')
|
|
||||||
|
|
||||||
# Can check whether client is in draining state
|
|
||||||
if nc.is_draining:
|
|
||||||
print("Connection is draining")
|
|
||||||
|
|
||||||
sid = await nc.subscribe("help", "workers", cb=handler)
|
|
||||||
await nc.flush()
|
|
||||||
|
|
||||||
# Gracefully unsubscribe the subscription
|
|
||||||
await nc.drain(sid)
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_sub_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/notapplicable.txt#L9-11"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby"># There is currently no API to drain a single subscription, the whole connection can be drained though via NATS.drain
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="drain_sub_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L208-212"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let sub = await nc.subscribe('updates', (err, msg) => {
|
|
||||||
t.log('worker got message', msg.data);
|
|
||||||
}, {queue: "workers"});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,139 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="error_listener_go" name="error_listener" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="error_listener_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="error_listener_java" name="error_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="error_listener_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="error_listener_js" name="error_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="error_listener_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="error_listener_py" name="error_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="error_listener_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="error_listener_ruby" name="error_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="error_listener_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="error_listener_ts" name="error_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="error_listener_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="error_listener_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/error_listener/main.go#L10-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set the callback that will be invoked when an asynchronous error occurs.
|
|
||||||
nc, err := nats.Connect("demo.nats.io",
|
|
||||||
nats.ErrorHandler(func(nc *nats.Conn, sub *nats.Subscription, err error) {
|
|
||||||
log.Printf("Error: %v", err)
|
|
||||||
}))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="error_listener_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SetErrorListener.java#L9-43"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">class MyErrorListener implements ErrorListener {
|
|
||||||
public void errorOccurred(Connection conn, String error)
|
|
||||||
{
|
|
||||||
System.out.println("The server notificed the client with: "+error);
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exceptionOccurred(Connection conn, Exception exp) {
|
|
||||||
System.out.println("The connection handled an exception: "+exp.getLocalizedMessage());
|
|
||||||
}
|
|
||||||
|
|
||||||
public void slowConsumerDetected(Connection conn, Consumer consumer) {
|
|
||||||
System.out.println("A slow consumer was detected.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SetErrorListener {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
errorListener(new MyErrorListener()). // Set the listener
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="error_listener_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/event_samples.js#L76-84"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// on node you *must* register an error listener. If not registered
|
|
||||||
// the library emits an 'error' event, the node process will exit.
|
|
||||||
nc.on('error', (err) => {
|
|
||||||
t.log('client got an error:', err);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="error_listener_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/error_listener.py#L6-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
async def error_cb(e):
|
|
||||||
print("Error: ", e)
|
|
||||||
|
|
||||||
await nc.connect(
|
|
||||||
servers=["nats://demo.nats.io:4222"],
|
|
||||||
reconnect_time_wait=10,
|
|
||||||
error_cb=error_cb,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="error_listener_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/error_listener.rb#L1-11"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://demo.nats.io:4222"]) do |nc|
|
|
||||||
nc.on_error do |e|
|
|
||||||
puts "Error: #{e}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="error_listener_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/event_samples.ts#L48-54"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// on node you *must* register an error listener. If not registered
|
|
||||||
// the library emits an 'error' event, the node process will exit.
|
|
||||||
nc.on('error', (err) => {
|
|
||||||
t.log('client got an out of band error:', err);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,132 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="flush_go" name="flush" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="flush_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="flush_java" name="flush" class="tab">
|
|
||||||
|
|
||||||
<label for="flush_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="flush_js" name="flush" class="tab">
|
|
||||||
|
|
||||||
<label for="flush_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="flush_py" name="flush" class="tab">
|
|
||||||
|
|
||||||
<label for="flush_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="flush_ruby" name="flush" class="tab">
|
|
||||||
|
|
||||||
<label for="flush_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="flush_ts" name="flush" class="tab">
|
|
||||||
|
|
||||||
<label for="flush_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="flush_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/flush/main.go#L11-26"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
if err := nc.Publish("updates", []byte("All is Well")); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
// Sends a PING and wait for a PONG from the server, up to the given timeout.
|
|
||||||
// This gives guarantee that the server has processed above message.
|
|
||||||
if err := nc.FlushTimeout(time.Second); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="flush_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/Flush.java#L13-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
nc.publish("updates", "All is Well".getBytes(StandardCharsets.UTF_8));
|
|
||||||
nc.flush(Duration.ofSeconds(1)); // Flush the message queue
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="flush_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/publisher_samples.js#L93-103"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({url: "nats://demo.nats.io:4222"});
|
|
||||||
let start = Date.now();
|
|
||||||
nc.flush(() => {
|
|
||||||
t.log('round trip completed in', Date.now() - start, 'ms');
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.publish('foo');
|
|
||||||
// function in flush is optional
|
|
||||||
nc.flush();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="flush_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/flush.py#L6-17"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
await nc.publish("updates", b'All is Well')
|
|
||||||
|
|
||||||
# Sends a PING and wait for a PONG from the server, up to the given timeout.
|
|
||||||
# This gives guarantee that the server has processed above message.
|
|
||||||
await nc.flush(timeout=1)
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="flush_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/flush.rb#L1-18"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'fiber'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
nc.subscribe("updates") do |msg|
|
|
||||||
puts msg
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.publish("updates", "All is Well")
|
|
||||||
|
|
||||||
nc.flush do
|
|
||||||
# Sends a PING and wait for a PONG from the server, up to the given timeout.
|
|
||||||
# This gives guarantee that the server has processed above message at this point.
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="flush_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/publisher_samples.ts#L90-108"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = await connect({
|
|
||||||
url: "nats://demo.nats.io:4222"
|
|
||||||
});
|
|
||||||
|
|
||||||
// you can use flush to trigger a function in your
|
|
||||||
// application once the round-trip to the server finishes
|
|
||||||
let start = Date.now();
|
|
||||||
nc.flush(() => {
|
|
||||||
t.log('round trip completed in', Date.now() - start, 'ms');
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.publish('foo');
|
|
||||||
|
|
||||||
// another way, simply wait for the promise to resolve
|
|
||||||
await nc.flush();
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,115 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="max_payload_go" name="max_payload" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="max_payload_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="max_payload_java" name="max_payload" class="tab">
|
|
||||||
|
|
||||||
<label for="max_payload_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="max_payload_js" name="max_payload" class="tab">
|
|
||||||
|
|
||||||
<label for="max_payload_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="max_payload_py" name="max_payload" class="tab">
|
|
||||||
|
|
||||||
<label for="max_payload_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="max_payload_ruby" name="max_payload" class="tab">
|
|
||||||
|
|
||||||
<label for="max_payload_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="max_payload_ts" name="max_payload" class="tab">
|
|
||||||
|
|
||||||
<label for="max_payload_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="max_payload_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/max_payload/main.go#L10-22"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
mp := nc.MaxPayload()
|
|
||||||
log.Printf("Maximum payload is %v bytes", mp)
|
|
||||||
|
|
||||||
// Do something with the max payload
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="max_payload_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/GetMaxPayload.java#L10-17"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
long max = nc.getMaxPayload();
|
|
||||||
// Do something with the max payload
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="max_payload_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/event_samples.js#L128-139"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// on node you *must* register an error listener. If not registered
|
|
||||||
// the library emits an 'error' event, the node process will exit.
|
|
||||||
nc.on('error', (err) => {
|
|
||||||
t.log('client got an error:', err);
|
|
||||||
});
|
|
||||||
nc.on('connect', () => {
|
|
||||||
t.log(nc.info.max_payload);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="max_payload_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/max_payload.py#L6-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
print("Maximum payload is %d bytes" % nc.max_payload)
|
|
||||||
|
|
||||||
# Do something with the max payload.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="max_payload_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/max_payload.rb#L1-16"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(max_outstanding_pings: 5) do |nc|
|
|
||||||
nc.on_reconnect do
|
|
||||||
puts "Got reconnected to #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "Got disconnected! #{reason}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Do something with the max_payload
|
|
||||||
puts "Maximum Payload is #{nc.server_info[:max_payload]} bytes"
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="max_payload_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/event_samples.ts#L76-83"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// connect will happen once - the first connect
|
|
||||||
nc.on('connect', (nc: Client, url: string, options: ServerInfo) => {
|
|
||||||
// nc is the connection that connected
|
|
||||||
t.log('client connected to', url);
|
|
||||||
t.log('max_payload', options.max_payload);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,105 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="no_echo_go" name="no_echo" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="no_echo_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="no_echo_java" name="no_echo" class="tab">
|
|
||||||
|
|
||||||
<label for="no_echo_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="no_echo_js" name="no_echo" class="tab">
|
|
||||||
|
|
||||||
<label for="no_echo_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="no_echo_py" name="no_echo" class="tab">
|
|
||||||
|
|
||||||
<label for="no_echo_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="no_echo_ruby" name="no_echo" class="tab">
|
|
||||||
|
|
||||||
<label for="no_echo_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="no_echo_ts" name="no_echo" class="tab">
|
|
||||||
|
|
||||||
<label for="no_echo_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="no_echo_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/no_echo/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Turn off echo
|
|
||||||
nc, err := nats.Connect("demo.nats.io", nats.NoEcho())
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="no_echo_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectNoEcho.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
noEcho(). // Turn off echo
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="no_echo_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L239-241"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// no_echo is not supported.
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="no_echo_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/no_echo.py#L5-27"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">ncA = NATS()
|
|
||||||
ncB = NATS()
|
|
||||||
|
|
||||||
await ncA.connect(no_echo=True)
|
|
||||||
await ncB.connect()
|
|
||||||
|
|
||||||
async def handler(msg):
|
|
||||||
# Messages sent by `ncA' will not be received.
|
|
||||||
print("[Received] ", msg)
|
|
||||||
|
|
||||||
await ncA.subscribe("greetings", cb=handler)
|
|
||||||
await ncA.flush()
|
|
||||||
await ncA.publish("greetings", b'Hello World!')
|
|
||||||
await ncB.publish("greetings", b'Hello World!')
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
await ncA.drain()
|
|
||||||
await ncB.drain()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="no_echo_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/no_echo.rb#L3-7"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">NATS.start("nats://demo.nats.io:4222", no_echo: true) do |nc|
|
|
||||||
# ...
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="no_echo_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L222-225"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = await connect({
|
|
||||||
url: "nats://demo.nats.io:4222", noEcho: true});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,111 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_20s_go" name="ping_20s" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="ping_20s_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_20s_java" name="ping_20s" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_20s_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_20s_js" name="ping_20s" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_20s_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_20s_py" name="ping_20s" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_20s_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_20s_ruby" name="ping_20s" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_20s_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_20s_ts" name="ping_20s" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_20s_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_20s_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/ping_20s/main.go#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set Ping Interval to 20 seconds
|
|
||||||
nc, err := nats.Connect("demo.nats.io", nats.PingInterval(20*time.Second))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_20s_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectPingTwenty.java#L13-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
pingInterval(Duration.ofSeconds(20)). // Set Ping Interval
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_20s_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L7-12"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
pingInterval: 20*1000, //20s
|
|
||||||
url: "nats://demo.nats.io:4222"
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_20s_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/ping_20s.py#L6-17"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(
|
|
||||||
servers=["nats://demo.nats.io:4222"],
|
|
||||||
# Set Ping Interval to 20 seconds
|
|
||||||
ping_interval=20,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_20s_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/ping_20s.rb#L1-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(ping_interval: 20) do |nc|
|
|
||||||
nc.on_reconnect do
|
|
||||||
puts "Got reconnected to #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "Got disconnected! #{reason}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_20s_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L5-12"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
pingInterval: 20*2000, //20s
|
|
||||||
url: "nats://demo.nats.io:4222"
|
|
||||||
});
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,118 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_5_go" name="ping_5" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="ping_5_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_5_java" name="ping_5" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_5_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_5_js" name="ping_5" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_5_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_5_py" name="ping_5" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_5_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_5_ruby" name="ping_5" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_5_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="ping_5_ts" name="ping_5" class="tab">
|
|
||||||
|
|
||||||
<label for="ping_5_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_5_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/ping_5/main.go#L10-25"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">opts := nats.GetDefaultOptions()
|
|
||||||
opts.Url = "demo.nats.io"
|
|
||||||
// Set maximum number of PINGs out without getting a PONG back
|
|
||||||
// before the connection will be disconnected as a stale connection.
|
|
||||||
opts.MaxPingsOut = 5
|
|
||||||
|
|
||||||
nc, err := opts.Connect()
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_5_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ConnectMaxPingFive.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
maxPingsOut(5). // Set max pings in flight
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_5_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L23-28"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
maxPingOut: 5,
|
|
||||||
url: "nats://demo.nats.io:4222"
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_5_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/ping_5.py#L6-19"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(
|
|
||||||
servers=["nats://demo.nats.io:4222"],
|
|
||||||
# Set maximum number of PINGs out without getting a PONG back
|
|
||||||
# before the connection will be disconnected as a stale connection.
|
|
||||||
max_outstanding_pings=5,
|
|
||||||
ping_interval=1,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_5_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/ping_5s.rb#L1-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(max_outstanding_pings: 5) do |nc|
|
|
||||||
nc.on_reconnect do
|
|
||||||
puts "Got reconnected to #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "Got disconnected! #{reason}"
|
|
||||||
end
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="ping_5_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L17-24"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
maxPingOut: 5,
|
|
||||||
url: "nats://demo.nats.io:4222"
|
|
||||||
});
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,101 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_bytes_go" name="publish_bytes" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="publish_bytes_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_bytes_java" name="publish_bytes" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_bytes_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_bytes_js" name="publish_bytes" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_bytes_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_bytes_py" name="publish_bytes" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_bytes_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_bytes_ruby" name="publish_bytes" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_bytes_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_bytes_ts" name="publish_bytes" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_bytes_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_bytes_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/publish_bytes/main.go#L10-22"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
if err := nc.Publish("updates", []byte("All is Well")); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
// Make sure the message goes through before we close
|
|
||||||
nc.Flush()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_bytes_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/PublishBytes.java#L13-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
nc.publish("updates", "All is Well".getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
// Make sure the message goes through before we close
|
|
||||||
nc.flush(Duration.ZERO);
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_bytes_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/publisher_samples.js#L8-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({url: "nats://demo.nats.io:4222", preserveBuffers: true});
|
|
||||||
let buf = Buffer.allocUnsafe(12);
|
|
||||||
buf.fill("All is well");
|
|
||||||
nc.publish('updates', buf);
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_bytes_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/publish_bytes.py#L6-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
await nc.publish("updates", b'All is Well')
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_bytes_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/publish_bytes.rb#L1-7"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
nc.publish("updates", "All is Well")
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_bytes_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/publisher_samples.ts#L6-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = await connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
payload: Payload.BINARY
|
|
||||||
});
|
|
||||||
|
|
||||||
let buf = Buffer.allocUnsafe(12);
|
|
||||||
buf.fill("All is Well");
|
|
||||||
nc.publish('updates', buf);
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,134 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_json_go" name="publish_json" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="publish_json_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_json_java" name="publish_json" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_json_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_json_js" name="publish_json" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_json_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_json_py" name="publish_json" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_json_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_json_ruby" name="publish_json" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_json_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_json_ts" name="publish_json" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_json_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_json_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/publish_json/main.go#L10-34"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
ec, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER)
|
|
||||||
if err != nil {
|
|
||||||
nc.Close()
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer ec.Close()
|
|
||||||
|
|
||||||
// Define the object
|
|
||||||
type stock struct {
|
|
||||||
Symbol string
|
|
||||||
Price int
|
|
||||||
}
|
|
||||||
|
|
||||||
// Publish the message
|
|
||||||
if err := ec.Publish("updates", &stock{Symbol: "GOOG", Price: 1200}); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
// Make sure the message goes through before we close
|
|
||||||
ec.Flush()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_json_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/PublishJSON.java#L12-44"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">class StockForJsonPub {
|
|
||||||
public String symbol;
|
|
||||||
public float price;
|
|
||||||
}
|
|
||||||
|
|
||||||
public class PublishJSON {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
try {
|
|
||||||
Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Create the data object
|
|
||||||
StockForJsonPub stk = new StockForJsonPub();
|
|
||||||
stk.symbol="GOOG";
|
|
||||||
stk.price=1200;
|
|
||||||
|
|
||||||
// use Gson to encode the object to JSON
|
|
||||||
GsonBuilder builder = new GsonBuilder();
|
|
||||||
Gson gson = builder.create();
|
|
||||||
String json = gson.toJson(stk);
|
|
||||||
|
|
||||||
// Publish the message
|
|
||||||
nc.publish("updates", json.getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
// Make sure the message goes through before we close
|
|
||||||
nc.flush(Duration.ZERO);
|
|
||||||
nc.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_json_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/publisher_samples.js#L25-28"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({url: "nats://demo.nats.io:4222", json: true});
|
|
||||||
nc.publish('updates', {ticker: 'GOOG', price: 1200});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_json_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/publish_json.py#L7-14"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
await nc.publish("updates", json.dumps({"symbol": "GOOG", "price": 1200 }).encode())
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_json_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/publish_json.rb#L1-8"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'json'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
nc.publish("updates", {"symbol": "GOOG", "price": 1200}.to_json)
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_json_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/publisher_samples.ts#L22-29"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = await connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
payload: Payload.JSON
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.publish('updates', {ticker: 'GOOG', price: 1200});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,186 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_with_reply_go" name="publish_with_reply" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="publish_with_reply_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_with_reply_java" name="publish_with_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_with_reply_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_with_reply_js" name="publish_with_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_with_reply_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_with_reply_py" name="publish_with_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_with_reply_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_with_reply_ruby" name="publish_with_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_with_reply_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="publish_with_reply_ts" name="publish_with_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="publish_with_reply_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_with_reply_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/publish_with_reply/main.go#L11-43"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Create a unique subject name
|
|
||||||
uniqueReplyTo := nats.NewInbox()
|
|
||||||
|
|
||||||
// Listen for a single response
|
|
||||||
sub, err := nc.SubscribeSync(uniqueReplyTo)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Send the request
|
|
||||||
if err := nc.PublishRequest("time", uniqueReplyTo, nil); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read the reply
|
|
||||||
msg, err := sub.NextMsg(time.Second)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the response
|
|
||||||
log.Printf("Reply: %s", msg.Data)
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_with_reply_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/PublishWithReply.java#L16-37"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Create a unique subject name
|
|
||||||
String uniqueReplyTo = NUID.nextGlobal();
|
|
||||||
|
|
||||||
// Listen for a single response
|
|
||||||
Subscription sub = nc.subscribe(uniqueReplyTo);
|
|
||||||
sub.unsubscribe(1);
|
|
||||||
|
|
||||||
// Send the request
|
|
||||||
nc.publish("time", uniqueReplyTo, null);
|
|
||||||
|
|
||||||
// Read the reply
|
|
||||||
Message msg = sub.nextMessage(Duration.ofSeconds(1));
|
|
||||||
|
|
||||||
// Use the response
|
|
||||||
System.out.println(new String(msg.getData(), StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_with_reply_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/publisher_samples.js#L41-57"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// set up a subscription to process the request
|
|
||||||
nc.subscribe('time', (msg, reply) => {
|
|
||||||
if(reply) {
|
|
||||||
nc.publish(reply, new Date().toLocaleTimeString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// create a subscription subject that the responding send replies to
|
|
||||||
let inbox = NATS.createInbox();
|
|
||||||
nc.subscribe(inbox, {max: 1}, (msg) => {
|
|
||||||
t.log('the time is', msg);
|
|
||||||
nc.close();
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.publish('time', "", inbox);
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_with_reply_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/publish_with_reply.py#L8-27"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
future = asyncio.Future()
|
|
||||||
|
|
||||||
async def sub(msg):
|
|
||||||
nonlocal future
|
|
||||||
future.set_result(msg)
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
await nc.subscribe("time", cb=sub)
|
|
||||||
|
|
||||||
unique_reply_to = new_inbox()
|
|
||||||
await nc.publish_request("time", unique_reply_to, b'')
|
|
||||||
|
|
||||||
# Use the response
|
|
||||||
msg = await asyncio.wait_for(future, 1)
|
|
||||||
print("Reply:", msg)
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_with_reply_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/publish_with_reply.rb#L1-22"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'fiber'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
Fiber.new do
|
|
||||||
f = Fiber.current
|
|
||||||
|
|
||||||
nc.subscribe("time") do |msg, reply|
|
|
||||||
f.resume msg
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.publish("time", 'example', NATS.create_inbox)
|
|
||||||
|
|
||||||
# Use the response
|
|
||||||
msg = Fiber.yield
|
|
||||||
puts "Reply: #{msg}"
|
|
||||||
|
|
||||||
end.resume
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="publish_with_reply_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/publisher_samples.ts#L41-64"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// set up a subscription to process the request
|
|
||||||
await nc.subscribe('time', (err, msg) => {
|
|
||||||
if (err) {
|
|
||||||
// this example is running inside of a promise
|
|
||||||
reject();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (msg.reply) {
|
|
||||||
nc.publish(msg.reply, new Date().toLocaleTimeString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// create a subscription subject that the responding send replies to
|
|
||||||
let inbox = createInbox();
|
|
||||||
await nc.subscribe(inbox, (err, msg) => {
|
|
||||||
t.log('the time is', msg.data);
|
|
||||||
// this example is running inside of a promise
|
|
||||||
nc.close();
|
|
||||||
resolve();
|
|
||||||
}, {max: 1});
|
|
||||||
|
|
||||||
nc.publish('time', "", inbox);
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,106 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10s_go" name="reconnect_10s" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="reconnect_10s_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10s_java" name="reconnect_10s" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10s_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10s_js" name="reconnect_10s" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10s_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10s_py" name="reconnect_10s" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10s_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10s_ruby" name="reconnect_10s" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10s_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10s_ts" name="reconnect_10s" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10s_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10s_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/reconnect_10s/main.go#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set reconnect interval to 10 seconds
|
|
||||||
nc, err := nats.Connect("demo.nats.io", nats.ReconnectWait(10*time.Second))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10s_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ReconnectTenSeconds.java#L13-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
reconnectWait(Duration.ofSeconds(10)). // Set Reconnect Wait
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10s_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/reconnect_samples.js#L42-47"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
reconnectTimeWait: 10 * 1000, //10s
|
|
||||||
servers: ["nats://demo.nats.io:4222"]
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10s_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/reconnect_10s.py#L5-16"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
await nc.connect(
|
|
||||||
servers=["nats://demo.nats.io:4222"],
|
|
||||||
reconnect_time_wait=10,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10s_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/reconnect_10s.rb#L1-10"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"], reconnect_time_wait: 10) do |nc|
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
# Close the connection
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10s_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/reconnect_samples.ts#L33-40"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
reconnectTimeWait: 10*1000, //10s
|
|
||||||
servers: ["nats://demo.nats.io:4222"]
|
|
||||||
});
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,106 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10x_go" name="reconnect_10x" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="reconnect_10x_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10x_java" name="reconnect_10x" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10x_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10x_js" name="reconnect_10x" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10x_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10x_py" name="reconnect_10x" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10x_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10x_ruby" name="reconnect_10x" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10x_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_10x_ts" name="reconnect_10x" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_10x_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10x_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/reconnect_10x/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set max reconnects attempts
|
|
||||||
nc, err := nats.Connect("demo.nats.io", nats.MaxReconnects(10))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10x_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ReconnectTenTimes.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
maxReconnects(10). // Set max reconnect attempts
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10x_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/reconnect_samples.js#L58-63"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
maxReconnectAttempts: 10,
|
|
||||||
servers: ["nats://demo.nats.io:4222"]
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10x_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/reconnect_10x.py#L5-16"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
await nc.connect(
|
|
||||||
servers=["nats://demo.nats.io:4222"],
|
|
||||||
max_reconnect_attempts=10,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10x_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/reconnect_10x.rb#L1-10"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"], max_reconnect_attempts: 10) do |nc|
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
# Close the connection
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_10x_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/reconnect_samples.ts#L45-52"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
maxReconnectAttempts: 10,
|
|
||||||
servers: ["nats://demo.nats.io:4222"]
|
|
||||||
});
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,82 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_5mb_go" name="reconnect_5mb" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="reconnect_5mb_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_5mb_java" name="reconnect_5mb" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_5mb_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_5mb_js" name="reconnect_5mb" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_5mb_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_5mb_py" name="reconnect_5mb" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_5mb_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_5mb_ruby" name="reconnect_5mb" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_5mb_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_5mb_ts" name="reconnect_5mb" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_5mb_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_5mb_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/reconnect_5mb/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set reconnect buffer size in bytes (5 MB)
|
|
||||||
nc, err := nats.Connect("demo.nats.io", nats.ReconnectBufSize(5*1024*1024))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_5mb_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ReconnectFiveMB.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
reconnectBufferSize(5 * 1024 * 1024). // Set buffer in bytes
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_5mb_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/reconnect_samples.js#L94-96"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// Reconnect buffer size is not configurable on node-nats
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_5mb_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/notapplicable.txt#L1-3"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python"># Asyncio NATS client currentply does not implement a reconnect buffer
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_5mb_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/notapplicable.txt#L1-3"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby"># There is currently no reconnect pending buffer as part of the Ruby NATS client.
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_5mb_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/reconnect_samples.ts#L76-78"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// Reconnect buffer size is not configurable on ts-nats
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,142 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_event_go" name="reconnect_event" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="reconnect_event_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_event_java" name="reconnect_event" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_event_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_event_js" name="reconnect_event" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_event_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_event_py" name="reconnect_event" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_event_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_event_ruby" name="reconnect_event" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_event_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_event_ts" name="reconnect_event" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_event_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_event_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/reconnect_event/main.go#L10-28"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Connection event handlers are invoked asynchronously
|
|
||||||
// and the state of the connection may have changed when
|
|
||||||
// the callback is invoked.
|
|
||||||
nc, err := nats.Connect("demo.nats.io",
|
|
||||||
nats.DisconnectHandler(func(nc *nats.Conn) {
|
|
||||||
// handle disconnect event
|
|
||||||
}),
|
|
||||||
nats.ReconnectHandler(func(nc *nats.Conn) {
|
|
||||||
// handle reconnect event
|
|
||||||
}))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_event_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ReconnectEvents.java#L12-28"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
connectionListener((conn, type) -> {
|
|
||||||
if (type == Events.RECONNECTED) {
|
|
||||||
// handle reconnected
|
|
||||||
} else if (type == Events.DISCONNECTED) {
|
|
||||||
// handle disconnected, wait for reconnect
|
|
||||||
}
|
|
||||||
}).
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_event_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/reconnect_samples.js#L74-83"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
maxReconnectAttempts: 10,
|
|
||||||
servers: ["nats://demo.nats.io:4222"]
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.on('reconnect', (c) => {
|
|
||||||
console.log('reconnected');
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_event_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/reconnect_event.py#L6-25"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
async def disconnected_cb():
|
|
||||||
print("Got disconnected!")
|
|
||||||
|
|
||||||
async def reconnected_cb():
|
|
||||||
# See who we are connected to on reconnect.
|
|
||||||
print("Got reconnected to {url}".format(url=nc.connected_url.netloc))
|
|
||||||
|
|
||||||
await nc.connect(
|
|
||||||
servers=["nats://demo.nats.io:4222"],
|
|
||||||
reconnect_time_wait=10,
|
|
||||||
reconnected_cb=reconnected_cb,
|
|
||||||
disconnected_cb=disconnected_cb,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Do something with the connection.
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_event_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/reconnect_event.rb#L1-14"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"]) do |nc|
|
|
||||||
# Do something with the connection
|
|
||||||
nc.on_reconnect do
|
|
||||||
puts "Got reconnected to #{nc.connected_server}"
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.on_disconnect do |reason|
|
|
||||||
puts "Got disconnected! #{reason}"
|
|
||||||
end
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_event_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/reconnect_samples.ts#L57-70"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
maxReconnectAttempts: 10,
|
|
||||||
servers: ["nats://demo.nats.io:4222"]
|
|
||||||
});
|
|
||||||
// first argument is the connection (same as nc in this case)
|
|
||||||
// second argument is the url of the server where the client
|
|
||||||
// connected
|
|
||||||
nc.on('reconnect', (conn, server) => {
|
|
||||||
console.log('reconnected to', server);
|
|
||||||
});
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,118 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_no_random_go" name="reconnect_no_random" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="reconnect_no_random_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_no_random_java" name="reconnect_no_random" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_no_random_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_no_random_js" name="reconnect_no_random" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_no_random_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_no_random_py" name="reconnect_no_random" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_no_random_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_no_random_ruby" name="reconnect_no_random" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_no_random_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_no_random_ts" name="reconnect_no_random" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_no_random_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_no_random_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/reconnect_no_random/main.go#L11-25"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">servers := []string{"nats://localhost:1222",
|
|
||||||
"nats://localhost:1223",
|
|
||||||
"nats://localhost:1224",
|
|
||||||
}
|
|
||||||
|
|
||||||
nc, err := nats.Connect(strings.Join(servers, ","), nats.DontRandomize())
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_no_random_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ReconnectNoRandom.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
noRandomize(). // Disable reconnect shuffle
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_no_random_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/reconnect_samples.js#L6-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
noRandomize: false,
|
|
||||||
servers: ["nats://127.0.0.1:4443",
|
|
||||||
"nats://demo.nats.io:4222"
|
|
||||||
]
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_no_random_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/reconnect_no_random.py#L5-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
await nc.connect(
|
|
||||||
servers=[
|
|
||||||
"nats://demo.nats.io:1222",
|
|
||||||
"nats://demo.nats.io:1223",
|
|
||||||
"nats://demo.nats.io:1224"
|
|
||||||
],
|
|
||||||
dont_randomize=True,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_no_random_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/reconnect_no_random.rb#L1-10"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"], dont_randomize_servers: true) do |nc|
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
# Close the connection
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_no_random_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/reconnect_samples.ts#L6-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
noRandomize: false,
|
|
||||||
servers: ["nats://127.0.0.1:4443",
|
|
||||||
"nats://demo.nats.io:4222"
|
|
||||||
]
|
|
||||||
});
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,110 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_none_go" name="reconnect_none" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="reconnect_none_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_none_java" name="reconnect_none" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_none_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_none_js" name="reconnect_none" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_none_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_none_py" name="reconnect_none" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_none_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_none_ruby" name="reconnect_none" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_none_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="reconnect_none_ts" name="reconnect_none" class="tab">
|
|
||||||
|
|
||||||
<label for="reconnect_none_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_none_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/reconnect_none/main.go#L10-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Disable reconnect attempts
|
|
||||||
nc, err := nats.Connect("demo.nats.io", nats.NoReconnect())
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_none_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ReconnectNone.java#L11-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
noReconnect(). // Disable reconnect attempts
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_none_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/reconnect_samples.js#L25-30"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
reconnect: false,
|
|
||||||
servers: ["nats://demo.nats.io:4222"]
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_none_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/reconnect_none.py#L5-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
await nc.connect(
|
|
||||||
servers=[
|
|
||||||
"nats://demo.nats.io:1222",
|
|
||||||
"nats://demo.nats.io:1223",
|
|
||||||
"nats://demo.nats.io:1224"
|
|
||||||
],
|
|
||||||
allow_reconnect=False,
|
|
||||||
)
|
|
||||||
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_none_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/reconnect_none.rb#L1-10"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers: ["nats://127.0.0.1:1222", "nats://127.0.0.1:1223", "nats://127.0.0.1:1224"], reconnect: false) do |nc|
|
|
||||||
# Do something with the connection
|
|
||||||
|
|
||||||
# Close the connection
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="reconnect_none_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/reconnect_samples.ts#L20-27"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// will throw an exception if connection fails
|
|
||||||
let nc = await connect({
|
|
||||||
reconnect: false,
|
|
||||||
servers: ["nats://demo.nats.io:4222"]
|
|
||||||
});
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,125 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="request_reply_go" name="request_reply" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="request_reply_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="request_reply_java" name="request_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="request_reply_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="request_reply_js" name="request_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="request_reply_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="request_reply_py" name="request_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="request_reply_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="request_reply_ruby" name="request_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="request_reply_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="request_reply_ts" name="request_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="request_reply_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="request_reply_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/request_reply/main.go#L11-29"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Send the request
|
|
||||||
msg, err := nc.Request("time", nil, time.Second)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the response
|
|
||||||
log.Printf("Reply: %s", msg.Data)
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="request_reply_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/RequestReply.java#L14-25"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Send the request
|
|
||||||
Message msg = nc.request("time", null, Duration.ofSeconds(1));
|
|
||||||
|
|
||||||
// Use the response
|
|
||||||
System.out.println(new String(msg.getData(), StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="request_reply_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/publisher_samples.js#L77-82"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">nc.requestOne('time', (msg) => {
|
|
||||||
t.log('the time is', msg);
|
|
||||||
nc.close();
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="request_reply_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/request_reply.py#L8-25"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
async def sub(msg):
|
|
||||||
await nc.publish(msg.reply, b'response')
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
await nc.subscribe("time", cb=sub)
|
|
||||||
|
|
||||||
# Send the request
|
|
||||||
try:
|
|
||||||
msg = await nc.request("time", b'', timeout=1)
|
|
||||||
# Use the response
|
|
||||||
print("Reply:", msg)
|
|
||||||
except asyncio.TimeoutError:
|
|
||||||
print("Timed out waiting for response")
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="request_reply_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/request_reply.rb#L1-17"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'fiber'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
nc.subscribe("time") do |msg, reply|
|
|
||||||
nc.publish(reply, "response")
|
|
||||||
end
|
|
||||||
|
|
||||||
Fiber.new do
|
|
||||||
# Use the response
|
|
||||||
msg = nc.request("time", "")
|
|
||||||
puts "Reply: #{msg}"
|
|
||||||
end.resume
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="request_reply_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/publisher_samples.ts#L81-85"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let msg = await nc.request('time', 1000);
|
|
||||||
t.log('the time is', msg.data);
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,111 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="servers_added_go" name="servers_added" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="servers_added_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="servers_added_java" name="servers_added" class="tab">
|
|
||||||
|
|
||||||
<label for="servers_added_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="servers_added_js" name="servers_added" class="tab">
|
|
||||||
|
|
||||||
<label for="servers_added_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="servers_added_py" name="servers_added" class="tab">
|
|
||||||
|
|
||||||
<label for="servers_added_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="servers_added_ruby" name="servers_added" class="tab">
|
|
||||||
|
|
||||||
<label for="servers_added_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="servers_added_ts" name="servers_added" class="tab">
|
|
||||||
|
|
||||||
<label for="servers_added_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="servers_added_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/servers_added/main.go#L10-25"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Be notified if a new server joins the cluster.
|
|
||||||
// Print all the known servers and the only the ones that were discovered.
|
|
||||||
nc, err := nats.Connect("demo.nats.io",
|
|
||||||
nats.DiscoveredServersHandler(func(nc *nats.Conn) {
|
|
||||||
log.Printf("Known servers: %v\n", nc.Servers())
|
|
||||||
log.Printf("Discovered servers: %v\n", nc.DiscoveredServers())
|
|
||||||
}))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="servers_added_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/ListenForNewServers.java#L8-37"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">class ServersAddedListener implements ConnectionListener {
|
|
||||||
public void connectionEvent(Connection nc, Events event) {
|
|
||||||
if (event == Events.DISCOVERED_SERVERS) {
|
|
||||||
for (String server : nc.getServers()) {
|
|
||||||
System.out.println("Known server: "+server);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class ListenForNewServers {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
connectionListener(new ServersAddedListener()). // Set the listener
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="servers_added_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/event_samples.js#L56-61"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect("nats://demo.nats.io:4222");
|
|
||||||
nc.on('serversDiscovered', (urls) => {
|
|
||||||
t.log('serversDiscovered', urls);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="servers_added_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/notapplicable.txt#L13-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python"># Asyncio NATS client does not support discovered servers handler right now
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="servers_added_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/notapplicable.txt#L25-27"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby"># The Ruby NATS client does not support discovered servers handler right now
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="servers_added_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/event_samples.ts#L36-40"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">nc.on('serversChanged', (ce) => {
|
|
||||||
t.log('servers changed\n', 'added: ',ce.added, 'removed:', ce.removed);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,154 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_listener_go" name="slow_listener" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="slow_listener_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_listener_java" name="slow_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_listener_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_listener_js" name="slow_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_listener_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_listener_py" name="slow_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_listener_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_listener_ruby" name="slow_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_listener_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_listener_ts" name="slow_listener" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_listener_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_listener_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/slow_listener/main.go#L10-27"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">// Set the callback that will be invoked when an asynchronous error occurs.
|
|
||||||
nc, err := nats.Connect("demo.nats.io",
|
|
||||||
nats.ErrorHandler(func(nc *nats.Conn, sub *nats.Subscription, err error) {
|
|
||||||
if err == nats.ErrSlowConsumer {
|
|
||||||
dropped, _ := sub.Dropped()
|
|
||||||
log.Printf("Slow consumer on subject %s dropped %d messages\n",
|
|
||||||
sub.Subject, dropped)
|
|
||||||
}
|
|
||||||
}))
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_listener_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SlowConsumerListener.java#L9-43"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">class SlowConsumerReporter implements ErrorListener {
|
|
||||||
public void errorOccurred(Connection conn, String error)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
public void exceptionOccurred(Connection conn, Exception exp) {
|
|
||||||
}
|
|
||||||
|
|
||||||
// Detect slow consumers
|
|
||||||
public void slowConsumerDetected(Connection conn, Consumer consumer) {
|
|
||||||
// Get the dropped count
|
|
||||||
System.out.println("A slow consumer dropped messages: "+ consumer.getDroppedCount());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SlowConsumerListener {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Options options = new Options.Builder().
|
|
||||||
server("nats://demo.nats.io:4222").
|
|
||||||
errorListener(new SlowConsumerReporter()). // Set the listener
|
|
||||||
build();
|
|
||||||
Connection nc = Nats.connect(options);
|
|
||||||
|
|
||||||
// Do something with the connection
|
|
||||||
|
|
||||||
nc.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_listener_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L114-116"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// slow consumer detection is not configurable on node-nats
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_listener_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/slow_listener.py#L7-50"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">
|
|
||||||
nc = NATS()
|
|
||||||
|
|
||||||
async def error_cb(e):
|
|
||||||
if type(e) is nats.aio.errors.ErrSlowConsumer:
|
|
||||||
print("Slow consumer error, unsubscribing from handling further messages...")
|
|
||||||
await nc.unsubscribe(e.sid)
|
|
||||||
|
|
||||||
await nc.connect(
|
|
||||||
servers=["nats://demo.nats.io:4222"],
|
|
||||||
error_cb=error_cb,
|
|
||||||
)
|
|
||||||
|
|
||||||
msgs = []
|
|
||||||
future = asyncio.Future()
|
|
||||||
async def cb(msg):
|
|
||||||
nonlocal msgs
|
|
||||||
nonlocal future
|
|
||||||
print(msg)
|
|
||||||
msgs.append(msg)
|
|
||||||
|
|
||||||
if len(msgs) == 3:
|
|
||||||
# Head of line blocking on other messages caused
|
|
||||||
# by single message proccesing taking long...
|
|
||||||
await asyncio.sleep(1)
|
|
||||||
|
|
||||||
await nc.subscribe("updates", cb=cb, pending_msgs_limit=5)
|
|
||||||
|
|
||||||
for i in range(0, 10):
|
|
||||||
await nc.publish("updates", "msg #{}".format(i).encode())
|
|
||||||
await asyncio.sleep(0)
|
|
||||||
|
|
||||||
try:
|
|
||||||
await asyncio.wait_for(future, 1)
|
|
||||||
except asyncio.TimeoutError:
|
|
||||||
pass
|
|
||||||
|
|
||||||
for msg in msgs:
|
|
||||||
print("[Received]", msg)
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_listener_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/notapplicable.txt#L21-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby"># The Ruby NATS client currently does not have option to customize slow consumer limits per sub.
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_listener_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L82-84"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// slow consumer detection is not configurable on ts-nats
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,121 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_pending_limits_go" name="slow_pending_limits" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="slow_pending_limits_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_pending_limits_java" name="slow_pending_limits" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_pending_limits_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_pending_limits_js" name="slow_pending_limits" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_pending_limits_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_pending_limits_py" name="slow_pending_limits" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_pending_limits_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_pending_limits_ruby" name="slow_pending_limits" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_pending_limits_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="slow_pending_limits_ts" name="slow_pending_limits" class="tab">
|
|
||||||
|
|
||||||
<label for="slow_pending_limits_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_pending_limits_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/sub_pending_limits/main.go#L10-37"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
sub1, err := nc.Subscribe("updates", func(m *nats.Msg) {})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set limits of 1000 messages or 5MB, whichever comes first
|
|
||||||
sub1.SetPendingLimits(1000, 5*1024*1024)
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
sub2, err := nc.Subscribe("updates", func(m *nats.Msg) {})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set no limits for this subscription
|
|
||||||
sub2.SetPendingLimits(-1, -1)
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_pending_limits_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SetPendingLimits.java#L12-32"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
// do something
|
|
||||||
});
|
|
||||||
|
|
||||||
d.subscribe("updates");
|
|
||||||
|
|
||||||
d.setPendingLimits(1_000, 5 * 1024 * 1024); // Set limits on a dispatcher
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
Subscription sub = nc.subscribe("updates");
|
|
||||||
|
|
||||||
sub.setPendingLimits(1_000, 5 * 1024 * 1024); // Set limits on a subscription
|
|
||||||
|
|
||||||
// Do something
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_pending_limits_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/options_samples.js#L107-109"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// slow pending limits are not configurable on node-nats
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_pending_limits_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/sub_pending_limits.py#L6-20"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
future = asyncio.Future()
|
|
||||||
|
|
||||||
async def cb(msg):
|
|
||||||
nonlocal future
|
|
||||||
future.set_result(msg)
|
|
||||||
|
|
||||||
# Set limits of 1000 messages or 5MB
|
|
||||||
await nc.subscribe("updates", cb=cb, pending_bytes_limit=5*1024*1024, pending_msgs_limit=1000)
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_pending_limits_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/notapplicable.txt#L17-19"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby"># The Ruby NATS client currently does not have option to customize slow consumer limits per sub.
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="slow_pending_limits_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/options_samples.ts#L75-77"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// slow pending limits are not configurable on ts-nats
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,195 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_arrow_go" name="subscribe_arrow" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="subscribe_arrow_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_arrow_java" name="subscribe_arrow" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_arrow_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_arrow_js" name="subscribe_arrow" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_arrow_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_arrow_py" name="subscribe_arrow" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_arrow_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_arrow_ruby" name="subscribe_arrow" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_arrow_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_arrow_ts" name="subscribe_arrow" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_arrow_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_arrow_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/subscribe_arrow/main.go#L11-35"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Use a WaitGroup to wait for 4 messages to arrive
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
wg.Add(4)
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
if _, err := nc.Subscribe("time.>", func(m *nats.Msg) {
|
|
||||||
log.Printf("%s: %s", m.Subject, m.Data)
|
|
||||||
wg.Done()
|
|
||||||
}); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the 4 messages to come in
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_arrow_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SubscribeArrow.java#L14-36"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Use a latch to wait for 4 messages to arrive
|
|
||||||
CountDownLatch latch = new CountDownLatch(4);
|
|
||||||
|
|
||||||
// Create a dispatcher and inline message handler
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
String subject = msg.getSubject();
|
|
||||||
String str = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
System.out.println(subject + ": " + str);
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
d.subscribe("time.>");
|
|
||||||
|
|
||||||
// Wait for messages to come in
|
|
||||||
latch.await();
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_arrow_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L176-199"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">nc.subscribe('time.>', (msg, reply, subject) => {
|
|
||||||
// converting timezones correctly in node requires a library
|
|
||||||
// this doesn't take into account *many* things.
|
|
||||||
let time = "";
|
|
||||||
switch (subject) {
|
|
||||||
case 'time.us.east':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/New_York"});
|
|
||||||
break;
|
|
||||||
case 'time.us.central':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Chicago"});
|
|
||||||
break;
|
|
||||||
case 'time.us.mountain':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Denver"});
|
|
||||||
break;
|
|
||||||
case 'time.us.west':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Los_Angeles"});
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
time = "I don't know what you are talking about Willis";
|
|
||||||
}
|
|
||||||
t.log(subject, time);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_arrow_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/subscribe_arrow.py#L6-30"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
# Use queue to wait for 4 messages to arrive
|
|
||||||
queue = asyncio.Queue()
|
|
||||||
async def cb(msg):
|
|
||||||
await queue.put(msg)
|
|
||||||
|
|
||||||
await nc.subscribe("time.>", cb=cb)
|
|
||||||
|
|
||||||
# Send 2 messages and wait for them to come in
|
|
||||||
await nc.publish("time.A.east", b'A')
|
|
||||||
await nc.publish("time.B.east", b'B')
|
|
||||||
await nc.publish("time.C.west", b'C')
|
|
||||||
await nc.publish("time.D.west", b'D')
|
|
||||||
|
|
||||||
for i in range(0, 4):
|
|
||||||
msg = await queue.get()
|
|
||||||
print("Msg:", msg)
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_arrow_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/subscribe_arrow.rb#L1-26"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'fiber'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
Fiber.new do
|
|
||||||
f = Fiber.current
|
|
||||||
|
|
||||||
nc.subscribe("time.>") do |msg, reply|
|
|
||||||
f.resume Time.now.to_f
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.publish("time.A.east", "A")
|
|
||||||
nc.publish("time.B.east", "B")
|
|
||||||
nc.publish("time.C.west", "C")
|
|
||||||
nc.publish("time.D.west", "D")
|
|
||||||
|
|
||||||
# Use the response
|
|
||||||
4.times do
|
|
||||||
msg = Fiber.yield
|
|
||||||
puts "Msg: #{msg}"
|
|
||||||
end
|
|
||||||
end.resume
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_arrow_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L156-179"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">await nc.subscribe('time.>', (err, msg) => {
|
|
||||||
// converting timezones correctly in node requires a library
|
|
||||||
// this doesn't take into account *many* things.
|
|
||||||
let time = "";
|
|
||||||
switch (msg.subject) {
|
|
||||||
case 'time.us.east':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/New_York"});
|
|
||||||
break;
|
|
||||||
case 'time.us.central':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Chicago"});
|
|
||||||
break;
|
|
||||||
case 'time.us.mountain':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Denver"});
|
|
||||||
break;
|
|
||||||
case 'time.us.west':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Los_Angeles"});
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
time = "I don't know what you are talking about Willis";
|
|
||||||
}
|
|
||||||
t.log(msg.subject, time);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,140 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_async_go" name="subscribe_async" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="subscribe_async_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_async_java" name="subscribe_async" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_async_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_async_js" name="subscribe_async" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_async_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_async_py" name="subscribe_async" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_async_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_async_ruby" name="subscribe_async" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_async_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_async_ts" name="subscribe_async" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_async_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_async_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/subscribe_async/main.go#L11-34"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Use a WaitGroup to wait for a message to arrive
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
if _, err := nc.Subscribe("updates", func(m *nats.Msg) {
|
|
||||||
wg.Done()
|
|
||||||
}); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for a message to come in
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_async_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SubscribeAsync.java#L14-35"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Use a latch to wait for a message to arrive
|
|
||||||
CountDownLatch latch = new CountDownLatch(1);
|
|
||||||
|
|
||||||
// Create a dispatcher and inline message handler
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
String str = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
System.out.println(str);
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
d.subscribe("updates");
|
|
||||||
|
|
||||||
// Wait for a message to come in
|
|
||||||
latch.await();
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_async_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L9-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">nc.subscribe("updates", (msg) => {
|
|
||||||
t.log(msg);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_async_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/subscribe_async.py#L6-24"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
future = asyncio.Future()
|
|
||||||
|
|
||||||
async def cb(msg):
|
|
||||||
nonlocal future
|
|
||||||
future.set_result(msg)
|
|
||||||
|
|
||||||
await nc.subscribe("updates", cb=cb)
|
|
||||||
await nc.publish("updates", b'All is Well')
|
|
||||||
await nc.flush()
|
|
||||||
|
|
||||||
# Wait for message to come in
|
|
||||||
msg = await asyncio.wait_for(future, 1)
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_async_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/subscribe_async.rb#L1-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
nc.subscribe("updates") do |msg|
|
|
||||||
puts msg
|
|
||||||
nc.close
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.publish("updates", "All is Well")
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_async_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L9-17"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">nc.subscribe("updates", (err, msg) => {
|
|
||||||
if(err) {
|
|
||||||
console.log('error', err);
|
|
||||||
} else {
|
|
||||||
t.log(msg.data);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,189 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_json_go" name="subscribe_json" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="subscribe_json_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_json_java" name="subscribe_json" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_json_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_json_js" name="subscribe_json" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_json_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_json_py" name="subscribe_json" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_json_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_json_ruby" name="subscribe_json" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_json_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_json_ts" name="subscribe_json" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_json_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_json_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/subscribe_json/main.go#L11-45"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
ec, err := nats.NewEncodedConn(nc, nats.JSON_ENCODER)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer ec.Close()
|
|
||||||
|
|
||||||
// Define the object
|
|
||||||
type stock struct {
|
|
||||||
Symbol string
|
|
||||||
Price int
|
|
||||||
}
|
|
||||||
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
wg.Add(1)
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
if _, err := ec.Subscribe("updates", func(s *stock) {
|
|
||||||
log.Printf("Stock: %s - Price: %v", s.Symbol, s.Price)
|
|
||||||
wg.Done()
|
|
||||||
}); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for a message to come in
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
ec.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_json_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SubscribeJSON.java#L12-57"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">class StockForJsonSub {
|
|
||||||
public String symbol;
|
|
||||||
public float price;
|
|
||||||
|
|
||||||
public String toString() {
|
|
||||||
return symbol + " is at " + price;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
public class SubscribeJSON {
|
|
||||||
public static void main(String[] args) {
|
|
||||||
|
|
||||||
try {
|
|
||||||
Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Use a latch to wait for 10 messages to arrive
|
|
||||||
CountDownLatch latch = new CountDownLatch(10);
|
|
||||||
|
|
||||||
// Create a dispatcher and inline message handler
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
Gson gson = new Gson();
|
|
||||||
|
|
||||||
String json = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
StockForJsonSub stk = gson.fromJson(json, StockForJsonSub.class);
|
|
||||||
|
|
||||||
// Use the object
|
|
||||||
System.out.println(stk);
|
|
||||||
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
d.subscribe("updates");
|
|
||||||
|
|
||||||
// Wait for a message to come in
|
|
||||||
latch.await();
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
} catch (Exception e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_json_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L76-88"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = NATS.connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
json: true
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.subscribe('updates', (msg) => {
|
|
||||||
if(msg && msg.ticker === 'TSLA') {
|
|
||||||
t.log('got message:', msg);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_json_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/subscribe_json.py#L1-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">import asyncio
|
|
||||||
import json
|
|
||||||
from nats.aio.client import Client as NATS
|
|
||||||
from nats.aio.errors import ErrTimeout
|
|
||||||
|
|
||||||
async def run(loop):
|
|
||||||
nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://127.0.0.1:4222"], loop=loop)
|
|
||||||
|
|
||||||
async def message_handler(msg):
|
|
||||||
data = json.loads(msg.data.decode())
|
|
||||||
print(data)
|
|
||||||
|
|
||||||
sid = await nc.subscribe("updates", cb=message_handler)
|
|
||||||
await nc.flush()
|
|
||||||
|
|
||||||
await nc.auto_unsubscribe(sid, 2)
|
|
||||||
await nc.publish("updates", json.dumps({"symbol": "GOOG", "price": 1200 }).encode())
|
|
||||||
await asyncio.sleep(1, loop=loop)
|
|
||||||
await nc.close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_json_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/subscribe_json.rb#L1-13"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'json'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
nc.subscribe("updates") do |msg|
|
|
||||||
m = JSON.parse(msg)
|
|
||||||
|
|
||||||
# {"symbol"=>"GOOG", "price"=>12}
|
|
||||||
p m
|
|
||||||
end
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_json_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L70-80"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">let nc = await connect({
|
|
||||||
url: "nats://demo.nats.io:4222",
|
|
||||||
payload: Payload.JSON
|
|
||||||
});
|
|
||||||
|
|
||||||
nc.subscribe('updates', (err, msg) => {
|
|
||||||
t.log('got message:', msg.data ? msg.data : "no payload");
|
|
||||||
});
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,143 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_queue_go" name="subscribe_queue" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="subscribe_queue_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_queue_java" name="subscribe_queue" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_queue_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_queue_js" name="subscribe_queue" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_queue_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_queue_py" name="subscribe_queue" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_queue_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_queue_ruby" name="subscribe_queue" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_queue_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_queue_ts" name="subscribe_queue" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_queue_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_queue_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/subscribe_queue/main.go#L11-34"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Use a WaitGroup to wait for 10 messages to arrive
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
wg.Add(10)
|
|
||||||
|
|
||||||
// Create a queue subscription on "updates" with queue name "workers"
|
|
||||||
if _, err := nc.QueueSubscribe("updates", "worker", func(m *nats.Msg) {
|
|
||||||
wg.Done()
|
|
||||||
}); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for messages to come in
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_queue_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SubscribeQueue.java#L14-35"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Use a latch to wait for 10 messages to arrive
|
|
||||||
CountDownLatch latch = new CountDownLatch(10);
|
|
||||||
|
|
||||||
// Create a dispatcher and inline message handler
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
String str = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
System.out.println(str);
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
d.subscribe("updates", "workers");
|
|
||||||
|
|
||||||
// Wait for a message to come in
|
|
||||||
latch.await();
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_queue_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L217-221"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">nc.subscribe('updates', {queue: "workers"}, (msg) => {
|
|
||||||
t.log('worker got message', msg);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_queue_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/subscribe_queue.py#L6-23"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
future = asyncio.Future()
|
|
||||||
|
|
||||||
async def cb(msg):
|
|
||||||
nonlocal future
|
|
||||||
future.set_result(msg)
|
|
||||||
|
|
||||||
await nc.subscribe("updates", queue="workers", cb=cb)
|
|
||||||
await nc.publish("updates", b'All is Well')
|
|
||||||
|
|
||||||
msg = await asyncio.wait_for(future, 1)
|
|
||||||
print("Msg", msg)
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_queue_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/subscribe_queue.rb#L1-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'fiber'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
Fiber.new do
|
|
||||||
f = Fiber.current
|
|
||||||
|
|
||||||
nc.subscribe("updates", queue: "worker") do |msg, reply|
|
|
||||||
f.resume Time.now
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.publish("updates", "A")
|
|
||||||
|
|
||||||
# Use the response
|
|
||||||
msg = Fiber.yield
|
|
||||||
puts "Msg: #{msg}"
|
|
||||||
end.resume
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_queue_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L193-197"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">await nc.subscribe('updates', (err, msg) => {
|
|
||||||
t.log('worker got message', msg.data);
|
|
||||||
}, {queue: "workers"});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,193 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_star_go" name="subscribe_star" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="subscribe_star_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_star_java" name="subscribe_star" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_star_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_star_js" name="subscribe_star" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_star_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_star_py" name="subscribe_star" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_star_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_star_ruby" name="subscribe_star" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_star_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_star_ts" name="subscribe_star" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_star_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_star_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/subscribe_star/main.go#L11-35"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Use a WaitGroup to wait for 2 messages to arrive
|
|
||||||
wg := sync.WaitGroup{}
|
|
||||||
wg.Add(2)
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
if _, err := nc.Subscribe("time.*.east", func(m *nats.Msg) {
|
|
||||||
log.Printf("%s: %s", m.Subject, m.Data)
|
|
||||||
wg.Done()
|
|
||||||
}); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for the 2 messages to come in
|
|
||||||
wg.Wait()
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_star_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SubscribeStar.java#L14-36"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Use a latch to wait for 2 messages to arrive
|
|
||||||
CountDownLatch latch = new CountDownLatch(2);
|
|
||||||
|
|
||||||
// Create a dispatcher and inline message handler
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
String subject = msg.getSubject();
|
|
||||||
String str = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
System.out.println(subject + ": " + str);
|
|
||||||
latch.countDown();
|
|
||||||
});
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
d.subscribe("time.*.east");
|
|
||||||
|
|
||||||
// Wait for messages to come in
|
|
||||||
latch.await();
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_star_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L134-157"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">nc.subscribe('time.us.*', (msg, reply, subject) => {
|
|
||||||
// converting timezones correctly in node requires a library
|
|
||||||
// this doesn't take into account *many* things.
|
|
||||||
let time = "";
|
|
||||||
switch (subject) {
|
|
||||||
case 'time.us.east':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/New_York"});
|
|
||||||
break;
|
|
||||||
case 'time.us.central':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Chicago"});
|
|
||||||
break;
|
|
||||||
case 'time.us.mountain':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Denver"});
|
|
||||||
break;
|
|
||||||
case 'time.us.west':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Los_Angeles"});
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
time = "I don't know what you are talking about Willis";
|
|
||||||
}
|
|
||||||
t.log(subject, time);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_star_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/subscribe_star.py#L6-28"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
# Use queue to wait for 2 messages to arrive
|
|
||||||
queue = asyncio.Queue()
|
|
||||||
async def cb(msg):
|
|
||||||
await queue.put_nowait(msg)
|
|
||||||
|
|
||||||
await nc.subscribe("time.*.east", cb=cb)
|
|
||||||
|
|
||||||
# Send 2 messages and wait for them to come in
|
|
||||||
await nc.publish("time.A.east", b'A')
|
|
||||||
await nc.publish("time.B.east", b'B')
|
|
||||||
|
|
||||||
msg_A = await queue.get()
|
|
||||||
msg_B = await queue.get()
|
|
||||||
|
|
||||||
print("Msg A:", msg_A)
|
|
||||||
print("Msg B:", msg_B)
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_star_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/subscribe_star.rb#L1-26"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'fiber'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
Fiber.new do
|
|
||||||
f = Fiber.current
|
|
||||||
|
|
||||||
nc.subscribe("time.*.east") do |msg, reply|
|
|
||||||
f.resume Time.now
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.publish("time.A.east", "A")
|
|
||||||
nc.publish("time.B.east", "B")
|
|
||||||
|
|
||||||
# Use the response
|
|
||||||
msg_A = Fiber.yield
|
|
||||||
puts "Msg A: #{msg_A}"
|
|
||||||
|
|
||||||
msg_B = Fiber.yield
|
|
||||||
puts "Msg B: #{msg_B}"
|
|
||||||
|
|
||||||
end.resume
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_star_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L119-142"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">await nc.subscribe('time.us.*', (err, msg) => {
|
|
||||||
// converting timezones correctly in node requires a library
|
|
||||||
// this doesn't take into account *many* things.
|
|
||||||
let time = "";
|
|
||||||
switch (msg.subject) {
|
|
||||||
case 'time.us.east':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/New_York"});
|
|
||||||
break;
|
|
||||||
case 'time.us.central':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Chicago"});
|
|
||||||
break;
|
|
||||||
case 'time.us.mountain':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Denver"});
|
|
||||||
break;
|
|
||||||
case 'time.us.west':
|
|
||||||
time = new Date().toLocaleTimeString("en-us", {timeZone: "America/Los_Angeles"});
|
|
||||||
break;
|
|
||||||
default:
|
|
||||||
time = "I don't know what you are talking about Willis";
|
|
||||||
}
|
|
||||||
console.log(msg.subject, time);
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,100 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_sync_go" name="subscribe_sync" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="subscribe_sync_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_sync_java" name="subscribe_sync" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_sync_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_sync_js" name="subscribe_sync" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_sync_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_sync_py" name="subscribe_sync" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_sync_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_sync_ruby" name="subscribe_sync" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_sync_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_sync_ts" name="subscribe_sync" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_sync_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_sync_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/subscribe_sync/main.go#L11-35"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
sub, err := nc.SubscribeSync("updates")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Wait for a message
|
|
||||||
msg, err := sub.NextMsg(10 * time.Second)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Use the response
|
|
||||||
log.Printf("Reply: %s", msg.Data)
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_sync_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SubscribeSync.java#L15-29"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
Subscription sub = nc.subscribe("updates");
|
|
||||||
|
|
||||||
// Read a message
|
|
||||||
Message msg = sub.nextMessage(Duration.ZERO);
|
|
||||||
|
|
||||||
String str = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
System.out.println(str);
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_sync_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L246-248"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// node-nats subscriptions are always async.
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_sync_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/notapplicable.txt#L9-11"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python"># Asyncio NATS client currently does not have a sync subscribe API
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_sync_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/notapplicable.txt#L13-15"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby"># The Ruby NATS client subscriptions are all async.
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_sync_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L238-240"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// ts-nats subscriptions are always async.
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,162 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_w_reply_go" name="subscribe_w_reply" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="subscribe_w_reply_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_w_reply_java" name="subscribe_w_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_w_reply_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_w_reply_js" name="subscribe_w_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_w_reply_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_w_reply_py" name="subscribe_w_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_w_reply_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_w_reply_ruby" name="subscribe_w_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_w_reply_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="subscribe_w_reply_ts" name="subscribe_w_reply" class="tab">
|
|
||||||
|
|
||||||
<label for="subscribe_w_reply_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_w_reply_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/subscribe_w_reply/main.go#L11-39"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
sub, err := nc.SubscribeSync("time")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Read a message
|
|
||||||
msg, err := sub.NextMsg(10 * time.Second)
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get the time
|
|
||||||
timeAsBytes := []byte(time.Now().String())
|
|
||||||
|
|
||||||
// Send the time
|
|
||||||
nc.Publish(msg.Reply, timeAsBytes)
|
|
||||||
|
|
||||||
// Flush and close the connection
|
|
||||||
nc.Flush()
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_w_reply_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/SubscribeWithReply.java#L17-37"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
|
|
||||||
// Subscribe
|
|
||||||
Subscription sub = nc.subscribe("time");
|
|
||||||
|
|
||||||
// Read a message
|
|
||||||
Message msg = sub.nextMessage(Duration.ZERO);
|
|
||||||
|
|
||||||
// Get the time
|
|
||||||
Calendar cal = Calendar.getInstance();
|
|
||||||
SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss");
|
|
||||||
byte[] timeAsBytes = sdf.format(cal.getTime()).getBytes(StandardCharsets.UTF_8);
|
|
||||||
|
|
||||||
// Send the time
|
|
||||||
nc.publish(msg.getReplyTo(), timeAsBytes);
|
|
||||||
|
|
||||||
// Flush and close the connection
|
|
||||||
nc.flush(Duration.ZERO);
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_w_reply_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L28-35"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// set up a subscription to process a request
|
|
||||||
nc.subscribe('time', (msg, reply) => {
|
|
||||||
if (msg.reply) {
|
|
||||||
nc.publish(msg.reply, new Date().toLocaleTimeString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_w_reply_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/subscribe_w_reply.py#L8-31"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
future = asyncio.Future()
|
|
||||||
|
|
||||||
async def cb(msg):
|
|
||||||
nonlocal future
|
|
||||||
future.set_result(msg)
|
|
||||||
|
|
||||||
await nc.subscribe("time", cb=cb)
|
|
||||||
|
|
||||||
await nc.publish_request("time", new_inbox(), b'What is the time?')
|
|
||||||
await nc.flush()
|
|
||||||
|
|
||||||
# Read the message
|
|
||||||
msg = await asyncio.wait_for(future, 1)
|
|
||||||
|
|
||||||
# Send the time
|
|
||||||
time_as_bytes = "{}".format(datetime.now()).encode()
|
|
||||||
await nc.publish(msg.reply, time_as_bytes)
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_w_reply_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/subscribe_w_reply.rb#L1-22"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'fiber'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
Fiber.new do
|
|
||||||
f = Fiber.current
|
|
||||||
|
|
||||||
nc.subscribe("time") do |msg, reply|
|
|
||||||
f.resume Time.now
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.publish("time", 'What is the time?', NATS.create_inbox)
|
|
||||||
|
|
||||||
# Use the response
|
|
||||||
msg = Fiber.yield
|
|
||||||
puts "Reply: #{msg}"
|
|
||||||
|
|
||||||
end.resume
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="subscribe_w_reply_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L29-38"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// set up a subscription to process a request
|
|
||||||
await nc.subscribe('time', (err, msg) => {
|
|
||||||
if (msg.reply) {
|
|
||||||
nc.publish(msg.reply, new Date().toLocaleTimeString());
|
|
||||||
} else {
|
|
||||||
t.log('got a request for the time, but no reply subject was set.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,168 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_go" name="unsubscribe" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="unsubscribe_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_java" name="unsubscribe" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_js" name="unsubscribe" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_py" name="unsubscribe" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_ruby" name="unsubscribe" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_ts" name="unsubscribe" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/unsubscribe/main.go#L10-37"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Sync Subscription
|
|
||||||
sub, err := nc.SubscribeSync("updates")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := sub.Unsubscribe(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Async Subscription
|
|
||||||
sub, err = nc.Subscribe("updates", func(_ *nats.Msg) {})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := sub.Unsubscribe(); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/Unsubscribe.java#L14-31"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
String str = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
System.out.println(str);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sync Subscription
|
|
||||||
Subscription sub = nc.subscribe("updates");
|
|
||||||
sub.unsubscribe();
|
|
||||||
|
|
||||||
// Async Subscription
|
|
||||||
d.subscribe("updates");
|
|
||||||
d.unsubscribe("updates");
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L54-65"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// set up a subscription to process a request
|
|
||||||
let sub = nc.subscribe(NATS.createInbox(), (msg, reply) => {
|
|
||||||
if (msg.reply) {
|
|
||||||
nc.publish(reply, new Date().toLocaleTimeString());
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// without arguments the subscription will cancel when the server receives it
|
|
||||||
// you can also specify how many messages are expected by the subscription
|
|
||||||
nc.unsubscribe(sub);
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/unsubscribe.py#L6-26"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
future = asyncio.Future()
|
|
||||||
|
|
||||||
async def cb(msg):
|
|
||||||
nonlocal future
|
|
||||||
future.set_result(msg)
|
|
||||||
|
|
||||||
sid = await nc.subscribe("updates", cb=cb)
|
|
||||||
await nc.publish("updates", b'All is Well')
|
|
||||||
|
|
||||||
# Remove interest in subject
|
|
||||||
await nc.unsubscribe(sid)
|
|
||||||
|
|
||||||
# Won't be received...
|
|
||||||
await nc.publish("updates", b'...')
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/unsubscribe.rb#L1-27"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'fiber'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
Fiber.new do
|
|
||||||
f = Fiber.current
|
|
||||||
|
|
||||||
sid = nc.subscribe("time") do |msg, reply|
|
|
||||||
f.resume Time.now
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.publish("time", 'What is the time?', NATS.create_inbox)
|
|
||||||
|
|
||||||
# Use the response
|
|
||||||
msg = Fiber.yield
|
|
||||||
puts "Reply: #{msg}"
|
|
||||||
|
|
||||||
nc.unsubscribe(sid)
|
|
||||||
|
|
||||||
# Won't be received
|
|
||||||
nc.publish("time", 'What is the time?', NATS.create_inbox)
|
|
||||||
|
|
||||||
end.resume
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L51-64"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// set up a subscription to process a request
|
|
||||||
let sub = await nc.subscribe(createInbox(), (err, msg) => {
|
|
||||||
if (msg.reply) {
|
|
||||||
nc.publish(msg.reply, new Date().toLocaleTimeString());
|
|
||||||
} else {
|
|
||||||
t.log('got a request for the time, but no reply subject was set.');
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
// without arguments the subscription will cancel when the server receives it
|
|
||||||
// you can also specify how many messages are expected by the subscription
|
|
||||||
sub.unsubscribe();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,167 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_auto_go" name="unsubscribe_auto" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="unsubscribe_auto_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_auto_java" name="unsubscribe_auto" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_auto_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_auto_js" name="unsubscribe_auto" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_auto_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_auto_py" name="unsubscribe_auto" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_auto_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_auto_ruby" name="unsubscribe_auto" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_auto_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="unsubscribe_auto_ts" name="unsubscribe_auto" class="tab">
|
|
||||||
|
|
||||||
<label for="unsubscribe_auto_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_auto_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/unsubscribe_auto/main.go#L10-37"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
// Sync Subscription
|
|
||||||
sub, err := nc.SubscribeSync("updates")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := sub.AutoUnsubscribe(1); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Async Subscription
|
|
||||||
sub, err = nc.Subscribe("updates", func(_ *nats.Msg) {})
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
if err := sub.AutoUnsubscribe(1); err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_auto_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/AutoUnsubscribe.java#L14-31"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
Dispatcher d = nc.createDispatcher((msg) -> {
|
|
||||||
String str = new String(msg.getData(), StandardCharsets.UTF_8);
|
|
||||||
System.out.println(str);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Sync Subscription
|
|
||||||
Subscription sub = nc.subscribe("updates");
|
|
||||||
sub.unsubscribe(1);
|
|
||||||
|
|
||||||
// Async Subscription
|
|
||||||
d.subscribe("updates");
|
|
||||||
d.unsubscribe("updates", 1);
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_auto_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/subscriber_samples.js#L105-120"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// `max` specifies the number of messages that the server will forward.
|
|
||||||
// The server will auto-cancel.
|
|
||||||
let opts = {max: 10};
|
|
||||||
let sub = nc.subscribe(NATS.createInbox(), opts, (msg) => {
|
|
||||||
t.log(msg);
|
|
||||||
});
|
|
||||||
|
|
||||||
// another way after 10 messages
|
|
||||||
let sub2 = nc.subscribe(NATS.createInbox(), (err, msg) => {
|
|
||||||
t.log(msg.data);
|
|
||||||
});
|
|
||||||
// if the subscription already received 10 messages, the handler
|
|
||||||
// won't get any more messages
|
|
||||||
nc.unsubscribe(sub2, 10);
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_auto_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/unsubscribe_auto.py#L6-21"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
async def cb(msg):
|
|
||||||
print(msg)
|
|
||||||
|
|
||||||
sid = await nc.subscribe("updates", cb=cb)
|
|
||||||
await nc.auto_unsubscribe(sid, 1)
|
|
||||||
await nc.publish("updates", b'All is Well')
|
|
||||||
|
|
||||||
# Won't be received...
|
|
||||||
await nc.publish("updates", b'...')
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_auto_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/unsubscribe_auto.rb#L1-25"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">require 'nats/client'
|
|
||||||
require 'fiber'
|
|
||||||
|
|
||||||
NATS.start(servers:["nats://127.0.0.1:4222"]) do |nc|
|
|
||||||
Fiber.new do
|
|
||||||
f = Fiber.current
|
|
||||||
|
|
||||||
nc.subscribe("time", max: 1) do |msg, reply|
|
|
||||||
f.resume Time.now
|
|
||||||
end
|
|
||||||
|
|
||||||
nc.publish("time", 'What is the time?', NATS.create_inbox)
|
|
||||||
|
|
||||||
# Use the response
|
|
||||||
msg = Fiber.yield
|
|
||||||
puts "Reply: #{msg}"
|
|
||||||
|
|
||||||
# Won't be received
|
|
||||||
nc.publish("time", 'What is the time?', NATS.create_inbox)
|
|
||||||
|
|
||||||
end.resume
|
|
||||||
end
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="unsubscribe_auto_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/subscriber_samples.ts#L94-109"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">// `max` specifies the number of messages that the server will forward.
|
|
||||||
// The server will auto-cancel.
|
|
||||||
let opts = {max: 10};
|
|
||||||
let sub = await nc.subscribe(createInbox(), (err, msg) => {
|
|
||||||
t.log(msg.data);
|
|
||||||
}, opts);
|
|
||||||
|
|
||||||
// another way after 10 messages
|
|
||||||
let sub2 = await nc.subscribe(createInbox(), (err, msg) => {
|
|
||||||
t.log(msg.data);
|
|
||||||
});
|
|
||||||
// if the subscription already received 10 messages, the handler
|
|
||||||
// won't get any more messages
|
|
||||||
sub2.unsubscribe(10);
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -1,134 +0,0 @@
|
|||||||
|
|
||||||
<div class="tab-wrap">
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="wildcard_tester_go" name="wildcard_tester" class="tab" checked>
|
|
||||||
|
|
||||||
<label for="wildcard_tester_go" class="api-lang" data-language="go">Go</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="wildcard_tester_java" name="wildcard_tester" class="tab">
|
|
||||||
|
|
||||||
<label for="wildcard_tester_java" class="api-lang" data-language="java">Java</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="wildcard_tester_js" name="wildcard_tester" class="tab">
|
|
||||||
|
|
||||||
<label for="wildcard_tester_js" class="api-lang" data-language="js">JavaScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="wildcard_tester_py" name="wildcard_tester" class="tab">
|
|
||||||
|
|
||||||
<label for="wildcard_tester_py" class="api-lang" data-language="py">Python</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="wildcard_tester_ruby" name="wildcard_tester" class="tab">
|
|
||||||
|
|
||||||
<label for="wildcard_tester_ruby" class="api-lang" data-language="ruby">Ruby</label>
|
|
||||||
|
|
||||||
|
|
||||||
<input type="radio" id="wildcard_tester_ts" name="wildcard_tester" class="tab">
|
|
||||||
|
|
||||||
<label for="wildcard_tester_ts" class="api-lang" data-language="ts">TypeScript</label>
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="wildcard_tester_go_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/go-nats-examples/blob/master/api-examples/wildcard_tester/main.go#L11-41"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-go">nc, err := nats.Connect("demo.nats.io")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
defer nc.Close()
|
|
||||||
|
|
||||||
zoneID, err := time.LoadLocation("America/New_York")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
now := time.Now()
|
|
||||||
zoneDateTime := now.In(zoneID)
|
|
||||||
formatted := zoneDateTime.String()
|
|
||||||
|
|
||||||
nc.Publish("time.us.east", []byte(formatted))
|
|
||||||
nc.Publish("time.us.east.atlanta", []byte(formatted))
|
|
||||||
|
|
||||||
zoneID, err = time.LoadLocation("Europe/Warsaw")
|
|
||||||
if err != nil {
|
|
||||||
log.Fatal(err)
|
|
||||||
}
|
|
||||||
zoneDateTime = now.In(zoneID)
|
|
||||||
formatted = zoneDateTime.String()
|
|
||||||
|
|
||||||
nc.Publish("time.eu.east", []byte(formatted))
|
|
||||||
nc.Publish("time.eu.east.warsaw", []byte(formatted))
|
|
||||||
|
|
||||||
// Close the connection
|
|
||||||
nc.Close()
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="wildcard_tester_java_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/java-nats-examples/blob/master/src/main/java/io/nats/examples/PublishForWildcards.java#L17-34"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-java">Connection nc = Nats.connect("nats://demo.nats.io:4222");
|
|
||||||
ZoneId zoneId = ZoneId.of("America/New_York");
|
|
||||||
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.now(), zoneId);
|
|
||||||
String formatted = zonedDateTime.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
|
|
||||||
|
|
||||||
nc.publish("time.us.east", formatted.getBytes(StandardCharsets.UTF_8));
|
|
||||||
nc.publish("time.us.east.atlanta", formatted.getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
zoneId = ZoneId.of("Europe/Warsaw");
|
|
||||||
zonedDateTime = ZonedDateTime.ofInstant(Instant.now(), zoneId);
|
|
||||||
formatted = zonedDateTime.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
|
|
||||||
nc.publish("time.eu.east", formatted.getBytes(StandardCharsets.UTF_8));
|
|
||||||
nc.publish("time.eu.east.warsaw", formatted.getBytes(StandardCharsets.UTF_8));
|
|
||||||
|
|
||||||
nc.flush(Duration.ZERO);
|
|
||||||
nc.close();
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="wildcard_tester_js_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/node-nats-examples/blob/master/src/publisher_samples.js#L138-143"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">nc.publish('time.us.east');
|
|
||||||
nc.publish('time.us.central');
|
|
||||||
nc.publish('time.us.mountain');
|
|
||||||
nc.publish('time.us.west');
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="wildcard_tester_py_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/asyncio-nats-examples/blob/master/wildcard_tester.py#L6-19"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-python">nc = NATS()
|
|
||||||
|
|
||||||
await nc.connect(servers=["nats://demo.nats.io:4222"])
|
|
||||||
|
|
||||||
await nc.publish("time.us.east", b'...')
|
|
||||||
await nc.publish("time.us.east.atlanta", b'...')
|
|
||||||
|
|
||||||
await nc.publish("time.eu.east", b'...')
|
|
||||||
await nc.publish("time.eu.east.warsaw", b'...')
|
|
||||||
|
|
||||||
await nc.close()
|
|
||||||
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="wildcard_tester_ruby_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ruby-nats-examples/blob/master/wildcard_tester.rb#L2-12"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-ruby">NATS.start do |nc|
|
|
||||||
nc.publish("time.us.east", '...')
|
|
||||||
nc.publish("time.us.east.atlanta", '...')
|
|
||||||
|
|
||||||
nc.publish("time.eu.east", '...')
|
|
||||||
nc.publish("time.eu.east.warsaw", '...')
|
|
||||||
|
|
||||||
nc.drain
|
|
||||||
end
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="tab__content">
|
|
||||||
<pre id="wildcard_tester_ts_content"><a class="toolbar-icons pull-right" target="_blank" href="https://github.com/nats-io/ts-nats-examples/blob/master/src/publisher_samples.ts#L139-144"><i class="mdi mdi-github-circle" title="View on GitHub"></i></a><a class="toolbar-icons pull-right"><i class="mdi mdi-content-copy js-copy" title="Copy to Clipboard"></i></a><span class="copy-msg pull-right"></span><code class="language-javascript">nc.publish('time.us.east');
|
|
||||||
nc.publish('time.us.central');
|
|
||||||
nc.publish('time.us.mountain');
|
|
||||||
nc.publish('time.us.west');
|
|
||||||
</code></pre>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
</div>
|
|
@ -4,11 +4,11 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||||
<title>Developing with NATS · GitBook</title>
|
<title>Developing with NATS · NATS</title>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="generator" content="GitBook 3.2.3">
|
<meta name="generator" content="GitBook 3.2.3">
|
||||||
|
<meta name="author" content="The NATS Maintainers">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -388,7 +388,7 @@ digraph nats_queues {
|
|||||||
<script>
|
<script>
|
||||||
var gitbook = gitbook || [];
|
var gitbook = gitbook || [];
|
||||||
gitbook.push(function() {
|
gitbook.push(function() {
|
||||||
gitbook.page.hasChanged({"page":{"title":"Developing with NATS","level":"1.3","depth":1,"next":{"title":"Connecting","level":"1.3.1","depth":2,"path":"developer/connecting.md","ref":"developer/connecting.md","articles":[]},"previous":{"title":"Clients","level":"1.2.3","depth":2,"path":"nats_server/clients.md","ref":"nats_server/clients.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["prism","-highlight","include-html"],"pluginsConfig":{"prism":{},"include-html":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"developer/README.md","mtime":"2019-05-14T18:47:55.355Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-15T17:32:34.308Z"},"basePath":"..","book":{"language":""}});
|
gitbook.page.hasChanged({"page":{"title":"Developing with NATS","level":"1.3","depth":1,"next":{"title":"Connecting","level":"1.3.1","depth":2,"path":"developer/connecting.md","ref":"developer/connecting.md","articles":[]},"previous":{"title":"Clients","level":"1.2.3","depth":2,"path":"nats_server/clients.md","ref":"nats_server/clients.md","articles":[]},"dir":"ltr"},"config":{"plugins":["prism","-highlight","include-html"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{},"include-html":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"The NATS Maintainers","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"NATS","gitbook":"*","description":"Administrative, developer and conceptual documentation for the NATS messaging system."},"file":{"path":"developer/README.md","mtime":"2019-05-14T18:47:55.355Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-15T17:41:03.846Z"},"basePath":"..","book":{"language":""}});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
@ -4,11 +4,11 @@
|
|||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||||
<title>Introduction · GitBook</title>
|
<title>Introduction · NATS</title>
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<meta name="description" content="">
|
<meta name="description" content="">
|
||||||
<meta name="generator" content="GitBook 3.2.3">
|
<meta name="generator" content="GitBook 3.2.3">
|
||||||
|
<meta name="author" content="The NATS Maintainers">
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -279,7 +279,7 @@
|
|||||||
<script>
|
<script>
|
||||||
var gitbook = gitbook || [];
|
var gitbook = gitbook || [];
|
||||||
gitbook.push(function() {
|
gitbook.push(function() {
|
||||||
gitbook.page.hasChanged({"page":{"title":"Introduction","level":"1.1","depth":1,"next":{"title":"NATS Server","level":"1.2","depth":1,"path":"nats_server/README.md","ref":"nats_server/README.md","articles":[{"title":"Installing","level":"1.2.1","depth":2,"path":"nats_server/installation.md","ref":"nats_server/installation.md","articles":[]},{"title":"Running","level":"1.2.2","depth":2,"path":"nats_server/running.md","ref":"nats_server/running.md","articles":[]},{"title":"Clients","level":"1.2.3","depth":2,"path":"nats_server/clients.md","ref":"nats_server/clients.md","articles":[]}]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["prism","-highlight","include-html"],"pluginsConfig":{"prism":{},"include-html":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"README.md","mtime":"2019-05-13T22:01:38.511Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-15T17:32:34.308Z"},"basePath":".","book":{"language":""}});
|
gitbook.page.hasChanged({"page":{"title":"Introduction","level":"1.1","depth":1,"next":{"title":"NATS Server","level":"1.2","depth":1,"path":"nats_server/README.md","ref":"nats_server/README.md","articles":[{"title":"Installing","level":"1.2.1","depth":2,"path":"nats_server/installation.md","ref":"nats_server/installation.md","articles":[]},{"title":"Running","level":"1.2.2","depth":2,"path":"nats_server/running.md","ref":"nats_server/running.md","articles":[]},{"title":"Clients","level":"1.2.3","depth":2,"path":"nats_server/clients.md","ref":"nats_server/clients.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["prism","-highlight","include-html"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"prism":{},"include-html":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"The NATS Maintainers","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"NATS","gitbook":"*","description":"Administrative, developer and conceptual documentation for the NATS messaging system."},"file":{"path":"README.md","mtime":"2019-05-13T22:01:38.511Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-05-15T17:41:03.846Z"},"basePath":".","book":{"language":""}});
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
</div>
|
</div>
|
||||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user