2.7.15 • Published 4 years ago

@tutorbot/microservice v2.7.15

Weekly downloads
34
License
ISC
Repository
-
Last release
4 years ago

@tutorbot/microservice

The toolkit for build microservices in tutorbot's ecosystem.

yarn add @tutorbot/microservice

start local pub/sub

$ gcloud beta emulators pubsub start $ DATASTORE_EMULATOR_HOST=localhost:8432 DATASTORE_PROJECT_ID=my-project-id gcloud beta emulators datastore start

example1.js

const { registerSubscriber, publish } = require("@tutorbot/microservice");

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);

PUBSUB_EMULATOR_HOST="localhost:8085" PUBSUB_PROJECT_ID="my-project-id" GCLOUD_PROJECT="my-project-id" node example1.js

example2.js

const { publish, subscribeMulti } = require("@tutorbot/microservice");


function subscribe1() {
    subscribeMulti("test", ["dev.test", "dev.test.other"], async (topic, data) => {
        console.log('\x1b[31m%s %s\x1b[0m', " 1 ", topic, data);
    });
}

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);

PUBSUB_EMULATOR_HOST="localhost:8085" PUBSUB_PROJECT_ID="my-project-id" GCLOUD_PROJECT="my-project-id" node example2.js

example3.js

import { autoStart as AutoStart, subscribe as on, publish } from "@tutorbot/microservice";

@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);

PUBSUB_EMULATOR_HOST="localhost:8085" PUBSUB_PROJECT_ID="my-project-id" GCLOUD_PROJECT="my-project-id" node example3.js

run all examples with env variables PUBSUB_EMULATOR_HOST="localhost:8085" PUBSUB_PROJECT_ID="my-project-id" GCLOUD_PROJECT="my-project-id"

2.7.15

4 years ago

2.7.14

5 years ago

2.7.13

5 years ago

2.7.12

5 years ago

2.7.11

5 years ago

2.7.9

5 years ago

2.7.10

5 years ago

2.7.8

5 years ago

2.7.7

5 years ago

2.7.6

5 years ago

2.7.5

5 years ago

2.7.4

5 years ago

2.7.3

5 years ago

2.7.2

5 years ago

2.7.1

5 years ago

2.7.0

5 years ago

2.6.0

5 years ago

2.5.0

6 years ago

2.4.1

6 years ago

2.4.0

6 years ago

2.3.0

6 years ago

2.2.0

6 years ago

2.1.1

6 years ago

2.1.0

6 years ago

2.0.1

6 years ago

2.0.0

6 years ago

1.5.1

6 years ago

1.5.0

6 years ago

1.4.2

7 years ago

1.4.1

7 years ago

1.4.0

7 years ago

1.3.14

7 years ago

1.3.13

7 years ago

1.3.12

7 years ago

1.3.11

7 years ago

1.3.10

7 years ago

1.3.9

7 years ago

1.3.8

7 years ago

1.3.7

7 years ago

1.3.6

7 years ago

1.3.5

7 years ago

1.3.4

7 years ago

1.3.3

7 years ago

1.3.2

7 years ago

1.3.1

7 years ago

1.3.0

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.2

7 years ago

1.1.1

7 years ago

1.1.0

7 years ago

1.0.11

7 years ago

1.0.10

7 years ago

1.0.9

7 years ago

1.0.8

7 years ago

1.0.7

7 years ago

1.0.6

7 years ago

1.0.5

7 years ago

1.0.4

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago