Skip to content

Instantly share code, notes, and snippets.

View wallyqs's full-sized avatar
🌎

Waldemar Quevedo wallyqs

🌎
  • Synadia Communications, Inc.
  • San Francisco
  • X @wallyqs
View GitHub Profile
@wallyqs
wallyqs / pull-subscriber.py
Created May 12, 2021 18:14
pull-subscriber.py
import asyncio
import nats
async def run():
# With stream and pull consumer created as follows via the NATS Cli:
#
# - Stream:
#
# $ nats stream create
# ? Stream Name foo
@wallyqs
wallyqs / wq.go
Created April 16, 2021 00:04
Pull Subscribe + WorkQueuePolicy
package main
import (
"context"
"encoding/json"
"errors"
"math"
"time"
"log"
@wallyqs
wallyqs / nats-ctx.go
Last active April 7, 2021 16:06
NATS Context Option
func ExampleContext() {
nc, err := nats.Connect("localhost")
if err != nil {
log.Fatal(err)
}
// Base context
ctx := nats.Context(context.Background())
js, err := nc.JetStream()
@wallyqs
wallyqs / inbox_concat_test.go
Last active March 31, 2021 22:39
Custom Inbox concat
package main
import (
"bytes"
"fmt"
"strings"
"testing"
"github.com/nats-io/nats.go"
"github.com/nats-io/nuid"
@wallyqs
wallyqs / Dockerfile
Last active March 15, 2021 17:46
NATS Go Dockerfile + Go mod workflow
FROM golang:1.16-alpine AS builder
WORKDIR $GOPATH/src/github.com/nats-io/nats-server
MAINTAINER Waldemar Quevedo <wally@synadia.com>
RUN apk add --update git
COPY . .
@wallyqs
wallyqs / nats-server-init
Created February 24, 2021 22:14
nats-server init
#!/bin/bash
#
# chkconfig: 35 90 12
# description: nats-server
#
# Get function from functions library
. /etc/init.d/functions
# Start the service nats-server
@wallyqs
wallyqs / clusterB.conf
Created February 15, 2021 18:43
NATS Clusters + Leafnodes
system_account: sys
accounts {
sys { users = [{user: sys, pass: sys}] }
}
leaf {
port = 7422
authorization {
users = [
@wallyqs
wallyqs / stan-embbedded-nats.yaml
Created January 21, 2021 17:38
NATS + STAN embedded
---
apiVersion: v1
kind: ConfigMap
metadata:
name: stan-config
data:
stan.conf: |
port: 4222
http: 8222
@wallyqs
wallyqs / aks-lb.md
Last active October 18, 2022 11:25
Setting up a NATS Server with external access on Azure

Setting up a NATS Server with external access on Azure

With the following, you can create a 3-node NATS Server cluster:

kubectl apply -f https://raw.githubusercontent.com/nats-io/k8s/b55687a97a5fd55485e1af302fbdbe43d2d3b968/nats-server/leafnodes/nats-cluster.yaml

The configuration map from the NATS cluster that was created can be found below.

<!doctype html>
<html>
<head>
<meta charset="utf-8">
</head>
<body>
<script type="module">
import { connect, StringCodec } from "/nats.mjs";
document.addEventListener("DOMContentLoaded", function() {