-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
NIXBUS_TOKEN=kcvar1ogctxwkjf71p1p2141 | ||
NIXBUS_PASSPHRASE=M38rmVJNh6pc2B4rE6fvwsgoUY |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# Serverless queue example with NixBus | ||
|
||
1. Install dependencies: | ||
```bash | ||
npm install | ||
``` | ||
|
||
2. Set the environment variables: | ||
```bash | ||
cp .env.example .env | ||
``` | ||
Edit the `.env` file and set the `NIXBUS_TOKEN` and `NIXBUS_PASSPHRASE` variables. | ||
|
||
2. Run the example: | ||
```bash | ||
npm start | ||
``` |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { getNixBusHttp } from '@nixbus/event-bus' | ||
|
||
import { SendPageViewedNotification } from 'src/actions/SendPageViewedNotification' | ||
import { UpdatePageViewedAnalytics } from 'src/actions/UpdatePageViewedAnalytics' | ||
import { PageViewed } from 'src/events/PageViewed' | ||
import { getEnvVar } from 'src/shared/env' | ||
|
||
async function main() { | ||
const bus = getNixBusHttp({ | ||
token: getEnvVar('NIXBUS_TOKEN'), | ||
passphrase: getEnvVar('NIXBUS_PASSPHRASE'), | ||
}) | ||
|
||
await bus.unsubscribeAll() | ||
await Promise.all([ | ||
bus.subscribe(PageViewed.getEventType(), { | ||
id: SendPageViewedNotification.name, | ||
action: SendPageViewedNotification, | ||
config: { maxRetries: 3, timeout: 30, concurrency: 10 }, | ||
}), | ||
bus.subscribe(PageViewed.getEventType(), { | ||
id: UpdatePageViewedAnalytics.name, | ||
action: UpdatePageViewedAnalytics, | ||
config: { maxRetries: 3, timeout: 30, concurrency: 10 }, | ||
}), | ||
]) | ||
|
||
bus | ||
.run() | ||
.then(() => console.log('[Consumer] Running NixBus...')) | ||
.catch((error) => console.error('[Consumer] Error:', error)) | ||
} | ||
|
||
main().catch(console.error) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import { getNixBusHttp } from '@nixbus/event-bus' | ||
|
||
import { PageViewed } from 'src/events/PageViewed' | ||
import { getEnvVar } from 'src/shared/env' | ||
|
||
async function main() { | ||
const bus = getNixBusHttp({ | ||
token: getEnvVar('NIXBUS_TOKEN'), | ||
passphrase: getEnvVar('NIXBUS_PASSPHRASE'), | ||
}) | ||
|
||
while (true) { | ||
const title = `Title ${getTitleId()}` | ||
console.log(`[Publisher] Publishing ${PageViewed.getEventType()}: ${title}`) | ||
await bus.publish( | ||
PageViewed.create({ | ||
title, | ||
}), | ||
) | ||
await new Promise((resolve) => setTimeout(resolve, 250)) | ||
} | ||
} | ||
|
||
let titleId = 1 | ||
function getTitleId(): number { | ||
return titleId++ | ||
} | ||
|
||
main().catch(console.error) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import js from '@eslint/js' | ||
import noRelativeImportPaths from 'eslint-plugin-no-relative-import-paths' | ||
import simpleImportSort from 'eslint-plugin-simple-import-sort' | ||
import unusedImports from 'eslint-plugin-unused-imports' | ||
import globals from 'globals' | ||
import ts from 'typescript-eslint' | ||
|
||
export default [ | ||
js.configs.recommended, | ||
...ts.configs.recommended, | ||
{ | ||
plugins: { | ||
'no-relative-import-paths': noRelativeImportPaths, | ||
'simple-import-sort': simpleImportSort, | ||
'unused-imports': unusedImports, | ||
}, | ||
|
||
languageOptions: { | ||
ecmaVersion: 2022, | ||
globals: { | ||
...globals.browser, | ||
...globals.node, | ||
}, | ||
parserOptions: { | ||
project: true, | ||
}, | ||
sourceType: 'module', | ||
}, | ||
|
||
rules: { | ||
'@typescript-eslint/consistent-type-imports': 'error', | ||
'@typescript-eslint/explicit-module-boundary-types': 'off', | ||
'@typescript-eslint/no-empty-function': 'warn', | ||
'@typescript-eslint/no-explicit-any': 'off', | ||
'@typescript-eslint/no-unused-expressions': 'off', | ||
'@typescript-eslint/no-unused-vars': [ | ||
'error', | ||
{ | ||
argsIgnorePattern: '__', | ||
caughtErrorsIgnorePattern: '__', | ||
}, | ||
], | ||
'@typescript-eslint/no-var-requires': 'off', | ||
'no-relative-import-paths/no-relative-import-paths': 'error', | ||
'no-unused-vars': 'off', | ||
'simple-import-sort/imports': [ | ||
'error', | ||
{ | ||
groups: [ | ||
['^\\u0000'], | ||
['^node:.*\\u0000$', '^node:'], | ||
['^(?!src)@?\\w.*\\u0000$', '^(?!src)@?\\w'], | ||
['^src.*\\u0000$', '^src'], | ||
['(?<=\\u0000)$', '^'], | ||
['^\\..*\\u0000$', '^\\.'], | ||
], | ||
}, | ||
], | ||
'unused-imports/no-unused-imports': 'error', | ||
}, | ||
}, | ||
] |