Requirements
Node 10+
Usage
Configuration Options
Configuration options with defaults that can be passed to the constructor.
options
Server
import ShoulderTapServer from 'shoulder-tap'
const shoulderTapServer = new ShoulderTapServer({
type: 'udp4',
HOST: '127.0.0.1',
PORT: 3131,
})
shoulderTapServer.addListener(key, func)
shoulderTapServer.removeListener(key)
Client
import ShoulderTapClient from 'shoulder-tap'
const shoulderTapClient = new ShoulderTapClient({
type: 'udp4',
HOST: '127.0.0.1',
PORT: 3131,
})
shoulderTapClient.setErrorListener((err) => {
log.error(err)
})
shoulderTapClient.sendBestEffort(JSON.stringify({ key: 'testKey', value: 'testValue' }))
Configuration
const config = {
disabled: process.env.SHOULDER_TAP_DNS_DISABLE === 'true',
dnsTtlMs: process.env.SHOULDER_TAP_DNS_CACHE_TTL_MS || 10000,
cacheGraceExpireMultiplier: process.env.SHOULDER_TAP_DNS_CACHE_EXPIRE_MULTIPLIER || 2,
dnsIdleTtlMs: process.env.SHOULDER_TAP_DNS_CACHE_IDLE_TTL_MS || 1000 * 60 * 60,
backgroundScanMs: process.env.SHOULDER_TAP_DNS_BACKGROUND_SCAN_MS || 5000,
dnsCacheSize: process.env.SHOULDER_TAP_DNS_CACHE_SIZE || 100,
logging: {
name: 'shoulder-tap-cache-dns-resolve',
level: process.env.SHOULDER_TAP_DNS_LOG_LEVEL || 'info',
prettyPrint: process.env.NODE_ENV === 'DEBUG' || false,
useLevelLabels: true,
},
}
Statistics
Statistics are available via getStats()
Recommend exposing this through consuming service health statistic/metrics endpoints.
const stats = {
dnsEntries: 0,
refreshed: 0,
hits: 0,
misses: 0,
idleExpired: 0,
errors: 0,
lastError: 0,
lastErrorTs: 0,
}
Getting started
npm i -S shoulder-tap
Testing
Command line
Ubuntu
npm run testServer
npm run testClient
OR
echo -n "{\"key\":\"hello\"}" >/dev/udp/localhost/3131
OR
echo -n "{\"key\":\"hello\"}" | nc -4u -w0 localhost 3131
More information
See the tests and implementation files.