Giter Site home page Giter Site logo

pubsub-server's Introduction

PubSub Server

A PubSub API using expressjs + typescript + docker.

Features

  • Create subscription to topics.
  • Publish messages to topic subscribers.

Technologies

Getting started

# Clone the project
git clone https://github.com/sauban/pubsub-server.git
cd pubsub-server

# Install dependencies
yarn install

# Copy .env.example file
cp .env.example .env

Set Environment Variables

MONGODB_URL=<mongodburl>
PORT=9094

Then you can start the application:

npm start

This will launch the server node process on port 9094

Subscribing

To create subscription for topics

  • API Endpoint
  <BASE_URL>/subscribe/:topic
  • Request Payload
  POST /subscribe/topic1
  {
    "url": "http://localhost:3000/test1"
  }

This should return a response as shown below:

{
  "url": "http://localhost:3000/test1"
}

Publishing

To publish messages under topic to subscribers

  • API Endpoint
  <BASE_URL>/publish/:topic
  • Request Payload
  POST /publish/topic1
  {
    "message": "Hello world"
  }

This should return the payload as shown below:

{
  "topic": "topic1",
  "data": {
    "message": "Hello world"
  }
}

Use Shell script

Run below to start the pubsub server and the subscriber server

  chmod +x ./start-server.sh
  ./start-server.sh

Open a new terminal and run the following:

  curl -X POST -H "Content-Type: application/json" -d '{ "url": "http://localhost:4043/hello"}' http://localhost:9009/subscribe/topic1
  curl -X POST -H "Content-Type: application/json" -d '{ "url": "http://localhost:4043/hello2"}' http://localhost:9009/subscribe/topic1
  curl -X POST -H "Content-Type: application/json" -d '{"message": "hello"}' http://localhost:9009/publish/topic1

pubsub-server's People

Contributors

sauban avatar

Stargazers

 avatar

Watchers

 avatar  avatar

pubsub-server's Issues

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.