This is part of scalecube-js project, see more at https://github.com/scalecube/scalecube-js
Full documentation
Microservices-browser
This package provides Scalecube's solution with default setting for working in node.
Usage
yarn add @scalecube/node
or npm i @scalecube/node
import { createMicroservice, ASYNC_MODEL_TYPES } from '@scalecube/node';
create a seed
export const MySeedAddress: 'ws://localhost:8000';
createMicroservice({
address : MySeedAddress
});
Create a service
export const greetingServiceDefinition = {
serviceName: 'GreetingService',
methods: {
hello: {
asyncModel: ASYNC_MODEL_TYPES.REQUEST_RESPONSE,
}
},
};
createMicroservice({
service : [{
definition: greetingServiceDefinition,
reference: {
hello : (name) => `Hello ${name}`
},
}],
seedAddress : MySeedAddress,
address : 'ws://localhost:8001'
});
Use a service
const microservice = createMicroservice({
seedAddress : MySeedAddress,
address : 'ws://localhost:8002'
})
const greetingService = microservice.createProxy({
serviceDefinition: greetingServiceDefinition
});
greetingService.hello('ME').then(console.log)
Dependency Injection
createMicroservice({
seedAddress : MySeedAddress,
address : 'ws://localhost:8003',
services: [
{
definition: serviceB,
reference: ({ createProxy, createServiceCall }) => {
const greetingService = createProxy({serviceDefinition: greetingServiceDefinition });
return new ServiceB(greetingService);
}
}
]
})
documentation
please Read before starting to work with scalecube.