This package can be used to call any service on Micro.
Please also check the typesafe autogenerated APIs for your Micro services, you might find them more pleasant to use.
Installation:
npm install --save @microhq/node-client
Assuming you have the helloworld service running locally (do micro run github.com/micro/examples/helloworld
):
const { Client } = require("@microhq/node-client");
new Client({local: true}).call("helloworld", "Helloworld.Call", {"name": "John"}).then(response => {
console.log(response)
})
The output will be:
{ msg: 'Hello John' }
You can also connect to your local micro installation:
new Client({local: true})
If you want to change the address, assuming you run the client api:
new Client({address: "https://api.mydomain.com/client"})
const client = require("@microhq/node-client")
new client.Client().stream("go.micro.srv.asim", "Asim.Stream", {"count": 10}).then(stream => {
stream.recv(msg => {
console.log("message received: ", msg)
})
}).catch(e => {
console.log(e)
})
setInterval(() => {}, 5000);
Above example will output:
message received: {}
message received: {"count":"1"}
message received: {"count":"2"}
message received: {"count":"3"}
message received: {"count":"4"}
message received: {"count":"5"}
message received: {"count":"6"}
message received: {"count":"7"}
message received: {"count":"8"}
message received: {"count":"9"}