bijukunjummen / livenotifications

live notifications demo with SSE using redis pub/sub

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Live Notification

Run locally

Start Redis

redis-server

Start Cloud Firestore emulator

gcloud components install cloud-firestore-emulator
gcloud beta emulators firestore start --host-port=:8662

OR

Start Bigtable Emulator

gcloud components install bigtable
gcloud beta emulators bigtable start --host-port=0.0.0.0:8086

export BIGTABLE_EMULATOR_HOST=localhost:8086
cbt -project "project-id" -instance "bus-instance" createtable chat_messages
cbt -project "project-id" -instance "bus-instance" createfamily chat_messages chatRoomDetails
cbt -project "project-id" -instance "bus-instance" createfamily chat_messages chatMessageDetails
cbt -project "project-id" -instance "bus-instance" read chat_messages

OR

Start Spanner Emulator

gcloud components install spanner
gcloud emulators spanner start

# In another window
gcloud config configurations create emulator
gcloud config set auth/disable_credentials true
gcloud config set project sample-project
gcloud config set api_endpoint_overrides/spanner http://localhost:9020/
gcloud spanner instances create test-instance \
   --config=emulator-config --description="Test Instance" --nodes=1

Start application

# With Firestore
SPRING_PROFILES_ACTIVE="local,firestore" ./gradlew bootRun
# With Bigtable
SPRING_PROFILES_ACTIVE="local,bigtable" ./gradlew bootRun
# With Spanner
SPRING_PROFILES_ACTIVE="local,spanner" ./gradlew bootRun

Create chat rooms

curl -v -X POST  \
  -H "Content-type: application/json" \
  -H "Accept: application/json" \
   http://localhost:8080/chatrooms \
   -d '{
   "id": "some-room",
   "name": "some-room"
}'

Get Chat Room

curl -v http://localhost:8080/chatrooms/some-room

Stream Messages from room

curl -v http://localhost:8080/messages/some-room

Add a messsage to a room

curl -v -X POST \
  -H "Content-type: application/json" \
  -H "Accept: application/json" \
   http://localhost:8080/messages/some-room \
   -d '{
   "payload": "hello world"
}'

It should show up on the previous GET endpoint

About

live notifications demo with SSE using redis pub/sub


Languages

Language:Kotlin 98.3%Language:HCL 1.7%