All Projects → XadillaX → Aliyun Ons

XadillaX / Aliyun Ons

Licence: mit
☁️ SDK of Node.js for Aliyun ONS. 🚀

Projects that are alternatives of or similar to Aliyun Ons

Openapi Sdk Php Client
Official repository of the Alibaba Cloud Client for PHP
Stars: ✭ 206 (+36.42%)
Mutual labels:  aliyun, sdk
Openapi Sdk Php
Alibaba Cloud SDK for PHP
Stars: ✭ 423 (+180.13%)
Mutual labels:  aliyun, sdk
Rocketmq Spring Boot Starter
rocketmq-spring-boot-starter
Stars: ✭ 178 (+17.88%)
Mutual labels:  aliyun, rocketmq
Iotkit Embedded
高速镜像: https://code.aliyun.com/linkkit/c-sdk
Stars: ✭ 461 (+205.3%)
Mutual labels:  aliyun, sdk
Alibaba Cloud Sdk Go
Alibaba Cloud SDK for Go
Stars: ✭ 876 (+480.13%)
Mutual labels:  aliyun, sdk
Ali Mns
The nodejs sdk for aliyun mqs service
Stars: ✭ 107 (-29.14%)
Mutual labels:  aliyun, sdk
Spring Cloud Alibaba
Spring Cloud Alibaba provides a one-stop solution for application development for the distributed solutions of Alibaba middleware.
Stars: ✭ 20,934 (+13763.58%)
Mutual labels:  aliyun, rocketmq
Aliyun Sdk Js
阿里云 SDK for Javascript,支持在浏览器和 Nodejs 环境使用,支持大部分阿里云服务。
Stars: ✭ 727 (+381.46%)
Mutual labels:  aliyun, sdk
Aliyungo
Go SDK for Aliyun (Alibaba Cloud) - Golang API for ECS, OSS, DNS, SLB, RDS, RAM, MNS, STS, SLS, MQ, Push, OpenSearch, DM, Container Service etc.
Stars: ✭ 756 (+400.66%)
Mutual labels:  aliyun, sdk
Waliyun
阿里云Node.js Open API SDK(完整版)
Stars: ✭ 40 (-73.51%)
Mutual labels:  aliyun, sdk
Ali Oss
Aliyun OSS(open storage service) JavaScript SDK for the browser and Node.js
Stars: ✭ 1,579 (+945.7%)
Mutual labels:  aliyun, sdk
Kittik
Create slides in TypeScript and present them in the terminal using ASCII only!
Stars: ✭ 147 (-2.65%)
Mutual labels:  sdk
Filestack Android
Official Android SDK for Filestack - API and content management system that makes it easy to add powerful file uploading and transformation capabilities to any web or mobile application.
Stars: ✭ 140 (-7.28%)
Mutual labels:  sdk
Facebook Js Ads Sdk
[DEPRECATED] OFFICIAL FACEBOOK SDK: https://github.com/facebook/facebook-nodejs-ads-sdk
Stars: ✭ 140 (-7.28%)
Mutual labels:  sdk
Onfido Sdk Ui
The Onfido SDK for Front-end JavaScript
Stars: ✭ 139 (-7.95%)
Mutual labels:  sdk
Jitsi Meet Sdk Samples
Jitsi Meet SDK examples (Android and iOS)
Stars: ✭ 150 (-0.66%)
Mutual labels:  sdk
Parse Sdk Android
The Android SDK for the Parse Platform
Stars: ✭ 1,806 (+1096.03%)
Mutual labels:  sdk
Newlife.rocketmq
纯托管轻量级RocketMQ客户端,支持发布消息、消费消息、负载均衡等核心功能!
Stars: ✭ 140 (-7.28%)
Mutual labels:  rocketmq
Cityengine Sdk
CityEngine is a 3D city modeling software for urban design, visual effects, and VR/AR production. With its C++ SDK you can create plugins and standalone apps capable to execute CityEngine CGA procedural modeling rules.
Stars: ✭ 137 (-9.27%)
Mutual labels:  sdk
Alan Sdk Reactnative
Alan React Native SDK adds a voice assistant or chatbot to your app.
Stars: ✭ 138 (-8.61%)
Mutual labels:  sdk

Aliyun ONS SDK for Node.js

Version Downloads License AppVeypr TravisCI Dependency

SDK of Node.js for Aliyun ONS.

ONS (Open Notification Service) is a message queue service of aliyun based on MetaQ (RocketMQ).

Maybe you want 中文文档?

Installation

$ npm install --save ons

NOTE: Because of Aliyun ONS C++ SDK's closed source, it only provides Linux and Windows library file (libonsclient4cpp.a, ONSClientCPP.lib). So you can only install this package under Linux and Windows 64x so far.

Current 4.x version of ons supports OSX via incomplete HTTP protocol. Not recommended for stable use.

Usage

You should turn on ONS first and then get an access key and a secret key. In next step you should create a consumer id or a producer id, and a topic.

You can do steps above by refering to help desk and aliyun console.

Examples

Here's some examples for consumer and producer.

Consumer

You can create a consumer by code following:

var Consumer = require("ons").Consumer;
var consumer = new Consumer(CUSTOMER_ID, TOPIC, TAGS, ACCESS_KEY, SECRET_KEY, OPTIONS);

OPTIONS is optional and any parameters in OPTIONS are optional too.

eg.

{
    namesrvAddr: "112.124.141.191:80",
    onsAddr: "http://onsaddr-internet.aliyun.com:80/rocketmq/nsaddr4client-internet",

    threadNum: 3
}

OSX only supports threadNum and httpDomain options. And TAGS parameter in constructor will be useless under OSX.

Next step you should set one or more message receive function to that consumer.

consumer.on("message", function(msg, ack) {
    // DO SOMETHING
    // 
    // this function will be emitted while receiving a message
    //
    // after finishing this, call `ack.done(true)` or `ack.done(false)` to tell
    // ONS whether you're successful.
    //
    // `ack.done()` equals to `ack.done(true)`
});

After creating a consumer and set listener, you should initialize for it and then listen.

consumer.init(function(err) {
    if(err) return console.log(err);
    consumer.listen();
});

That's easy! And what's more, you can stop it when you want.

consumer.stop(function() {
    // closed
});

CAUTION: You should ack all received messages (whether done(true) or done(false)) before you call consumer.stop(), or you won't get callback function called in stop and consumer won't be stopped.

What's more, you'd better to stop consumer before your program exited. e.g.

process.on("SIGINT", function() {
    consumer.stop(function() {
        process.exit(0);
    });
});

You should write down your exit code in your own scene.

Producer

You can create a producer by code following:

var Producer = require("ons").Producer;
var producer = new Producer(PRODUCER_ID, ACCESS_KEY, SECRET_KEY, OPTIONS);

OPTIONS is optional and any parameters in OPTIONS are optional too. e.g.

{
    namesrvAddr: "112.124.141.191:80",
    onsAddr: "http://onsaddr-internet.aliyun.com:80/rocketmq/nsaddr4client-internet",

    sendTimeout: 1000
}
  • namesrvAddr: the ONS server address
  • onsAddr: an address to fetch ONS server address
  • sendTimeout: timeout for sending a message
  • order: true if you want it be OrderProducer
  • httpDomain: OSX only, refer to https://help.aliyun.com/document_detail/29574.html

OSX only supports order and httpDomain options.

After creating a producer, you should start it.

producer.start(function(err) {
    if(err) return console.log(err);
    console.log("Started!");
});

Now you can send message(s)!

producer.send([KEY,] TOPIC, TAGS, CONTENT, [SHARDING_KEY,] [DELAY,] function(err, messageId) {
    console.log(arguments);
});

// or key / shardingKey / delay (ms) / callback are optional parameter

producer.send(TOPIC, TAGS, CONTENT, function(err, messageId) {
    console.log(arguments);
});

NOTICE 1: SHARDING_KEY is only for OrderProducer, each message in same SHARDING_KEY will send one by one in order and OrderConsumer will receive messages in same SHARDING_KEY one by one in order.

NOTICE 2: callback is optional when it's not OrderProducer. If no callback passed, message will be sent in oneway method.

That's easy! And what's more, you can stop it when you want.

producer.stop(function() {
    // closed
});

CAUTION: you'd better to stop producer before your program exited. e.g.

process.on("SIGINT", function() {
    producer.stop(function() {
        process.exit(0);
    });
});

You should write down your exit code in your own scene.

Original Logs

This feature is available under Linux so far.

By default C++ ONS SDK will generate a log file. So we create a tail stream to watch it.

const logger = require("ons").logger;
logger.on("data", function(data) {
    console.log("[ORIG LOG]", data);
});

// [ORIG LOG] ... register sendMessageHook success,hookname is OnsSendMessageHook ...
// ...
// [ORIG LOG] ... register consumeMessageHook success,hookname is OnsConsumerMessageHook ...
// ...
// [ORIG LOG] ... shutdown producerl successfully ...
// ...
// [ORIG LOG] ... shutdown pushConsumer successfully ...
// ...

NOTICE 1: C++ ONS SDK will create only one log file per process, so logger is a singleton. NOTICE 2: Don't use under OSX!

C++ SDK Changelog

Here's original C++ ONS SDK changelog.

NOTICE: It's only the changelog for the original C++ SDK. Node.js SDK may not use all new features of original SDK.

Contribute

You're welcome to fork and make pull requests!

「雖然我覺得不怎麼可能有人會關注我」

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].