0.3.23 • Published 2 years ago

bpframework v0.3.23

Weekly downloads
112
License
MIT
Repository
github
Last release
2 years ago

This project is still in development

Setup.

use cli to create a project.

npm i bpframework-cli -g

create a project.

bpframework init

Example.

see directory ./examples

Feature.

featuresupports
configbootstrap.ymlSpringCloudConfig
discoverynacos
scheduling@Scheduled
api routers@RestController

Configure.

The appropriate configuration is required to enable the corresponding feature: config

namedescription
FindMicroserviceConfigure定义自定义的服务发现处理方法
FeignClientConfigure定义FeignClient的默认headers等信息
RestControllerConfigure定义RestController的默认headers等信息

@FindMicroserviceConfigure

By default, nacos is used to find micro-service; You can customize it by @FindMicroserviceConfigure.

@Service()
class Configure {
  @FindMicroserviceConfigure
  async onFindMicroservice(serviceName: string, excludeHost: string): Promise<ServiceInfo> {
    return {
      ip,
      port,
      serviceName,
      metadata,
    }
  }
}

@RestControllerConfigure

定义RestController的默认headers等信息, 使用如下方式.

@Service()
class Configure {
  @RestControllerConfigure
  onConfigure(): bp.RestControllerConfigureInfo {
    return {
      defaultHeaders: {'content-type': 'application/json;charset=utf-8'},
    }
  }
}

@FeignClientConfigure

定义FeignClient的默认headers等信息, 使用如下方式.

@Service()
class Configure {
  @FeignClientConfigure
  onConfigure(): bp.FeignClientConfigureInfo {
    return {
      defaultHeaders: {'content-type': 'application/json;charset=utf-8'},
      /**
       * 对每次请求后接收的消息进行过滤.
       */
      filterResponseCallback: (data: FeignClientFilterResponseData) => {
        
      },
      /**
       * Processing the data of the request.
       */
      filterRequestCallback: (data: FeignClientFilterRequestData, feignData: FeignDataType) => {

      }
    }
  }
}

@Value

使用 @Value 注解设置初始值或获取配置值.

@Service()
class Demo {
  @Value("Miss A")
  teacher1Name: string; // will set to 'Miss A'

  @Value("${teacherName2}")
  teacher2Name: string; // will set to config value "teacherName2"

  @Value("${teacherName3:defaultName}")
  teacher3Name: string; // will set to 'defaultName' if config value "teacherName3" isn't existed.
}

Middleware.

see https://github.com/bpcloud/middleware.git

Event Listener.

namedescription
ContextRefreshedEventListener本地配置加载完成, 系统service对象初始化完成
RefreshRemoteEventListener远程配置动态刷新事件
InstanceRegisteredEventListener实例注册到注册中心后的事件

@ContextRefreshedEventListener

本地配置加载完成, 系统service对象初始化完成.

@Service()
class ApplicationEvent {
  @ContextRefreshedEventListener
  async onContextRefreshed(ev:ContextRefreshedEvent):void {

  }
}

@RefreshRemoteEventListener

远程配置动态刷新事件.

@Service()
class ApplicationEvent {
  @RefreshRemoteEventListener
  async onRefreshRemote(ev:RefreshRemoteEvent):void {

  }
}

@InstanceRegisteredEventListener

实例注册到注册中心后的事件.

@Service()
class ApplicationEvent {
  @InstanceRegisteredEventListener
  async onInstanceRegistered(ev:InstanceRegisteredEvent):void {
    
  }
}

Scheduling

@Scheduled

使用此注解可以开启一个定时任务.

@Service()
class Demo {
  @Scheduled({cron:'* * * * * *'})
  async onTick(): Promise<false|void> {
    return false; // 返回false则表明停止此task.
  }
}
  • Start task: 当类实例被创建后, task即按照时间间隔运行
  • Stop task: 当@Scheduled修饰的方法明确返回false时, task将停止
0.3.23

2 years ago

0.3.22

2 years ago

0.3.20

2 years ago

0.3.21

2 years ago

0.3.19

2 years ago

0.3.18

2 years ago

0.3.17

2 years ago

0.3.16

2 years ago

0.3.15

2 years ago

0.3.14

2 years ago

0.3.13

2 years ago

0.3.9

2 years ago

0.3.12

2 years ago

0.3.11

2 years ago

0.3.10

2 years ago

0.3.8

3 years ago

0.3.7

3 years ago

0.3.6

3 years ago

0.3.5

3 years ago

0.3.4

3 years ago

0.3.3

3 years ago

0.3.2

3 years ago

0.3.0

3 years ago

0.3.1

3 years ago

0.2.30

3 years ago

0.2.29

3 years ago

0.2.27

3 years ago

0.2.26

3 years ago

0.2.28

3 years ago

0.2.25

3 years ago

0.2.24

3 years ago

0.2.23

3 years ago

0.2.22

3 years ago

0.2.21

3 years ago

0.2.20

3 years ago

0.2.19

3 years ago

0.2.18

3 years ago

0.2.17

3 years ago

0.2.16

3 years ago

0.2.15

3 years ago

0.2.14

3 years ago

0.2.13

3 years ago

0.2.12

3 years ago

0.2.11

3 years ago

0.2.10

3 years ago

0.2.1

3 years ago

0.2.0

3 years ago

0.2.7

3 years ago

0.2.6

3 years ago

0.2.9

3 years ago

0.2.8

3 years ago

0.2.3

3 years ago

0.2.2

3 years ago

0.2.5

3 years ago

0.2.4

3 years ago

0.1.14

3 years ago

0.1.15

3 years ago

0.1.16

3 years ago

0.1.13

3 years ago

0.1.10

3 years ago

0.1.11

3 years ago

0.1.12

3 years ago

0.1.9

3 years ago

0.1.8

3 years ago

0.1.7

3 years ago

0.1.6

3 years ago

0.1.2

3 years ago

0.1.1

3 years ago

0.1.3

3 years ago

0.1.5

3 years ago

0.1.0

3 years ago

0.0.20

3 years ago

0.0.19

3 years ago

0.0.18

3 years ago

0.0.15

3 years ago

0.0.16

3 years ago

0.0.17

3 years ago

0.0.14

4 years ago

0.0.12

4 years ago

0.0.13

4 years ago

0.0.11

4 years ago

0.0.10

4 years ago

0.0.9

4 years ago

0.0.8

4 years ago

0.0.5

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.4

4 years ago

0.0.3

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago