2.0.1 • Published 5 years ago
rpc1-socket v2.0.1
Bindings
Why
Install
Yarn
Example
Local
createBroker(broker => {
// Add a local service
broker.local('calculator', service => {
service.addMethod('multiply', (x1, x2) => x1 * x2);
});
// Add a local client
broker.client(async client => {
const service = client.use('calculator');
try {
console.log(await service.multiply(2, 3));
} catch (err) {
console.log(err);
}
});
});
Socket
const port = 9999;
createBroker(
broker => {
console.log('Broker is listening');
},
{
plugins: [
pluginSocketBroker({
port
})
]
}
);
// Add a remote service
createSocketService('calculator', 'http://localhost:9999', service => {
service.addMethod('multiply', (x1, x2) => x1 * x2);
});
// Add a remote client
createSocketClient('http://localhost:9999', async client => {
const service = client.use('local-calculator');
try {
console.log(await service.multiply(2, 3));
} catch (err) {
console.log(err);
}
});
React
export default () => {};