j1m-renwick / reactive-backend

A PoC of what an event-publishing microservice might look like

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Event-broadcasting sample backend

This project is a proof of concept for a microservice broadcasting events to frontend browser clients as a result of one of it's API endpoints being invoked.

On starting, the webpage can open a websocket to the microservice, and receive existing relevant event data that is stored in Redis. This would be data such as short-term, non-persistent data (such as the state of current users).

The assumption is that the events will be broadly split into two types:

  1. User-session based events (such as notifying a user that another user is interacting with a common component in their session)
  2. Notification-based events (such as notifying users that a particular piece of data is stale and needs to be refreshed)

It is assumed is that there will be multiple instances of the microservice, and that each will need to broadcast events to the particular websocket connections that it is handling. To maintain syncing of events being broadcast across instances, the event generated by the invocation of the endpoint is published to a Redis Pub/Sub channel. All microservice instances listen to this channel, and broadcast the received messages from this channel to their respective websockets.

###To run

  • start redis on localhost:6379
  • run app
  • run frontend app (see README in related project for details)

###APIs

####POST http://localhost:8123/poc/submit_update_event

Sends an update event to the frontend, and saves it to the redis cache.

Sample request:

{
  "username" : "alice",
  "cardId" : "id_123",
  "data" : "this card's subtitle is different now!"
}

####GET http://localhost:8123/poc/replay_event_data/{userId}

Returns the latest event data for the specified user (e.g. alice)

Micronaut 3.3.0 Documentation


Feature rxjava3 documentation

About

A PoC of what an event-publishing microservice might look like


Languages

Language:Groovy 100.0%