mirror of
https://github.com/taigrr/nats.docs
synced 2025-01-18 04:03:23 -08:00
Started on developer section of the book
Added tool to build example html Added book.json to bring in a couple plugins Added building_the_book.md to help with how to build things Updated gitignore with vscode and node modules Checking in initial version of code examples Copy/pasted a couple pages to get started on dev book Updated html template for dev book to support graph vis/copy icon/styles
This commit is contained in:
101
developer/examples/publish_bytes.html
Normal file
101
developer/examples/publish_bytes.html
Normal file
@@ -0,0 +1,101 @@
|
||||
|
||||
<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>
|
||||
Reference in New Issue
Block a user