Socket
Socket
Sign inDemoInstall

@dasmeta/event-manager-node-api

Package Overview
Dependencies
Maintainers
3
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@dasmeta/event-manager-node-api - npm Package Compare versions

Comparing version 2.0.0 to 2.1.1

example1.js

25

package.json
{
"name": "@dasmeta/event-manager-node-api",
"version": "2.0.0",
"version": "2.1.1",
"description": "Extended event publishing PubSub/Kafka package.",
"main": "./dist/index.js",
"typings": "./dist/index.d.ts",
"main": "src/index.js",
"private": false,
"scripts": {
"build": "tsc --outDir dist/",
"prepublishOnly": "yarn build"
"start": "node src/index.js",
"test": "echo 'ok'",
"prettier": "prettier --write 'src/**/*.js'",
"kafkaExample1": "MQ_CLIENT_NAME='Kafka' KAFKA_BROKERS='127.0.0.1:29092' node example1.js",
"kafkaExample2": "MQ_CLIENT_NAME='Kafka' KAFKA_BROKERS='127.0.0.1:29092' node example2.js",
"PubSubExample1": "PUBSUB_EMULATOR_HOST='localhost:8085' PUBSUB_PROJECT_ID='YOUR_GCLOUD_PROJECT_ID' GCLOUD_PROJECT='YOUR_GCLOUD_PROJECT_ID' node example1.js",
"PubSubExample2": "PUBSUB_EMULATOR_HOST='localhost:8085' PUBSUB_PROJECT_ID='YOUR_GCLOUD_PROJECT_ID' GCLOUD_PROJECT='YOUR_GCLOUD_PROJECT_ID' node example2.js"
},
"dependencies": {
"axios": "^0.21.1"
"@bugsnag/js": "^6.4.0",
"@google-cloud/pubsub": "^2.5.0",
"amqplib": "^0.8.0",
"kafkajs": "^1.15.0",
"mongodb": "^3.3.2",
"uuid": "^3.3.3"
},
"devDependencies": {
"@types/node": "^12.11.5",
"typescript": "^3.6.4"
"prettier": "^1.18.2"
},

@@ -18,0 +27,0 @@ "keywords": [

@@ -1,45 +0,125 @@

## @
# @dasmeta/microservice #
This generator creates TypeScript/JavaScript client that utilizes [axios](https://github.com/axios/axios). The generated Node module can be used in the following environments:
Extended event publishing PubSub/Kafka package.
Environment
* Node.js
* Webpack
* Browserify
`yarn add @dasmeta/event-manager-node-api`
Language level
* ES5 - you must have a Promises/A+ library installed
* ES6
### start local pub/sub
Module system
* CommonJS
* ES6 module system
`$ gcloud beta emulators pubsub start`
`$ DATASTORE_EMULATOR_HOST=localhost:8432 DATASTORE_PROJECT_ID=YOUR_GCLOUD_PROJECT_ID gcloud beta emulators datastore start`
It can be used in both TypeScript and JavaScript. In TypeScript, the definition should be automatically resolved via `package.json`. ([Reference](http://www.typescriptlang.org/docs/handbook/typings-for-npm-packages.html))
### Building
To build and compile the typescript sources to javascript use:
#### example1.js
```
npm install
npm run build
const { registerSubscriber, publish } = require("@dasmeta/event-manager-node-api");
async function test1(data) {
console.log("test1", data);
}
async function test2(data) {
console.log("test2", data);
}
async function test3(data) {
console.log("test3", data);
}
registerSubscriber("dev.test", "dev-test_test1", test1);
registerSubscriber("dev.test", "dev-test_test2", test2);
registerSubscriber("dev.test.other", "dev-test_test3", test3);
setInterval(async () => {
await publish("dev.test", { key: Date.now() });
}, 300);
setInterval(async () => {
await publish("dev.test.other", { key2: Date.now() });
}, 500);
```
### Publishing
`PUBSUB_EMULATOR_HOST="localhost:8085" PUBSUB_PROJECT_ID="YOUR_GCLOUD_PROJECT_ID" GCLOUD_PROJECT="YOUR_GCLOUD_PROJECT_ID" node example1.js`
First build the package then run ```npm publish```
#### example2.js
```
const { publish, subscribeMulti } = require("@dasmeta/event-manager-node-api");
### Consuming
navigate to the folder of your consuming project and run one of the following commands.
function subscribe1() {
subscribeMulti("test", ["dev.test", "dev.test.other"], async (topic, data) => {
console.log('\x1b[31m%s %s\x1b[0m', " 1 ", topic, data);
});
}
_published:_
function subscribe2() {
// resubscribe
subscribeMulti("test", ["dev.test"], async (topic, data) => {
console.log('\x1b[32m%s %s\x1b[0m', " 2 ", topic, data);
});
subscribeMulti("test3", ["dev.test", "dev.test.other"], async (topic, data) => {
console.log('\x1b[33m%s %s\x1b[0m', " 3 ", topic, data);
});
}
setInterval(async () => {
await publish("dev.test", { key: Date.now() });
}, 200);
setInterval(async () => {
await publish("dev.test.other", { key2: Date.now() });
}, 300);
subscribe1();
setTimeout(async () => {
subscribe2();
}, 20 * 1000);
```
npm install @ --save
`PUBSUB_EMULATOR_HOST="localhost:8085" PUBSUB_PROJECT_ID="YOUR_GCLOUD_PROJECT_ID" GCLOUD_PROJECT="YOUR_GCLOUD_PROJECT_ID" node example2.js`
#### example3.js
```
import { autoStart as AutoStart, subscribe as on, publish } from "@dasmeta/event-manager-node-api";
_unPublished (not recommended):_
@AutoStart
class Example {
@on("dev.test")
async test1(data) {
console.log("test1", data);
}
@on("dev.test")
async test2(data) {
console.log("test2", data);
}
@on("dev.test.other")
async test3(data) {
console.log("test3", data);
}
}
setInterval(async () => {
await publish("dev.test", { key: Date.now() });
}, 300);
setInterval(async () => {
await publish("dev.test.other", { key2: Date.now() });
}, 500);
```
npm install PATH_TO_GENERATED_PACKAGE --save
`PUBSUB_EMULATOR_HOST="localhost:8085" PUBSUB_PROJECT_ID="YOUR_GCLOUD_PROJECT_ID" GCLOUD_PROJECT="YOUR_GCLOUD_PROJECT_ID" node example3.js`
#### Kafka : run all examples with env variables
`MQ_CLIENT_NAME='Kafka' KAFKA_BROKERS='127.0.0.1:29092'`
#### PubSub : run all examples with env variables
`PUBSUB_EMULATOR_HOST="localhost:8085" PUBSUB_PROJECT_ID="YOUR_GCLOUD_PROJECT_ID" GCLOUD_PROJECT="YOUR_GCLOUD_PROJECT_ID"`

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc