Skip to content

Latest commit

 

History

History
56 lines (43 loc) · 1.71 KB

File metadata and controls

56 lines (43 loc) · 1.71 KB

Join the chat at https://gitter.im/scalecube-js/Lobby

This is part of scalecube-js project, see more at https://github.com/scalecube/scalecube-js
Full documentation

rsocket-websocket-gateway

This package provides gateway implementation for NodeJS based on rsocket websocket

API

interface Gateway {
  constructor(options: {port: number, requestResponse?: RequestHandler, requestStream?: RequestHandler});
  start: (options: { serviceCall: ServiceCall }) => void;
  stop: () => void;
}

Usage

Server side

import { createMicroservice } from '@scalecube/scalecube-microservice';
import { Gateway } from '@scalecube/rsocket-ws-gateway';

const definition = {
  serviceName: 'serviceA',
  methods: {
    methodA: { asyncModel: ASYNC_MODEL_TYPES.REQUEST_RESPONSE },
  },
};
const reference = { methodA: () => Promise.resolve('ok') };
const services = [{ definition, reference }];
const ms = createMicroservice({ services });
const serviceCall = ms.createServiceCall({});
const gateway = new Gateway({ port: 3000 });
gateway.start({ serviceCall });

Client side

import { createGatewayProxy } from '@scalecube/rsocket-ws-gateway/dist/createGatewayProxy';


const definition = {
  serviceName: 'serviceA',
  methods: {
    methodA: { asyncModel: ASYNC_MODEL_TYPES.REQUEST_RESPONSE },
  },
};
  const proxy = await createGatewayProxy('ws://localhost:3000', definition);
  const resp = await proxy.methodA() // => 'ok'