Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

bpframework

Package Overview
Dependencies
Maintainers
1
Versions
91
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

bpframework

Web framework like java springboot and springcloud

  • 0.3.23
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
7
increased by600%
Maintainers
1
Weekly downloads
 
Created
Source

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.yml
SpringCloudConfig
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将停止

Keywords

FAQs

Package last updated on 14 Mar 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc