1
0
mirror of https://github.com/taigrr/nats.docs synced 2025-01-18 04:03:23 -08:00
nats.docs/_examples/wildcard_tester.html
Stephen Asbury 57db99feba 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
2019-05-15 10:41:36 -07:00

135 lines
6.3 KiB
HTML

<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(&#34;demo.nats.io&#34;)
if err != nil {
log.Fatal(err)
}
defer nc.Close()
zoneID, err := time.LoadLocation(&#34;America/New_York&#34;)
if err != nil {
log.Fatal(err)
}
now := time.Now()
zoneDateTime := now.In(zoneID)
formatted := zoneDateTime.String()
nc.Publish(&#34;time.us.east&#34;, []byte(formatted))
nc.Publish(&#34;time.us.east.atlanta&#34;, []byte(formatted))
zoneID, err = time.LoadLocation(&#34;Europe/Warsaw&#34;)
if err != nil {
log.Fatal(err)
}
zoneDateTime = now.In(zoneID)
formatted = zoneDateTime.String()
nc.Publish(&#34;time.eu.east&#34;, []byte(formatted))
nc.Publish(&#34;time.eu.east.warsaw&#34;, []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(&#34;nats://demo.nats.io:4222&#34;);
ZoneId zoneId = ZoneId.of(&#34;America/New_York&#34;);
ZonedDateTime zonedDateTime = ZonedDateTime.ofInstant(Instant.now(), zoneId);
String formatted = zonedDateTime.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
nc.publish(&#34;time.us.east&#34;, formatted.getBytes(StandardCharsets.UTF_8));
nc.publish(&#34;time.us.east.atlanta&#34;, formatted.getBytes(StandardCharsets.UTF_8));
zoneId = ZoneId.of(&#34;Europe/Warsaw&#34;);
zonedDateTime = ZonedDateTime.ofInstant(Instant.now(), zoneId);
formatted = zonedDateTime.format(DateTimeFormatter.ISO_ZONED_DATE_TIME);
nc.publish(&#34;time.eu.east&#34;, formatted.getBytes(StandardCharsets.UTF_8));
nc.publish(&#34;time.eu.east.warsaw&#34;, 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(&#39;time.us.east&#39;);
nc.publish(&#39;time.us.central&#39;);
nc.publish(&#39;time.us.mountain&#39;);
nc.publish(&#39;time.us.west&#39;);
</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=[&#34;nats://demo.nats.io:4222&#34;])
await nc.publish(&#34;time.us.east&#34;, b&#39;...&#39;)
await nc.publish(&#34;time.us.east.atlanta&#34;, b&#39;...&#39;)
await nc.publish(&#34;time.eu.east&#34;, b&#39;...&#39;)
await nc.publish(&#34;time.eu.east.warsaw&#34;, b&#39;...&#39;)
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(&#34;time.us.east&#34;, &#39;...&#39;)
nc.publish(&#34;time.us.east.atlanta&#34;, &#39;...&#39;)
nc.publish(&#34;time.eu.east&#34;, &#39;...&#39;)
nc.publish(&#34;time.eu.east.warsaw&#34;, &#39;...&#39;)
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(&#39;time.us.east&#39;);
nc.publish(&#39;time.us.central&#39;);
nc.publish(&#39;time.us.mountain&#39;);
nc.publish(&#39;time.us.west&#39;);
</code></pre>
</div>
</div>