-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: ✏️ Heartbeat negotiation interceptor (#183)
* fix: add system heartbeat interval env * fix: server - mq heartbeath interver 25s to 20s * chore: rabbitmq requested-heartbeat set 20 sec * feat: create heartbeat negotiation interceptor * fix: modify negotiation rule when client send 0,0 or null heartbeat header * style: 협상 결과 log 위치 수정
- Loading branch information
1 parent
149756f
commit 7f74e8c
Showing
7 changed files
with
68 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,7 @@ spring: | |
username: ${RABBITMQ_USERNAME:guest} | ||
password: ${RABBITMQ_PASSWORD:guest} | ||
virtual-host: ${RABBITMQ_VIRTUAL_HOST:/} | ||
requested-heartbeat: ${RABBITMQ_REQUESTED_HEARTBEAT:20} | ||
|
||
app: | ||
question-address: ${ADMIN_ADDRESS:[email protected]} | ||
|
55 changes: 55 additions & 0 deletions
55
...o/pennyway/socket/common/interceptor/handler/inbound/HeartBeatNegotiationInterceptor.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package kr.co.pennyway.socket.common.interceptor.handler.inbound; | ||
|
||
import kr.co.pennyway.socket.common.interceptor.marker.ConnectCommandHandler; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.messaging.Message; | ||
import org.springframework.messaging.simp.stomp.StompCommand; | ||
import org.springframework.messaging.simp.stomp.StompHeaderAccessor; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Slf4j | ||
@Component | ||
public class HeartBeatNegotiationInterceptor implements ConnectCommandHandler { | ||
private static final String HEART_BEAT_HEADER = "heart-beat"; | ||
|
||
private static final long SERVER_HEARTBEAT_SEND = 25000; // sx | ||
private static final long SERVER_HEARTBEAT_RECEIVE = 25000; // sy | ||
|
||
@Override | ||
public boolean isSupport(StompCommand command) { | ||
return StompCommand.CONNECT.equals(command); | ||
} | ||
|
||
@Override | ||
public void handle(Message<?> message, StompHeaderAccessor accessor) { | ||
String heartbeat = accessor.getFirstNativeHeader(HEART_BEAT_HEADER); | ||
|
||
long clientToServer = SERVER_HEARTBEAT_RECEIVE; | ||
long serverToClient = SERVER_HEARTBEAT_SEND; | ||
|
||
if (heartbeat == null || heartbeat.equals("0,0")) { | ||
log.debug("Client attempted connection without heart-beat. Enforcing server's heart-beat policy: {},{}", | ||
SERVER_HEARTBEAT_SEND, SERVER_HEARTBEAT_RECEIVE); | ||
} | ||
|
||
if (heartbeat != null) { | ||
String[] parts = heartbeat.split(","); | ||
|
||
if (parts.length == 2) { | ||
long cx = Long.parseLong(parts[0]); | ||
long cy = Long.parseLong(parts[1]); | ||
|
||
clientToServer = (cx != 0) ? Math.max(cx, SERVER_HEARTBEAT_RECEIVE) : SERVER_HEARTBEAT_RECEIVE; | ||
serverToClient = (cy != 0) ? Math.max(SERVER_HEARTBEAT_SEND, cy) : SERVER_HEARTBEAT_SEND; | ||
|
||
log.debug("Heart-beat negotiation - Client wants: {}, Server wants: {}", | ||
heartbeat, SERVER_HEARTBEAT_SEND + "," + SERVER_HEARTBEAT_RECEIVE); | ||
} | ||
} | ||
|
||
log.info("Negotiated heart-beat - Client to Server: {}, Server to Client: {}", | ||
clientToServer, serverToClient); | ||
|
||
accessor.setNativeHeader(HEART_BEAT_HEADER, clientToServer + "," + serverToClient); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters