0.1.4-alpha.1572516199.3 • Published 6 years ago

@scalecube/scalecube-microservice v0.1.4-alpha.1572516199.3

Weekly downloads
706
License
MIT
Repository
-
Last release
6 years ago

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

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

Microservices

This package provides Scalecube's implementation for microservices architecture.

Usage

Define a service

import { ASYNC_MODEL_TYPES } from '@scalecube/scalecube-microservice';

export const greetingServiceDefinition = {
  serviceName: 'GreetingService',
  methods: { 
    hello: {
      asyncModel: ASYNC_MODEL_TYPES.REQUEST_RESPONSE,
    }
  },
};

Create a service

import { createMicroservice } from '@scalecube/scalecube-microservice';
import { greetingServiceDefinition } from './definitions';

createMicroservice({
  service : [{
    definition: greetingServiceDefinition,
    reference: {
      hello : (name) => `Hello ${name}`
    }, 
   }],
   address : 'seed'
});
example of working with dependencies
import { createMicroservice } from '@scalecube/scalecube-microservice';
import { greetingServiceDefinition } from './definitions';

createMicroservice({
  service : [{
    definition: greetingServiceDefinition,
    reference: ({ createProxy, createServiceCall }) => {
      // callback response with createProxy or createServiceCall
      // it is possible to inject the proxy/serviceCall to the service
      const proxy = createProxy({ serviceDefinition: remoteServiceDefinition});
      return new GreetingService(proxy);
    }
   }],
   address : 'seed'
});

Use the service

import { createMicroservice } from '@scalecube/scalecube-microservice';

const microservice = createMicroservice({
  address : 'ms1',
  seedAddress : 'seed'
});
example of resolving the proxy only when the service is available
// createProxies will return a map of <proxyName: Promise<Proxy(service)>>
// this way we are able to request for multiple proxies in 1 function.
const { awaitProxyName } = microservice.createProxies({
      proxies: [{
          serviceDefinition: remoteServiceDefinition,
          proxyName: 'awaitProxyName',
        },
      ],
      isAsync: true,
});

awaitProxyName.then(({proxy}) => {
  proxy.hello('ME').then(console.log) // Hello ME
});
example of resolving the proxy immediately
// isAsync: false so createProxies will return a map of <proxyName: Proxy(service)>
// this way we are able to request for multiple proxies in 1 function.
// in this example we are not sure if the service is available to use.
const { proxyName } = microservice.createProxies({
      proxies: [{
          serviceDefinition: remoteServiceDefinition,
          proxyName: 'proxyName',
        },
      ],
      // isAsync: false, 
});

proxyName.hello('ME').then(console.log) // Hello ME
example of resolving the single proxy immediately
// createProxy will return a Proxy(service)
// in this example we are not sure if the service is available to use.
const { proxyName } = microservice.createProxy({
    serviceDefinition: remoteServiceDefinition
});

proxyName.hello('ME').then(console.log) // Hello ME
0.2.11

4 years ago

0.2.9

6 years ago

0.2.8

6 years ago

0.2.2-test.0

6 years ago

0.2.0

6 years ago

0.1.4-next.20

6 years ago

0.1.4-next.19

6 years ago

0.1.4-next.18

6 years ago

0.1.4-next.17

6 years ago

0.1.4-next.16

6 years ago

0.1.4-next.15

6 years ago

0.1.4-next.14

6 years ago

0.1.4-next.13

6 years ago

0.1.4-next.12

6 years ago

0.1.4-next.11

6 years ago

0.1.4-next.10

6 years ago

0.1.4-next.9

6 years ago

0.1.4-next.8

6 years ago

0.1.4-next.7

6 years ago

0.1.4-next.6

6 years ago

0.1.4-next.5

6 years ago

0.1.4-next.4

6 years ago

0.1.4-next.3

6 years ago

0.1.4-next.2

6 years ago

0.1.4-next.1

6 years ago

0.1.4-next.0

6 years ago

0.1.3-next.2

6 years ago

0.1.3-next.1

6 years ago

0.1.3-next.0

6 years ago

0.1.3-alpha.36

6 years ago

0.1.3-alpha.35

6 years ago

0.1.3-alpha.34

6 years ago

0.1.3-alpha.33

6 years ago

0.1.3-alpha.32

6 years ago

0.1.3-alpha.31

6 years ago

0.1.3-alpha.30

6 years ago

0.1.3-alpha.29

6 years ago

0.1.3-alpha.28

6 years ago

0.1.3-alpha.27

6 years ago

0.1.3-alpha.26

6 years ago

0.1.3-alpha.25

6 years ago

0.1.3-alpha.24

6 years ago

0.1.3-alpha.23

6 years ago

0.1.3-alpha.22

6 years ago

0.1.3-alpha.21

6 years ago

0.1.3-alpha.20

7 years ago

0.1.3-alpha.19

7 years ago

0.1.3-alpha.18

7 years ago

0.1.3-alpha.17

7 years ago

0.1.3-alpha.16

7 years ago

0.1.3-alpha.15

7 years ago

0.1.3-alpha.14

7 years ago

0.1.3-alpha.13

7 years ago

0.1.3-alpha.12

7 years ago

0.1.3-alpha.11

7 years ago

0.1.3-alpha.10

7 years ago

0.1.3-alpha.9

7 years ago

0.1.3-alpha.8

7 years ago

0.1.3-alpha.7

7 years ago

0.1.3-alpha.6

7 years ago

0.1.3-alpha.5

7 years ago

0.1.3-alpha.4

7 years ago

0.1.3-alpha.3

7 years ago

0.1.3-alpha.2

7 years ago

0.1.3-alpha.1

7 years ago

0.1.3-alpha.0

7 years ago

0.1.2

7 years ago

0.1.2-alpha.2

7 years ago

0.1.2-alpha.92

7 years ago

0.1.2-alpha.1

7 years ago

0.1.2-alpha.0

7 years ago

0.1.1

7 years ago