Code examples
Minimal working examples for consuming the Wingbits live stream. All use the same server and .creds file. Replace <YOUR_ASSIGNED_SUBJECT> with the exact subject in your onboarding email, including its final wildcard.
Scoped trial credentials are normally subscribe-only. These examples use a direct Core NATS subscription and do not use request/reply, _INBOX.*, or JetStream APIs. See Real-time stream (NATS) for the full walkthrough and Access & authentication for credentials.
Python
import asyncio
import nats
async def main():
nc = await nats.connect(
"nats://nats-cluster.wingbits.com:4222",
user_credentials="prod-<CUSTOMER>-trial.creds",
)
subject = "<YOUR_ASSIGNED_SUBJECT>"
async def handler(msg):
print(msg.subject, msg.data.decode())
await nc.subscribe(subject, cb=handler)
await asyncio.Event().wait()
asyncio.run(main())Install: pip install nats-py
Node.js
Install: npm install nats
.NET
Install: dotnet add package NATS.Net
Other languages
NATS has official clients for most languages (Go, Rust, Java, C#, …). The pattern is always the same: connect with your .creds file and subscribe directly to your assigned subject.
Production consumer requirements
The examples above prove connectivity and intentionally print each message. For production, replace that per-message work with a non-blocking handoff and handle connection events explicitly. The pattern is:
Choose and document what your application does when its bounded queue is full. Do not silently replace it with an unbounded queue or block the NATS read loop.
Keep the NATS message-reading loop responsive. The subscription handler should do only the minimum work needed to validate or decode a message and place it on a bounded internal queue. Run database writes, file writes, API calls, and other slower processing in separate workers.
Monitor queue depth, processing latency, pending and dropped messages, slow-consumer events, and disconnect/reconnect events. Configure automatic reconnect and an asynchronous error or status handler. If your client does not drain the connection quickly enough, Wingbits may close it to protect the latency and performance of the shared live service. Data missed during a disconnect is not replayed.
See Keep your consumer healthy for the complete production checklist.
See available subjects in NATS subjects & topics.
Last updated
Was this helpful?
