Code Monkey home page Code Monkey logo

js-sdk's Introduction

Any language, any framework, anywhere

Go Report OpenSSF Docker Pulls Build Status Test Status Code Coverage License: Apache 2.0 FOSSA Status TODOs Good First Issues discord YouTube X/Twitter

Dapr is a portable, serverless, event-driven runtime that makes it easy for developers to build resilient, stateless and stateful microservices that run on the cloud and edge and embraces the diversity of languages and developer frameworks.

Dapr codifies the best practices for building microservice applications into open, independent, building blocks that enable you to build portable applications with the language and framework of your choice. Each building block is independent and you can use one, some, or all of them in your application.

Dapr overview

We are a Cloud Native Computing Foundation (CNCF) incubation project.

Goals

  • Enable developers using any language or framework to write distributed applications
  • Solve the hard problems developers face building microservice applications by providing best practice building blocks
  • Be community driven, open and vendor neutral
  • Gain new contributors
  • Provide consistency and portability through open APIs
  • Be platform agnostic across cloud and edge
  • Embrace extensibility and provide pluggable components without vendor lock-in
  • Enable IoT and edge scenarios by being highly performant and lightweight
  • Be incrementally adoptable from existing code, with no runtime dependency

How it works

Dapr injects a side-car (container or process) to each compute unit. The side-car interacts with event triggers and communicates with the compute unit via standard HTTP or gRPC protocols. This enables Dapr to support all existing and future programming languages without requiring you to import frameworks or libraries.

Dapr offers built-in state management, reliable messaging (at least once delivery), triggers and bindings through standard HTTP verbs or gRPC interfaces. This allows you to write stateless, stateful and actor-like services following the same programming paradigm. You can freely choose consistency model, threading model and message delivery patterns.

Dapr runs natively on Kubernetes, as a self hosted binary on your machine, on an IoT device, or as a container that can be injected into any system, in the cloud or on-premises.

Dapr uses pluggable component state stores and message buses such as Redis as well as gRPC to offer a wide range of communication methods, including direct dapr-to-dapr using gRPC and async Pub-Sub with guaranteed delivery and at-least-once semantics.

Why Dapr?

Writing highly performant, scalable and reliable distributed application is hard. Dapr brings proven patterns and practices to you. It unifies event-driven and actors semantics into a simple, consistent programming model. It supports all programming languages without framework lock-in. You are not exposed to low-level primitives such as threading, concurrency control, partitioning and scaling. Instead, you can write your code by implementing a simple web server using familiar web frameworks of your choice.

Dapr is flexible in threading and state consistency models. You can leverage multi-threading if you choose to, and you can choose among different consistency models. This flexibility enables you to implement advanced scenarios without artificial constraints. Dapr is unique because you can transition seamlessly between platforms and underlying implementations without rewriting your code.

Features

  • Event-driven Pub-Sub system with pluggable providers and at-least-once semantics
  • Input and output bindings with pluggable providers
  • State management with pluggable data stores
  • Consistent service-to-service discovery and invocation
  • Opt-in stateful models: Strong/Eventual consistency, First-write/Last-write wins
  • Cross platform virtual actors
  • Secret management to retrieve secrets from secure key vaults
  • Rate limiting
  • Built-in Observability support
  • Runs natively on Kubernetes using a dedicated Operator and CRDs
  • Supports all programming languages via HTTP and gRPC
  • Multi-Cloud, open components (bindings, pub-sub, state) from Azure, AWS, GCP
  • Runs anywhere, as a process or containerized
  • Lightweight (58MB binary, 4MB physical memory)
  • Runs as a sidecar - removes the need for special SDKs or libraries
  • Dedicated CLI - developer friendly experience with easy debugging
  • Clients for Java, .NET Core, Go, Javascript, Python, Rust and C++

Get Started using Dapr

See our Getting Started guide over in our docs.

Quickstarts and Samples

Community

We want your contributions and suggestions! One of the easiest ways to contribute is to participate in discussions on the mailing list, chat on IM or the bi-weekly community calls. For more information on the community engagement, developer and contributing guidelines and more, head over to the Dapr community repo.

Contact Us

Reach out with any questions you may have and we'll make sure to answer them as soon as possible!

Platform Link
๐Ÿ’ฌ Instant Message Chat (preferred) Discord Banner
๐Ÿ“ง Mailing List https://groups.google.com/forum/#!forum/dapr-dev
๐Ÿค Twitter @daprdev

Community Call

Every two weeks we host a community call to showcase new features, review upcoming milestones, and engage in a Q&A. All are welcome!

๐Ÿ“ž Visit https://aka.ms/dapr-community-call for upcoming dates and the meeting link.

Videos and Podcasts

We have a variety of keynotes, podcasts, and presentations available to reference and learn from.

๐Ÿ“บ Visit https://docs.dapr.io/contributing/presentations/ for previous talks and slide decks.

Contributing to Dapr

See the Development Guide to get started with building and developing.

Repositories

Repo Description
Dapr The main repository that you are currently in. Contains the Dapr runtime code and overview documentation.
CLI The Dapr CLI allows you to setup Dapr on your local dev machine or on a Kubernetes cluster, provides debugging support, launches and manages Dapr instances.
Docs The documentation for Dapr.
Quickstarts This repository contains a series of simple code samples that highlight the main Dapr capabilities.
Samples This repository holds community maintained samples for various Dapr use cases.
Components-contrib The purpose of components contrib is to provide open, community driven reusable components for building distributed applications.
Dashboard General purpose dashboard for Dapr
Go-sdk Dapr SDK for Go
Java-sdk Dapr SDK for Java
JS-sdk Dapr SDK for JavaScript
Python-sdk Dapr SDK for Python
Dotnet-sdk Dapr SDK for .NET
Rust-sdk Dapr SDK for Rust
Cpp-sdk Dapr SDK for C++
PHP-sdk Dapr SDK for PHP

Code of Conduct

Please refer to our Dapr Community Code of Conduct

js-sdk's People

Contributors

aaroncrawfis avatar ahmedhesham6 avatar amanbha avatar amulyavarote avatar artursouza avatar brendandburns avatar deepanshua avatar dependabot[bot] avatar dolencd avatar elena-kolevska avatar greenie-msft avatar heunghingwan avatar hhunter-ms avatar italypaleale avatar kaibocai avatar ksivamuthu avatar lechnerc77 avatar marcduiker avatar mregxn avatar pkedy avatar pruthvidhodda avatar salmankhan-prs avatar shalabhms avatar shubham1172 avatar sotrx avatar tcnghia avatar webup avatar xaviergeerinck avatar yaron2 avatar zcong1993 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

js-sdk's Issues

update to grpc.js is necessary

this package [https://www.npmjs.com/package/grpc] is deprecated, I have problems installing it, and it is necessary to update to grpc.js.

Cannot find module 'node-pre-gyp/lib/pre-binding'

Hello all,

currently we have the problem that the module grpc is not found at runtime. This is probably because the module is deprecated and has been replaced with @grpc/grpc-js.

If I change the dependencies and the requiere statement accordingly our application works again.

here the original error message =>
Cannot find module 'node-pre-gyp/lib/pre-binding'
Require stack:

  • /usr/src/app/node_modules/grpc/src/grpc_extension.js
  • /usr/src/app/node_modules/grpc/src/client_interceptors.js
  • /usr/src/app/node_modules/grpc/src/client.js
  • /usr/src/app/node_modules/grpc/index.js
  • /usr/src/app/node_modules/dapr-client/src/dapr/proto/runtime/v1/dapr_grpc_pb.js
  • /usr/src/app/node_modules/dapr-client/src/index.js
  • /usr/src/app/node_modules/adapter_sdk/api/services/EventPublisher.js....

Can you please fix this quickly?

Best Regard
Patrick Campergue

Documentation - Add Actor Example

We strive to have easy to use examples that help everyone. For this issue we are looking for an example that describes how to use actors for HTTP.

Automate publishing package to npm registry

Describe the proposal

  • Fix the github workflow to publish the package to npm registry
  • Add NPM_AUTH_TOKEN to github secrets for this repo

Edit: publish to github releases as well

Automate NPM Publish

NPM Publish should get automated, building the SDK on main merge and publishing a new version to the NPM Registry.

  • Find out who owns the NPM Org
  • Setup GitHub Actions build script

Import errors when running examples

Expected Behavior

Examples should run if you follow the instructions.

Actual Behavior

Examples don't run. The compiler gives errors about missing imports.

Steps to Reproduce the Problem

Run the examples.

NodeJS doesn't find the library from the import of @dapr/js-sdk. This should be changed to ../../../../build to reference the correct folder.

After changing this, more import errors occur, this time due to protos not having been compiled. An extra step should be added to the instructions, saying to run ./build.sh, which compiles the protos.

TypeScript example with incorrect grpc variable declaration / import

Expected Behavior

The declaration / import of the grpc in the dapr js-sdk TypeScript example come from the grpc library itself not from dapr import.

Correct declaration / import:

import grpc from 'grpc';

Actual Behavior

The example extract the grpc from the dapr module

var grpc = dapr.grpc;

Steps to Reproduce the Problem

When compiling the example the following error happens:

error TS2339: Property 'grpc' does not exist on type 'typeof import("js-sdk/node_modules/dapr-client/src/main")'.

27 var grpc = dapr.grpc;
                   ~~~~


Found 1 error.

Simplify building, testing, ...

Describe the proposal

The testing and building process could use some simplification to lay foundations for CI/CD process

Documentation - Add Secrets Example

We strive to have easy to use examples that help everyone. For this issue we are looking for an example that describes how to use Secrets for HTTP and gRPC.

Code examples on how to use the Javascript SDK with each supported building block

Describe the proposal

Consider adding examples on how to use the JS SDK for each of the supported Building Blocks, e.g how to use the JS SDK for Service Invocation.

These examples will provide clarity on how to use the SDK. Additionally, we can raise visibility into the SDK by linking to the examples from each Building Block overview page.

Dev Ergonomics

Describe the proposal

It looks like this repo has received minimal love, but I did want to propose a change that I think would make this lib much friendlier. The protoc generated javascript is....not great. From the pre-property getXyz and setXyz, to the bizzare naming, this lib is not very Javascript like.

I propose switching to something like protobuf.js which has a reasonably active implementation and generates much friendlier code by default.

Issue with reminders

Expected Behavior

Reminder tests should correctly succeed

Actual Behavior

There is an issue that appears that reminders are being fired multiple times in the tests, this might be due to IDs being similar

Steps to Reproduce the Problem

Actors in js

Just want to know if this feature (being able to write actors in javascript) along with pub sub dapr/dapr#501 is there in the roadmap.

Error handling in invoker

Describe the proposal

DAPR supports invoked services signifying errors using their response status code. https://docs.dapr.io/reference/api/service_invocation_api/

The invoker server currently sends a status 200 response when the callback is called. To support errors, some controls will need to be added to set a custom response status code.

On the client side, the return value will need to show this returned status code.

DaprClient in JS throws DaprClient throws error saying ECONNREFUSED under load condition

Expected Behavior

We are using DaprClient to publish message to kafka using kafka pubsub.
We are receiving http request in our application via dapr side car and in the application we are publishing the message to kafka pub sub using DaprClient. DaprClient should publish the message to kafka pub sub when rate of publishing to kafka is increased.

Actual Behavior

DaprClient throws error when the rate at which we publish the message increases.

We get an error from DarpClient
ERROR 14:43:36:777 error publishing topic through dapr: FetchError: request to http://localhost:3500/v1.0/publish/kafka-pubsub/request-topic failed, reason: connect ECONNREFUSED 127.0.0.1:3500
== APP == at ClientRequest.

When the rate at which we are publishing the message to kafka pub sub increase than DaprClient throws error saying connection refused.

Steps to Reproduce the Problem

We are using DaprCLient and publishing using below

 async publishMessage(topic: string, message: PubSubMessage): Promise<void> {
    try {
      await this.client.pubsub.publish(this.pubsubName, topic, message);
    } catch (error: any) {
      logger.error("error publishing topic through dapr: ", error);
    }
  }

yaml for binding is

apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
  name: messagebus
spec:
  type: pubsub.kafka
  version: v1
  metadata:
  - name: brokers # Required. Kafka broker connection setting
    value: "localhost:9092"
  - name: consumerGroup # Optional. Used for input bindings.
    value: "group1"
  - name: clientID # Optional. Used as client tracing ID by Kafka brokers.
    value: "my-dapr-app-id"
  - name: authRequired # Required.
    value: "false"

It is running on Mac M1

The "simple" example is not working - TypeError: event.setPubsubName is not a function

Expected Behavior

The example is not working and running into an error.

Actual Behavior

Executing the example results in an error:

`$ node app.js
[...]/app.js:13
event.setPubsubName('pubsub');
^

TypeError: event.setPubsubName is not a function
at Object. ([...]/js-sdk/examples/simple/app.js:13:7)
at Module._compile (internal/modules/cjs/loader.js:778:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)
at Module.load (internal/modules/cjs/loader.js:653:32)
at tryModuleLoad (internal/modules/cjs/loader.js:593:12)
at Function.Module._load (internal/modules/cjs/loader.js:585:3)
at Function.Module.runMain (internal/modules/cjs/loader.js:831:12)
at startup (internal/bootstrap/node.js:283:19)
at bootstrapNodeJSCore (internal/bootstrap/node.js:623:3)`

Steps to Reproduce the Problem

  • Clone the repository
  • go to ./examples/simple
  • execute npm install
  • start the sample by running node app.js
    (the "main" entry in the package.json points to an index.js that does not exist)

Add support for Actor Reentrancy

Describe the proposal

Add support for actor reentrancy

Needs to check if Node.js requires this seeing it's single threaded nature?

TypeError: dapr.InvokeRequest is not a constructor

Expected Behavior

Actual Behavior

TypeError: dapr.InvokeRequest is not a constructor

Steps to Reproduce the Problem

import { Any } from 'google-protobuf/google/protobuf/any_pb';
import * as dapr from 'dapr-client';
import grpc from 'grpc';

export default class App {
    daprClient: dapr.dapr_grpc.DaprClient;

    constructor() {
        this.daprClient = new dapr.dapr_grpc.DaprClient(
            `localhost:50002`, grpc.credentials.createInsecure());
    }

    getUser() {
            return new Promise((resolve, reject) => {
                let invokeServiceRequest = new dapr.dapr_pb.InvokeServiceRequest();
                invokeServiceRequest.setId('app01');
                let invokeRequest = new dapr.InvokeRequest();
                invokeRequest.setContentType('application/json');
                invokeRequest.setMethod('users/12345');
                let httpExtension = new dapr.HTTPExtension();
                httpExtension.setVerb(dapr.HTTPExtension.Verb.GET);
                invokeRequest.setHttpExtension(httpExtension);
                invokeServiceRequest.setMessage(invokeRequest);
                this.daprClient.invokeService(invokeServiceRequest, (error, response) => {
                    if (error) {
                        reject(error);
                    }
                    else {
                        resolve(response.getData());
                    }
                });
            });
        }
}

API Spec Proposal

Hi All!

As discussed I would love to contribute an API spec proposal for the Dapr JS SDK :) It's a bit opiniated, but I hope it might lead to a discussion to see what can be improved.

Some of the key elements:

  • Typescript
  • Class based
  • Extensibility

Usage example:

// Initialize Express
const app = express();

// Initialize dapr service
const daprService = new Dapr("YOUR_URL", "YOUR_PORT");

// State Management
const res = await daprService.state.get("my-store-name", "key");
const res = await daprService.state.save("my-store-name", [{ key: "value" }]);

// Create binding (receive / send)
const res = await daprService.binding.send("my-queue", { hello: "world" });

daprService.binding.receive(app, "my-queue", bindingInput.bind(this));

async function bindingInput(data) {
    console.log("Receive Input");
    console.log(data);
}

// Create Pub Sub
const res = await daprService.pubsub.publish("my-pubsub", "my-topic", { hello: "world" });

daprService.pubsub.receive(app, "my-pubsub", "my-topic", bindingInput.bind(this));

async function bindingInput(data) {
    console.log("Receive Input");
    console.log(data);
}

// Invoke
const res = await daprService.invoke.invoke("app-id", "method-name", { hello: "world" });

await daprService.invoke.register(app, "my-endpoint", invokedEndpoint.bind(this));

async function invokedEndpoint(data) {
    console.log("Receive Input");
    console.log(data);
}

Some of the code I wrote for this can be found here: https://github.com/XavierGeerinck/PublicProjects/tree/master/JS/Dapr/AutoScalingHTTP/Gateway/src/API/dapr this has not been tested yet though... so some work is left to be done.

Follow Dapr Release Flow

Describe the proposal

The Dapr runtime follows a certain release cadence. It might be interesting to follow this release versioning:

Advantages:

  • Easier to know which SDK is compatible with which runtime version

Disadvantages:

  • Requires more updates and releases and strictly follow the Dapr release schedule (note: we do have milestone plannings that should be followed, so might be possible)

actors documentation

hi everyone. does any documentation exist that describes how to use actors in the js sdk ?

Support Observability

Describe the proposal

DAPR supports distributed tracing by sending a trace context in the request/response headers. To support this, js-sdk needs to send this trace context, if it's present in the request, in the response headers.

The trace context should also be available outside the library (for example, to the invoker server callback), so it can be used in other operations related to the request.

Documentation - Add Pub/Sub Example

We strive to have easy to use examples that help everyone. For this issue we are looking for an example that describes how to use Pub/Sub for HTTP and gRPC.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.