0.2.11 • Published 3 years ago

@scalecube/scalecube-microservice v0.2.11

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

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

Microservices

This package provides Scalecube's implementation for microservices architecture.

documentation

please Read before starting to work with scalecube.

Usage

import { createMicroservice } from '@scalecube/scalecube-microservice';
import { TransportNodeJS } from '@scalecube/transport-nodejs';
import { joinCluster } from '@scalecube/cluster-nodejs';

const microserviceInstance = createMicroservice({
  services: [/* array of services */],
  seedAddress : 'pm://myOrganization:8080/ServiceA',
  address : 'pm://myOrganization:8080/ServiceB',
  transport: TransportNodeJS, // scalecube provide a default transport configuration when running on browser,
  cluster: joinCluster, // scalecube provide a default cluster configuration when running on browser,
  defaultRouter: retryRouter({period:10}),
  debug: true // default is false
})

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({
  services : [{
    definition: greetingServiceDefinition,
    reference: {
      hello : async (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 creating and using a proxy
// createProxy will return a Proxy(service)
const proxyName = microservice.createProxy({
    serviceDefinition: remoteServiceDefinition
});

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

4 years ago

0.2.9

5 years ago

0.2.8

5 years ago

0.2.2-test.0

5 years ago

0.2.0

5 years ago

0.1.4-next.20

5 years ago

0.1.4-next.19

5 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

6 years ago

0.1.3-alpha.19

6 years ago

0.1.3-alpha.18

6 years ago

0.1.3-alpha.17

6 years ago

0.1.3-alpha.16

6 years ago

0.1.3-alpha.15

6 years ago

0.1.3-alpha.14

6 years ago

0.1.3-alpha.13

6 years ago

0.1.3-alpha.12

6 years ago

0.1.3-alpha.11

6 years ago

0.1.3-alpha.10

6 years ago

0.1.3-alpha.9

6 years ago

0.1.3-alpha.8

6 years ago

0.1.3-alpha.7

6 years ago

0.1.3-alpha.6

6 years ago

0.1.3-alpha.5

6 years ago

0.1.3-alpha.4

6 years ago

0.1.3-alpha.3

6 years ago

0.1.3-alpha.2

6 years ago

0.1.3-alpha.1

6 years ago

0.1.3-alpha.0

6 years ago

0.1.2

6 years ago

0.1.2-alpha.2

6 years ago

0.1.2-alpha.92

6 years ago

0.1.2-alpha.1

6 years ago

0.1.2-alpha.0

6 years ago

0.1.1

6 years ago