mirror of
https://github.com/taigrr/nats.docs
synced 2025-01-18 04:03:23 -08:00
Update noecho.md
This commit is contained in:
parent
12e6ebd640
commit
8fa9387c5d
@ -8,5 +8,81 @@ The NoEcho option can be useful in BUS patterns where all applications subscribe
|
|||||||
|
|
||||||
Keep in mind that each connection will have to turn off echo, and that it is per connection, not per application. Also, turning echo on and off can result in a major change to your applications communications protocol since messages will flow or stop flowing based on this setting and the subscribing code won't have any indication as to why.
|
Keep in mind that each connection will have to turn off echo, and that it is per connection, not per application. Also, turning echo on and off can result in a major change to your applications communications protocol since messages will flow or stop flowing based on this setting and the subscribing code won't have any indication as to why.
|
||||||
|
|
||||||
!INCLUDE "../../\_examples/no\_echo.html"
|
{% tabs %}
|
||||||
|
{% tab title="Go" %}
|
||||||
|
```go
|
||||||
|
// Turn off echo
|
||||||
|
nc, err := nats.Connect("demo.nats.io", nats.Name("API NoEcho Example"), nats.NoEcho())
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(err)
|
||||||
|
}
|
||||||
|
defer nc.Close()
|
||||||
|
|
||||||
|
// Do something with the connection
|
||||||
|
```
|
||||||
|
{% endtab %}
|
||||||
|
|
||||||
|
{% tab title="Java" %}
|
||||||
|
```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();
|
||||||
|
```
|
||||||
|
{% endtab %}
|
||||||
|
|
||||||
|
{% tab title="JavaScript" %}
|
||||||
|
```javascript
|
||||||
|
let nc = NATS.connect({
|
||||||
|
url: "nats://demo.nats.io:4222",
|
||||||
|
noEcho: true
|
||||||
|
});
|
||||||
|
```
|
||||||
|
{% endtab %}
|
||||||
|
|
||||||
|
{% tab title="Python" %}
|
||||||
|
```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()
|
||||||
|
```
|
||||||
|
{% endtab %}
|
||||||
|
|
||||||
|
{% tab title="Ruby" %}
|
||||||
|
```ruby
|
||||||
|
NATS.start("nats://demo.nats.io:4222", no_echo: true) do |nc|
|
||||||
|
# ...
|
||||||
|
end
|
||||||
|
```
|
||||||
|
{% endtab %}
|
||||||
|
|
||||||
|
{% tab title="TypeScript" %}
|
||||||
|
```typescript
|
||||||
|
let nc = await connect({
|
||||||
|
url: "nats://demo.nats.io:4222", noEcho: true});
|
||||||
|
```
|
||||||
|
{% endtab %}
|
||||||
|
{% endtabs %}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user