npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2025 – Pkg Stats / Ryan Hefner

egg-seneca

v1.0.2

Published

about egg-seneca detail

Downloads

12

Readme

egg-seneca

详细说明

使用说明

此为说明文档,请勿下载安装 This is a documentation, do not download the installation

插件以Egg.js为应用框架,以Seneca为服务交互支持,提供微服务方案。 整体结构分为两部分:

  • 网关部分:安装插件 egg-seneca-gateway,用以接收外部请求、被动接受子服务嵌入(发现)、提供子服务间交互;
  • 子服务部分: 安装插件 egg-seneca-subserver,子服务开发与普通的 Egg 应用开发无差异,仅配置和启动时机、其他服务交互方式不同。

暂不支持 RESTGraphQL 风格

启动顺序

  1. 先启动 网关 应用,被动等待子服务接入;
  2. 启动 子服务 部分,网关 会生成相应的对外接口、对其他子服务的交互方式;

侵入性

egg-seneca 在设计的过程中尽力避免对原有开发模式的侵入性,熟悉 Egg.js 的同学保持原有的开发方式即可。 与原 Egg.js 开发不同之处有以下几点,敬请阅读:

  • 由网关提供主要对外接口,子服务通过配置于启动时接入网关;
  • 子服务启动时会开启一个 Seneca Server 以便接收/响应网关数据;
  • 为Application提供 app.seneca('其他服务名', '操作命令', { 参数对象 }) 方式,用于调用其他子服务;
  • 子服务在启动注册网关过程中,会解析原应用的 EggRouter,用于生成 Seneca Patterns Action(接收/响应的匹配模式),并将路由表发送至网关,用于由网关生成对外接口。
  • 网关维护一个 ClientMap,用于描述当前子服务的映射表。获取方式为:await app.registryClient.getConfig('SenecaRoutersCache');
  • 网关插件不提供服务映射的图形界面,但由网关骨架模拟提供了一个子服务表视图网页展示。网关骨架的获取方式为:git clone https://github.com/Alalabu/sheu-gateway.git your-gateway,启动网关骨架后访问地址为:http://网关主机+端口号/;
  • 每隔 30s 网关会监测子服务是否依然保持活跃, 若不活跃则删除子服务的外部访问

服务注册

  • 子服务通过egg-seneca-subserver会解析Egg应用中的Router集合, 并发布于你的网关(安装了egg-seneca-gateway的应用)。
  • 在网关,会生成相应的web API以便客户端调用。
  • 例如你的路由地址是/findAll,而senecaSubserver中配置的server.name=user
  • 则网关会生成: /user/findAll作为统一调用接口

服务之间调用

  • 当您的应用需要调用其他微服务应用时,您应该使用seneca进行tcp模式调用:
// {app_root}/app/service/foo.js
async bar() {
  const { ctx } = this;
  // ctx.app.seneca(服务名, 命令, 参数对象);
  const res = await ctx.app.seneca('users', 'register', { account: 'abc1004' });
  return res;
}
  • 涉及鉴权的服务间调用时,鉴权内容通常封装于 header 之中。在调用其他子服务时,携带 header 作为参数即可(可能会与参数对象中的header冲突):
// {app_root}/app/service/foo.js
async bar() {
  const { ctx } = this;
  // ctx.app.seneca(服务名, 命令, 参数对象);
  const { header } = ctx.request;
  const res = await ctx.app.seneca('users', 'register', { header, account: 'abc1004' });
  return res;
}