reddis chat

hankyulee·2023년 3월 11일
0


출처: https://alnova2.tistory.com/915
stomp이용 chat -> reddis에 저장 - in memory 방식 -> main memory에 저장 -> 빠름 -> 그러나 shutdown 시 날아감 -> 계속 disk에 저장해 놓는 작업하면 해결가능
stomp를 이용하면 상대 client에 직접 data를 전달하지 않고, channel에 data를 전달하기만 하면 됨. subscriber들이 channel에 구독할 경우 message를 받게되므로.
websocket -> polling 없으므로 빠름

websocket: 서버와 클라이언트 간의 메시지 교환을 위한 통신 규약(프로토콜)
with lower latency than HTTP
Bi-directional communication
HTTP는 one-way communication (from the client to the server) - 메세지를 보내는동시에 받기도 되어야하므로.

  • Reduced network overhead: With HTTP, headers must be sent with each request, which can add additional network overhead. WebSockets, on the other hand, only require a single header to be sent with the initial connection request, reducing the network overhead.
  • 폴링하는 코드 , 다소 복잡할 수 있는,이 필요없다.

WebSockets are designed to minimize server processing time and reduce network overhead compared to other communication protocols like HTTP. With HTTP, a new connection must be established for each request and response, which can be resource-intensive. In contrast, WebSockets allow a single connection to be used for bidirectional communication, reducing the overhead of establishing and tearing down connections.

HTTP is a stateless protocol, which means that each request-response cycle is independent of any previous or subsequent cycles.

WebSockets allow both the client and the server to send data to each other at any time without having to establish a new connection for each exchange.
without the overhead of constantly opening and closing connections.

2 way handwake:
request: "Upgrade: websocket" field
response: 101 status code and a header that includes a "Upgrade: websocket" field,
이후,
the connection is upgraded from HTTP to WebSocket, and both the client and server can send and receive data in real-time.

close할때에도 비슷하게 handway shake함. tcp의 fin ack 처럼

Both parties can send and receive messages asynchronously, without blocking the other party. -> 즉 보내는 동시에 받을 수 있다는 말. http는 request -> response가 있음

In the context of STOMP, a broker is a server that implements the STOMP protocol and provides message brokering services. The broker maintains a list of destinations, which can be topics or queues, to which clients can subscribe and from which they can receive messages. When a client sends a message to a destination, the broker receives the message and delivers it to all subscribers of that destination.

In summary, the broker is the server that mediates communication between producers and consumers in a messaging system, and it manages the distribution of messages to subscribers based on subscription rules. The broker is not the same as a topic; rather, it is responsible for managing topics and other destinations.
-> publisher가 방을 만들면 서버 즉 브로커에서 topic을 만들고 섭스크라이버들이 subscribe를 토픽에 해서 메시지를 받게 된다. 브로커가 서버고 만들어지는 방이 토픽이다. 브로커가 메세지를 받으면 어떤 topic에 메시지를 전달할지 결정한다.

우리는 redis 에서 pub/sub 이용. 몽고디비에는 채팅 저장

0개의 댓글