Skip to content

Instantly share code, notes, and snippets.

View derekcollison's full-sized avatar

Derek Collison derekcollison

View GitHub Profile
@derekcollison
derekcollison / drain.go
Last active August 24, 2018 23:50
NATS Drain Mode
package main
import (
"log"
"os"
"os/signal"
"runtime"
"syscall"
"github.com/nats-io/go-nats"
@derekcollison
derekcollison / qsub.go
Created August 24, 2018 18:58
Simple Queue Subscriber
// All subscriptions with the same queue name will form a queue
// group at runtime. Each message will be delivered to only one
// subscriber per queue group. You can have as many queue groups
// as you wish, and as many members in a single group as you like.
// Normal subscribers will continue to work as expected.
nc.QueueSubscribe("foo", "job_workers", func(m *Msg) {
// Do some work, then send reply.
nc.Publish(m.ReplyTo, myAnswer)
})
@derekcollison
derekcollison / Wants N
Created December 3, 2018 17:51
Subscriber who only wants N responses
// Copyright 2012-2018 The NATS Authors
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.