Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature/decoupling-rsocket-transport #223

Merged
merged 11 commits into from Dec 5, 2019
1 change: 1 addition & 0 deletions packages/api/src/microservice/Microservice.ts
@@ -1,5 +1,6 @@
import { Address } from '../index';
import { Cluster, ClusterOptions } from '../cluster';
import { Transport } from '../transport';
import { CreateProxy, CreateServiceCall, Router, Service } from '.';

/**
Expand Down
40 changes: 0 additions & 40 deletions packages/api/src/transport/Provider.ts

This file was deleted.

13 changes: 0 additions & 13 deletions packages/api/src/transport/ProviderFactory.ts

This file was deleted.

102 changes: 85 additions & 17 deletions packages/api/src/transport/Transport.ts
@@ -1,32 +1,100 @@
import { Provider } from '.';
import { Address } from '../index';
import { Message } from '../microservice';
import { Observable } from 'rxjs';

/**
* @interface Provider
* @interface Transport
*
*/
export default interface Transport {
export interface Transport {
/**
* @property
* transport provider for the client
* transport layer for the client
*/
clientProvider: Provider;
clientTransport: ClientTransport;
/**
* @property
* transport provider for the server
* transport layer for the server
*/
serverProvider: Provider;
serverTransport: ServerTransport;
}

export interface ClientTransport {
/**
* @property start
* start transport client
*/
start: (options: ClientTransportOptions) => Promise<RequestHandler>;
/**
* @method destroy
* remove open connection to a specific microserivce container
*/
destroy: TDestroy;
}

export type ServerTransport = (options: ServerTransportOptions) => ServerStop;

export interface ClientTransportOptions {
/**
* @property remoteAddress
* address of the remote microservice that contain the service we want to execute.
*/
remoteAddress: Address;
/**
* @method logger
* add logs to scalecube eco-system
*/
logger: TLogger;
}

/**
* @interface ServerTransportOptions
*/
export interface ServerTransportOptions {
/**
* @property localAddress
* address this microservice container.
*/
localAddress: Address;
/**
* @property serviceCall
* callback for handling the request
*/
serviceCall: RequestHandler;
/**
* @method logger
* add logs to scalecube eco-system
*/
logger: TLogger;
}

/**
* PayloadSerializers - https://github.com/rsocket/rsocket-js/blob/master/packages/rsocket-core/src/RSocketSerialization.js
* @interface RequestHandler
*/
export interface PayloadSerializers {
data: {
deserialize: (data: any) => any;
serialize: (data: any) => any;
};
metadata: {
deserialize: (data: any) => any;
serialize: (data: any) => any;
};
export interface RequestHandler {
/**
* @method requestResponse
* @message - data to pass in the request
*/
requestResponse: (message: Message) => Promise<any>;
/**
* @method requestStream
* @message - data to pass in the request
*/
requestStream: (message: Message) => Observable<any>;
}

/**
* @method destroy
* remove all open connections of this microservice container
*/
export type ServerStop = () => void;

export type TLogger = (msg: any, type: 'warn' | 'log') => void;

export type TDestroy = ({ address, logger }: TDestroyOptions) => void;

export interface TDestroyOptions {
address: string;
logger: TLogger;
}
18 changes: 12 additions & 6 deletions packages/api/src/transport/index.ts
@@ -1,6 +1,12 @@
import Transport from './Transport';
import Provider from './Provider';
import { ProviderFactory } from './ProviderFactory';
import { Address } from '..';

export { Address, Transport, Provider, ProviderFactory };
export {
ServerTransportOptions,
ClientTransportOptions,
RequestHandler,
Transport,
ServerStop,
ClientTransport,
ServerTransport,
TDestroy,
TLogger,
TDestroyOptions,
} from './Transport';
2 changes: 1 addition & 1 deletion packages/browser/rollup.cjs.config.js
Expand Up @@ -19,14 +19,14 @@ export default {
],
external: ['rxjs'],
plugins: [
resolve({ jsnext: true, main: true }),
commonjs({
include: /node_modules/,
browser: true,
namedExports: {
'rsocket-types': ['CONNECTION_STATUS'],
},
}),
resolve(),
babel({
plugins: ['@babel/plugin-transform-arrow-functions'],
babelrc: false,
Expand Down
5 changes: 1 addition & 4 deletions packages/browser/rollup.iife.config.js
Expand Up @@ -20,14 +20,11 @@ export default {
},
],
plugins: [
resolve({ jsnext: true, main: true }),
commonjs({
include: /node_modules/,
browser: true,
namedExports: {
'rsocket-types': ['CONNECTION_STATUS'],
},
}),
resolve(),
babel({
plugins: ['@babel/plugin-transform-arrow-functions'],
babelrc: false,
Expand Down
5 changes: 2 additions & 3 deletions packages/browser/src/index.ts
@@ -1,6 +1,6 @@
import { MicroserviceApi } from '@scalecube/api';
import { createMicroservice as msCreate, ASYNC_MODEL_TYPES } from '@scalecube/scalecube-microservice';
import { TransportBrowser } from '@scalecube/transport-browser';
import { transport } from '@scalecube/transport-browser';
import { joinCluster } from '@scalecube/cluster-browser';
import { retryRouter } from '@scalecube/routers';
import { workers, getAddress as stringToAddress } from '@scalecube/utils';
Expand All @@ -9,8 +9,7 @@ export { ASYNC_MODEL_TYPES, workers, stringToAddress };

export const createMicroservice: MicroserviceApi.CreateMicroservice = (config: any) => {
return msCreate({
// @ts-ignore
transport: TransportBrowser,
transport,
cluster: joinCluster,
defaultRouter: retryRouter({ period: 10, maxRetry: 500 }),
...config,
Expand Down
4 changes: 2 additions & 2 deletions packages/node/src/index.ts
@@ -1,6 +1,6 @@
import { MicroserviceApi } from '@scalecube/api';
import { createMicroservice as msCreate, ASYNC_MODEL_TYPES } from '@scalecube/scalecube-microservice';
import { TransportNodeJS } from '@scalecube/transport-nodejs';
import { transport } from '@scalecube/transport-nodejs';
import { joinCluster } from '@scalecube/cluster-nodejs';
import { roundRobin } from '@scalecube/routers';
import { getAddress as stringToAddress } from '@scalecube/utils';
Expand All @@ -9,7 +9,7 @@ export { ASYNC_MODEL_TYPES, stringToAddress };

export const createMicroservice: MicroserviceApi.CreateMicroservice = (config: any) => {
return msCreate({
transport: TransportNodeJS,
transport,
cluster: joinCluster,
defaultRouter: roundRobin,
...config,
Expand Down
7 changes: 7 additions & 0 deletions packages/rsocket-adapter/.gitignore
@@ -0,0 +1,7 @@
.cache
node_modules

es/
cjs/

report.html
7 changes: 7 additions & 0 deletions packages/rsocket-adapter/README.md
@@ -0,0 +1,7 @@
[![Join the chat at https://gitter.im/scalecube-js/Lobby](https://badges.gitter.im/scalecube-js/Lobby.svg)](https://gitter.im/scalecube-js/Lobby?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)

> **NOTICE** versions 0.0.x are experimental without LTS or the API and behavior might change from patch to patch

# rsocke-transport

This package serves as RSocket Transport provider
9 changes: 9 additions & 0 deletions packages/rsocket-adapter/jest.config.js
@@ -0,0 +1,9 @@
module.exports = {
transform: {
'.(ts|tsx)': 'ts-jest',
},
testRegex: '(\\.|/)spec\\.ts$',
testPathIgnorePatterns: ['<rootDir>/es/', '<rootDir>/lib/', '<rootDir>/node_modules/'],
moduleFileExtensions: ['ts', 'tsx', 'js'],
moduleDirectories: ['node_modules', 'app/src'],
};
41 changes: 41 additions & 0 deletions packages/rsocket-adapter/package.json
@@ -0,0 +1,41 @@
{
"name": "@scalecube/rsocket-adapter",
"version": "0.0.1",
"private": false,
"main": "cjs/index.js",
"module": "es/index.js",
"types": "cjs/index.d.ts",
"files": [
"cjs",
"es"
],
"license": "MIT",
"scripts": {
"clean": "rimraf node_modules && rimraf .cache && rimraf lib && rimraf es",
"build": "yarn build-rollup && tsc",
"build-rollup": "rollup -c",
"lint": "tslint '{src,tests}/**/*.{ts,tsx}' --fix",
"prettier": "prettier --write '{src,tests}/**/*.{ts,tsx}'",
"test": "jest --config jest.config.js"
},
"author": "Scalecube (https://github.com/scalecube/scalecube-js)",
"devDependencies": {
"jest": "^24.6.0",
"rollup": "^1.14.6",
"rollup-plugin-commonjs": "^10.0.1",
"rollup-plugin-filesize": "^6.1.1",
"rollup-plugin-typescript2": "^0.21.1",
"rollup-plugin-visualizer": "^2.2.0",
"ts-jest": "^24.2.0",
"tslint": "^5.11.0",
"typescript": "^3.2.4"
},
"dependencies": {
"@scalecube/api": "^0.0.3-next.4",
"@scalecube/utils": "^0.0.3-next.8",
"rsocket-core": "^0.0.16",
"rsocket-flowable": "^0.0.14",
"rsocket-types": "^0.0.16",
"rxjs": "^6.4.0"
}
}
32 changes: 32 additions & 0 deletions packages/rsocket-adapter/rollup.config.js
@@ -0,0 +1,32 @@
import visualizer from 'rollup-plugin-visualizer';
import typescript from 'rollup-plugin-typescript2';
import filesize from 'rollup-plugin-filesize';
import pkg from './package.json';
import commonjs from 'rollup-plugin-commonjs';

export default {
input: 'src/index.ts',
output: [
{
file: pkg.main,
format: 'cjs',
},
],
external: ['@scalecube/api', '@scalecube/utils', 'rxjs'],
plugins: [
commonjs({
namedExports: {
'rsocket-types': ['CONNECTION_STATUS'],
},
}),
typescript({
typescript: require('typescript'),
clean: true,
}),
visualizer({
filename: 'report.html',
title: 'rsocket-adapter',
}),
filesize(),
],
};