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()
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();
// slow pending limits are not configurable on node-nats
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)
# The Ruby NATS client currently does not have option to customize slow consumer limits per sub.
// slow pending limits are not configurable on ts-nats