Skip to content

Instantly share code, notes, and snippets.

View StarpTech's full-sized avatar

Dustin Deus StarpTech

View GitHub Profile
@StarpTech
StarpTech / sub.go
Last active January 4, 2020 22:35
Event Store subscription
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
// your code
if err := m.Ack(); err != nil {
// event is redelivered
return
}
},
stan.maxInFlight(1),
stan.AckWait("30s"),
@StarpTech
StarpTech / command_publish.go
Last active January 4, 2020 21:36
Run command and publish events
func (c *CommandBus) HandleCommand(cmd Command) {
events := c.CommandHandler.HandleCommand(cmd)
c.stan.Publish("eventstore.events", events)
}
@StarpTech
StarpTech / replay-events.go
Last active January 4, 2020 19:20
Replay events
// Subscribe starting with most recently published value
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
}, stan.StartWithLastReceived())
// Receive all stored values in order
sub, err := sc.Subscribe("eventstore.events", func(m *stan.Msg) {
fmt.Printf("Received a message: %s\n", string(m.Data))
}, stan.DeliverAllAvailable())
@StarpTech
StarpTech / tracker_tanle
Created January 4, 2020 19:14
Processor Tracker table
id | last_processed_event_id | processor_name
+--------------------+----------------------------+-----------------+
517800172974768129 | 01DXRWAVGFZ46AV38EA2CYXFQJ | reactor
517800173095550977 | 01DXRWAVGFZ46AV38EA2CYXFQJ | order-projector
@StarpTech
StarpTech / config.hcl
Created January 1, 2020 18:22
NATS Streaming Event Store configuration
max_payload: 10485760
streaming {
store: "SQL"
sql_options: {
no_caching: true
driver: "postgres"
source: "dbname=mydb host=roach1 port=26257 user=test sslmode=disable readTimeout=5s writeTimeout=5s"
}
store_limits {
max_subs: 100
#!/usr/bin/env node
'use strict'
const inquirer = require('inquirer')
const bench = require('./lib/bench')
const { choices, list } = require('./lib/packages')
const argv = process.argv.slice(2)
async function select (callback) {
const result = await inquirer.prompt([
@StarpTech
StarpTech / react-hooks-axios.js
Created June 3, 2019 22:03
React Hooks Axios Client
// Inspired by https://www.robinwieruch.de/react-hooks-fetch-data/
const dataFetchReducer = (state, action) => {
switch (action.type) {
case 'REQUEST_INIT':
return { ...state, isLoading: true, isError: false };
case 'REQUEST_SUCCESS':
return { ...state, isLoading: false, isError: false, data: action.payload };
case 'REQUEST_FAILURE':
return { ...state, isLoading: false, isError: true };
@StarpTech
StarpTech / graphql-caching.md
Last active November 4, 2018 18:48
Notes about Caching in GraphQL

Graphql cache challenges

How to practice HTTP Caching?

GraphQL queries are usually POST requests. POST request aren't cached by nature. This means that we need different solutions to deliver our content efficiently.

@StarpTech
StarpTech / fab.ts
Last active October 29, 2018 12:10
Small library to validate numeric data structures in a functional-style
/**
* Small library to validate numeric data structures in a functional-style
* All functions are right associative
* If you are looking for more sophisticated features have a look at
* https://ramdajs.com/
*/
export interface FabPattern {
[index: string]: (input: number) => boolean;
}
@StarpTech
StarpTech / arangodb.js
Last active April 11, 2018 09:24
Manage Multi-Tenancy in Arangojs
// initialize
// The maximum number of requests is equal to
// maxSockets * 2 with keepAlive: true or equal to maxSockets with keepAlive: false.
const arangodb = new Arangojs.Database({
url: "http://localhost:8529", // Base URL of the ArangoDB server or list of server URLs.
agentOptions: {
maxSockets: 100,
keepAlive: true
},
loadBalancingStrategy: 'ROUND_ROBIN'