Skip to content

Commit

Permalink
add user service
Browse files Browse the repository at this point in the history
  • Loading branch information
ming.hsu committed Mar 27, 2022
1 parent d625f24 commit ef7b3f9
Show file tree
Hide file tree
Showing 33 changed files with 1,009 additions and 448 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ Features:
- Real-time communication and efficient websocket handling using [Melody](https://github.com/olahol/melody).
- Microservices architecture. All services can be horizontally scaled on demand.
- `web`: frontend server
- `user`: user account server
- `match`: user matching server
- `chat`: messaging server
- `uploader`: file uploader
Expand All @@ -30,6 +31,10 @@ System architecture:
<img width="723" alt="image" src="https://user-images.githubusercontent.com/50090692/159188893-6036a8a7-4318-48d2-a281-3567a12071bd.png">

## Usage
Prerequisite:
- Docker-Compose v2
- root permission

To run locally, execute the following command:
```bash
cd deployments
Expand Down
23 changes: 23 additions & 0 deletions cmd/user.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package cmd

import (
"github.com/minghsu0107/go-random-chat/internal/wire"
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)

var userCmd = &cobra.Command{
Use: "user",
Short: "user server",
Run: func(cmd *cobra.Command, args []string) {
server, err := wire.InitializeUserServer("user")
if err != nil {
log.Fatal(err)
}
server.Serve()
},
}

func init() {
rootCmd.AddCommand(userCmd)
}
9 changes: 9 additions & 0 deletions configs/config.example.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ match:
client:
chat:
endpoint: "localhost:4000"
user:
endpoint: "localhost:4001"
jwt:
secret: mysecret
expirationSecond: 86400
Expand All @@ -44,6 +46,13 @@ uploader:
secretKey: testsecret
jwt:
secret: mysecret
user:
http:
server:
port: "80"
grpc:
server:
port: "4001"
redis:
password: pass.123
addrs: localhost:6379
Expand Down
27 changes: 27 additions & 0 deletions deployments/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ services:
MATCH_HTTP_SERVER_PORT: "80"
MATCH_HTTP_SERVER_MAXCONN: "200"
MATCH_GRPC_CLIENT_CHAT_ENDPOINT: "reverse-proxy:80"
MATCH_GRPC_CLIENT_USER_ENDPOINT: "reverse-proxy:80"
MATCH_JWT_SECRET: ${JWT_SECRET}
MATCH_JWT_EXPIRATIONSECOND: "86400"
REDIS_PASSWORD: ${REDIS_PASSWORD}
Expand Down Expand Up @@ -117,6 +118,32 @@ services:
- "traefik.http.routers.uploader.entrypoints=web"
- "traefik.http.routers.uploader.service=uploader"
- "traefik.http.services.uploader.loadbalancer.server.port=80"
user:
image: minghsu0107/random-chat-api:main
restart: always
expose:
- "80"
command:
- user
environment:
USER_HTTP_SERVER_PORT: "80"
USER_GRPC_SERVER_PORT: "4000"
REDIS_PASSWORD: ${REDIS_PASSWORD}
REDIS_ADDRS: redis-node1:7000,redis-node2:7001,redis-node3:7002,redis-node4:7003,redis-node5:7004,redis-node6:7005
REDIS_EXPIRATIONHOUR: "24"
OBSERVABILITY_PROMETHEUS_PORT: "8080"
OBSERVABILITY_TRACING_JAEGERURL: http://jaeger:14268/api/traces
labels:
- "traefik.enable=true"
- "traefik.http.routers.user.rule=PathPrefix(`/api/user`)"
- "traefik.http.routers.user.entrypoints=web"
- "traefik.http.routers.user.service=user"
- "traefik.http.services.user.loadbalancer.server.port=80"
- "traefik.http.routers.user-grpc.rule=Headers(`content-type`,`application/grpc`) && Headers(`service-id`, `user`)"
- "traefik.http.routers.user-grpc.entrypoints=web"
- "traefik.http.routers.user-grpc.service=user-grpc"
- "traefik.http.services.user-grpc.loadbalancer.server.port=4000"
- "traefik.http.services.user-grpc.loadbalancer.server.scheme=h2c"
minio:
image: minio/minio:RELEASE.2021-03-17T02-33-02Z@sha256:d33b2e9559ee59acf7591cd83cb7238837158a316956e6140e6692a8e4e12fe9
volumes:
Expand Down
3 changes: 3 additions & 0 deletions deployments/prometheus/prometheus.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ scrape_configs:
- job_name: 'uploader_monitor'
static_configs:
- targets: ['deployments-uploader-1:8080']
- job_name: 'user_monitor'
static_configs:
- targets: ['deployments-user-1:8080']
Loading

0 comments on commit ef7b3f9

Please sign in to comment.