1.0.0 • Published 1 year ago

@infini-pattern/service v1.0.0

Weekly downloads
-
License
MIT
Repository
github
Last release
1 year ago

Microservice

The Microservice interface and MicroserviceMetadata type provide a way to represent a microservice and its metadata in TypeScript.

Installation

To use the Microservice interface and MicroserviceMetadata type in your project, you can install them as dependencies:

npm install @types/microservice

Usage

To use the Microservice interface and MicroserviceMetadata type, you can import them in your code:

import { Microservice, MicroserviceMetadata } from '@types/microservice'

The MicroserviceMetadata type represents the metadata for a microservice, including its unique identifier, name, description, and uptime.

const metadata: MicroserviceMetadata = {
  id: '12345',
  name: 'My Microservice',
  description: 'This is a simple microservice that returns a greeting.',
  uptime: 0,
};

The Microservice interface represents a microservice and defines three methods: start(), stop(), and getStatus().

class MyMicroservice implements Microservice {
  metadata: MicroserviceMetadata;

  constructor(metadata: MicroserviceMetadata) {
    this.metadata = metadata;
  }

  start(): void {
    // Start the microservice
  }

  stop(): void {
    // Stop the microservice
  }

  getStatus(): string {
    // Return the current status of the microservice
  }
}

You can then create an instance of your microservice and start it:

const microservice = new MyMicroservice(metadata);
microservice.start();

Contributing

To contribute to the Microservice interface and MicroserviceMetadata type, you can submit a pull request on GitHub. Please make sure to follow the code style guidelines and include appropriate tests for your changes.

License

The Microservice interface and MicroserviceMetadata type are released under the MIT license. See LICENSE for more information.