@cumulus/cumulus-message-adapter-js

中文文档
2.5.0发布于 2026/09/29Apache-2.0TypeScriptCommonJS近 30 天下载 7713

Cumulus message adapter

原始使用文档
文档目录12 节
  1. What is Cumulus
  2. What is the Cumulus Message Adapter?
  3. Installation
  4. Task definition
  5. Cumulus Message Adapter interface
  6. Example Cumulus task
  7. Creating a deployment package
  8. Usage in Cumulus Deployments
  9. Environment variables
  10. Development
  11. Running Tests
  12. Why use this approach

@cumulus/cumulus-message-adapter-js

CircleCI npm version

What is Cumulus

Cumulus is a cloud-based data ingest, archive, distribution and management prototype for NASA's future Earth science data streams.

Read the Cumulus Documentation

What is the Cumulus Message Adapter?

The Cumulus Message Adapter is a library that adapts incoming messages in the Cumulus protocol to a format more easily consumable by Cumulus tasks, invokes the tasks, and then adapts their response back to the Cumulus message protocol to be sent to the next task.

Installation

The cumulus-message-adapter-js can be installed via Node Package Manager (NPM) and the package is located here.

The package can be added to your project by running npm install @cumulus/cumulus-message-adapter-js --save.

Task definition

In order to use the Cumulus Message Adapter, you will need to create two methods in your task module: a handler function and a business logic function.

The handler function is a standard Lambda handler function which takes three parameters (as specified by AWS): event, context, and callback.

The business logic function is where the actual work of your task occurs. It should take two parameters: nestedEvent and context.

The nestedEvent object contains two keys:

  • input - the task's input, typically the payload of the message, produced at runtime
  • config - the task's configuration, with any templated variables resolved

The context parameter is the standard Lambda context as passed by AWS.

The return value of the business logic function will be placed in the payload of the resulting Cumulus message.

Expectations for input, config, and return values are all defined by the task, and should be well documented. Tasks should thoughtfully consider their inputs and return values, as breaking changes may have cascading effects on tasks throughout a workflow. Configuration changes are slightly less impactful, but must be communicated to those using the task.

Cumulus Message Adapter interface

The Cumulus Message adapter for Javascript provides one method: runCumulusTask. It takes five parameters:

  • taskFunction - the function containing your business logic (as described above)
  • cumulusMessage - the event passed by Lambda, and should be a Cumulus Message
  • context - the Lambda context
  • callback - the callback passed by Lambda
  • schemas - JSON object with the locations of the task schemas

The schemas JSON should contain input:, output:, and config: with strings for each location. If the schema locations are not specified, the message adapter will look for schemas in a schemas directory at the root level for the files: input.json, output.json, or config.json. If the schema is not specified or missing, schema validation will not be performed.

Example Cumulus task

const cumulusMessageAdapter = require('@cumulus/cumulus-message-adapter-js');

function myBusinessLogic(nestedEvent, context) {
  console.log('Hello, example!');
  return { answer: 42 };
}

// The handler function should rarely, if ever, contain more than this line
function handler(event, context, callback) {
  cumulusMessageAdapter.runCumulusTask(myBusinessLogic, event, context, callback, schemas);
}
exports.handler = handler;

Creating a deployment package

Tasks that use this library are just standard AWS Lambda tasks. Information on creating release packages is available here.

Usage in Cumulus Deployments

For documentation on how to utilize this package in a Cumulus Deployment, view the Cumulus Workflow Documenation.

Environment variables

There are two environment variables that can be used with this library:

  • CUMULUS_MESSAGE_ADAPTER_DISABLED=true
    • Defaults to false. This env var disables Cumulus Message Adapter. This can be used to turn off the message adapter for tasks that adapt the message on their own, or for testing.
  • CUMULUS_MESSAGE_ADAPTER_DIR
    • The default directory for Cumulus Message Adapter is the root directory of the lambda function.

Development

Running Tests

To run the tests for this package, run npm run lint && npm test

Why use this approach

This approach has a few major advantages:

  1. It explicitly prevents tasks from making assumptions about data structures like meta and cumulus_meta that are owned internally and may therefore be broken in future updates. To gain access to fields in these structures, tasks must be passed the data explicitly in the workflow configuration.
  2. It provides clearer ownership of the various data structures. Operators own meta. Cumulus owns cumulus_meta. Tasks define their own config, input, and output formats.
  3. The Cumulus Message Adapter greatly simplifies running Lambda functions not explicitly created for Cumulus.
  4. The approach greatly simplifies testing for tasks, as tasks don't need to set up cumbersome structures to emulate the message protocol and can just test their business function.

版本与发布记录

@cumulus/cumulus-message-adapter-js 共发布 36 个版本,首次发布于 2018/01/31;过去 12 个月发布了 2 个版本。

版本发布日期距今
2.5.0latest2026/09/291 个月前
2.4.02026/01/139 个月前
2.3.02025/01/271.8 年前
2.2.02024/04/292 年前
2.1.02023/10/053 年前
2.0.52023/05/113 年前

关于 @cumulus/cumulus-message-adapter-js 的常见问题

@cumulus/cumulus-message-adapter-js 是什么?

Cumulus message adapter

如何安装 @cumulus/cumulus-message-adapter-js?

在项目目录运行 npm install @cumulus/cumulus-message-adapter-js,或使用 pnpm add / yarn add / bun add。

@cumulus/cumulus-message-adapter-js 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@cumulus/cumulus-message-adapter-js 支持 ESM 还是 CommonJS?

以 CommonJS 形式发布,可以直接 require();在 ES Module 项目中也可以用 import 引入(Node.js 会把 module.exports 作为默认导出)。

@cumulus/cumulus-message-adapter-js 需要什么版本的 Node.js?

package.json 的 engines 字段要求 Node.js >=22.21.1。版本不符时 npm 默认只给出警告,开启 engine-strict 后会拒绝安装。

@cumulus/cumulus-message-adapter-js 可以商用吗?

@cumulus/cumulus-message-adapter-js 使用 Apache-2.0 许可。宽松许可:允许商业使用、修改和再分发,并附带明确的专利授权;分发时需保留许可与 NOTICE 文件,修改过的文件要注明改动。以上为概括,不构成法律意见,请以许可原文为准。

@cumulus/cumulus-message-adapter-js 的下载量有多少?

根据 npm 官方下载统计,@cumulus/cumulus-message-adapter-js 在 2026/10/11 – 2026/11/09 这 30 天内被下载 7,713 次,日均约 257 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@cumulus/cumulus-message-adapter-js 还在维护吗?

最新版本 2.5.0 发布于 2026/09/29(1 个月前);至今共发布 36 个版本,其中过去 12 个月发布了 2 个;首次发布于 2018/01/31。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。