Skip to content

Latest commit

 

History

History
96 lines (61 loc) · 2.41 KB

ReadMe.md

File metadata and controls

96 lines (61 loc) · 2.41 KB

Node.js & Apache Pulsar Example

This repository demonstrates the usage of Apache Pulsar with a dead simple Node.js application.

This demo displays a form where you can send a message, it will assess the mood of your message and tell if it's a negative or positive message.

How it works:

  • The client sends a request to the server with a message.
  • The server pushes the message onto an Apache Pulsar topic.
  • The worker analyzes the message and sends the result into another Apache Pulsar topic.
  • The server reads the result from the analyzed topic and sends them to the client via WebSocket.

Documentation

Requirements

You will need those dependencies to run it locally.

  • Node.js 14.17
  • Apache Pulsar C++ client 2.8.1
  • clever-tools (Clever Cloud CLI)

Note: The Apache Pulsar C++ client is already available on Clever Cloud Node.js applications.

Usage

Clone the repository and install its dependencies:

git clone https://github.com/CleverCloud/nodejs-pulsar-example.git && cd nodejs-pulsar-example

npm install

Build the frontend assets:

npm run build

Duplicate the .env.example file and fill the empty ADDON_PULSAR_ variables:

cp .env.example .env

You can either deploy a standalone Pulsar locally with Docker or use Pulsar add-on.

Start the server & worker:

npm start

# In another terminal 
npm run worker 

Deployment

To deploy the demo, we need to create a Pulsar add-on and a Node.js application.

Create the Node.js application:

clever create --type node nodejs-pulsar

Create the Pulsar add-on and link it to the Node.js application:

clever addon create addon-pulsar nodejs-pulsar --link nodejs-pulsar

Import the production environnment example:

cat .env.prod.example | clever env import

You can now link the application and deploy the repository:

clever link node-pulsar
clever deploy

To open your application in a browser, simply run clever open.

Et voilà!