Expressive Tea Logo

We are excited to announce the release of Expressive Tea 1.3 Beta! This release includes many significant new features, microservices, and performance improvements and not breaking changes.


Installation.

This version will be retro-compatible with the current production version 1.2.x and will allow you to move on to the beta version without any issue; however, as this is a beta version, some changes will still apply and could break your current projects in the future, please be aware.

with npm.

npm install --save @zerooneit/expressive-tea@next

with yarn.

yarn add @zerooneit/expressive-tea@next

Microservices For The Win.

Starting from this version and so on, Expressive Tea supports microservices; this will be possible by introducing two new decorators @Teapot and @Teacup. Expressive Tea takes simplicity so seriously that you will need to set up your configurations per every Teacup (microservices client), and Teapot (microservices host) will take care of everything for you, it will verify that every Teacup belongs to the implementation of the microservices network by providing an encrypted handshake and verification by using a private and public key.

Once you configure your servers with the decorators mentioned (will explain in detail below), the primary server or “Teapot” will validate, register, and auto-setting the microservice net even in runtime.

Teapot

Teapot is an entity that allows an Expressive Tea’s projects converts automatically in a microservice gateway for one or more other Expressive Tea projects configured as Teacup. You can do this by adding the decorator @Teapot into the Bootstrap class; the only parameters required to set up are serverKey and clientKey needed to secure and register Teacups, settings example on the code down below.

@Pour(ExpressPlugin)
@Static('./public')
@ServerSettings({
  port: 8084,
})

@Teapot({
  serverKey: '3xcJXjgNwe6yNxkx7F0/QzPmEgu7WkLBUrPwB2+G8/4=',
  clientKey: '2piAM0vUyIGZMJZpW1TIC7/hpX3gYwufTv11kpVviyE='
})
class Bootstrap extends Boot {
  @RegisterModule(RootModule)
  async start(): Promise<ExpressiveTeaApplication> {
    return super.start();
  }
}
  • Teacups will register automatically at the boot or runtime stage, which means you will not have to worry about restarting or rebooting your main gateway and can handle the new incoming Teacups dynamically. 
  • Every income Teacup will be a sure test to register in the Teapot by comparing the client key; all the handshake process is encrypted between Teapot and Teacups, and if the handshake fails, Teacups disconnect from Teapot.
  • For two or more Teacups that register under the same endpoint, Teapot will create a Round Robin Load Balancer to keep requests balanced between Teacups.
  • If a Teacup for a reason disconnects from Teapot, it will automatically remove it in one of the following cases. If Teacup is the only one registered response, it will be 404; if the Teacup is on a Load Balancer, it will remove it and recreate it with the current Teacup.

Teacup

Teacup is an entity that allows Expressive Tea projects to be used as microservice clients and receive a request from Teapot gateway. Registration and validations will be taken care of by gateway; if the client key is not assigned, it will not register. Once registered after assurances, it will receive a request from Teapot Gateway when the user points to the endpoint registered by Teacup. However, if a Teacup is part of a group of Expressive Tea instances on the same endpoint, it will defer the request to the Round Robin on the Teapot side. To set up, a Teacup @Teacup decorator needs to be used in the bootstrap class and will require four settings.

  1. clientKey: A string value that contains the client key defined by the Teapot creation.
  2. serverUrl: The IP or Named address to in teapot string url format (teapot://<address>[:port]/teapot)
  3. address: The URL.
  4. mountTo: The endpoint where Teapot should proxy the request to the Teacup.
@Teacup({
  clientKey: '2piAM0vUyIGZMJZpW1TIC7/hpX3gYwufTv11kpVviyE=',
  serverUrl: `teapot://example-teapot.com/teapot`,
  address: 'http://example-teacup.com',
  mountTo: '/teacup-1'
})
class Bootstrap extends Boot {
  @RegisterModule(TeacupModule)
  async start(): Promise<ExpressiveTeaApplication> {
    return super.start();
  }
}

Tea CLI

Warning

Tea CLI is on development, yet the command presented here should change by the time being, make sure to follow the documentation and update constantly.

Tea CLI received another upgrade to allow the server key and client key to add them to the Teapot and Teacup configuration to use it install and use.

Install.

npm install -g @expressive-tea/tea

Update.

npm update -g @expressive-tea/tea

Usage.

To use you can use the below example:

~
❯ tea teapod-secret
Welcome to TEA a CLI tool for Expressive Tea applications.

             ;,'
     _o_    ;:;'
 ,-.'---`.__ ;
((j`=====',-'
 `-\     /
    `-=-'



Generating Teapod and Teacup Key.

Server Key : faB8yp7h1VpFJg3YLeFprzPqYrkc
Clients Key: ScqtXNhsRFNNr8S8AwBz+rDAtcZL
Salt: 23cfdfc02be222691c1c217b323e1dd332387e9df9

CAUTION:
All keys generated here are unique, please store them in a secure place and avoid to make it public..

Providers in Module are optional.

Under Module declaration, the “providers” property are mandatory, even if you are not used. On this version, we flag the “providers” property to be optional, so instead to declare the module as:

@Module({
  controllers: [RootController],
  providers: [],
  mountpoint: '/'
})
export default class RootModule {
}

now you can declared as:

@Module({
  controllers: [RootController],
  mountpoint: '/'
})
export default class RootModule {
}

Better Typing and Interfaces.

We work on this version to provide Types and Interfaces to the developers that want to contribute to our project; this means we made some internal refactoring to increase code readability, types check and interfaces implementation to avoid errors when coding, so in this case, if there is someone new in the project will be understood quickly.

Upgraded dependencies.

We updated our base dependencies to the last compatible version to the current code to avoid errors and security breaches and give the users peace of mind; these recommendations come from Snyk and dependabot in Github.

Cleaner Code.

We made a refactoring to start to remove some complex functions inside of the project; we introduce Engines to many different aspects of Expressive Tea, there is, for example, an Engine for HTTP(S) related code and other different Engine for Websocket, with this our developers will be aware where need to modify and also allow to move complexity away from main components.

Internally, an Inversify Container includes using Dependency Injections so engines can get the data they need by injecting values directly in the Engine Constructors. Also, the method start from Boot Class has been reduced drastically by using dependency injection and engines.

Related Post

Leave a Comment