Skip to content

Instantly share code, notes, and snippets.

View aricart's full-sized avatar

Alberto Ricart aricart

View GitHub Profile
@aricart
aricart / README.md
Last active April 15, 2024 14:26
Sharing Jetstream

JetStream Stream Sharing

This is an incremental tutorial on how to share JetStream assets between accounts. The options are not going to be fully explained unless they are vital. The tools used are nats cli and nsc, and both have excellent --help.

Note that this tutorial is expected to be followed in sequence.

Prerequisites

  • Understand imports and exports and JWT
@aricart
aricart / Readme Message Pipeline
Last active February 15, 2024 16:17
Message Pipeline
So this example does a couple of things that are not in the obvious side.
If none of the fields of the message are read, there's no work cost as the pipeline never runs
If there's an error on the pipeline, it tosses, since the pipeline doesn't run until read, the error
will pop when the user access the message. This is not great but cannot add an async condition,
because the async portion is resolved when the message is read. Blowing up on access means that the
trace will be on message access (not great, but not as bad as it can be)
This means that if a pipeline is assigned far away, the error will be non-sensical and will lead
to issues filed due to user code problems
@aricart
aricart / osls.ts
Last active March 3, 2023 12:54
osls - tool for listing objectstores
import {
connect,
credsAuthenticator,
} from "https://raw.githubusercontent.com/nats-io/nats.deno/main/src/mod.ts";
import { cli } from "https://deno.land/x/cobra@v0.0.9/mod.ts";
const root = cli({
use:
"ls [--server host:port] [--creds /path/to/creds] [--user n] [--pass pw] --name osname",
short: "list objectstore assets",
@aricart
aricart / Readme.md
Last active January 11, 2023 19:16
os put large file
mkdir test; cd test; npm init -y; npm install nats.ws@latest
nats-server -c server.conf &
deno run -A os.js

nats object ls
╭────────────────────────────────────────────────────────────────────────────────────╮
│                                Object Store Buckets                                │
├────────────────────────┬─────────────┬─────────────────────┬─────────┬─────────────┤
│ Bucket                 │ Description │ Created             │ Size    │ Last Update │
@aricart
aricart / README.md
Created September 7, 2022 16:45
TLS server connection example

To run this example:

mkdir test
cd test
npm init -y
npm install nats.ws

# Copy `server.go`, `chat.html` and `chat.js` to the `test` directory

Hybrid Cluster

There are two server components, the cloud server and the internal or on-prem cluster.

On-Prem Server

The on-prem server, defines:

  • an account X with a single user x.
  • a leaf node configuration that maps a remote user leaf (and by extension leaf's account in the cloud) to account X
const { createUser, fromSeed } = require("nkeys.js");
const te = new TextEncoder();
const seed = "SAAGNKC24HXG5TD5XKKSWSVFRRKYQGZXF5LCTNXNNWCHO6C4WX3OTDQQNU";
const a = fromSeed(te.encode(seed));
const aid = a.getPublicKey();
const u = createUser();
const uid = u.getPublicKey();
@aricart
aricart / s1.conf
Created June 30, 2020 14:15
sample nats-streaming-cluster
listen: "localhost:4222"
cluster: {
listen: "localhost:4333"
}
streaming: {
store: "file"
dir: "/tmp/stan-cluster/data"
ft_group: "ft"
}
@aricart
aricart / session.md
Last active January 10, 2020 21:40
npm release workflow
> npm dist-tag
latest: 1.3.0
next: 1.3.0
// start on feature - create a branch, edit code commit

// Time to release the 'pre release'
> npm version premajor
v2.0.0–0
@aricart
aricart / package.json
Last active May 23, 2019 16:35
stan queue debug
{
"name": "test",
"version": "1.0.0",
"description": "",
"main": "pub.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"author": "",
"license": "ISC",