Skip to content

Commit

Permalink
fix: Connection Prematurely Closed issue 대응 작업 (#987)
Browse files Browse the repository at this point in the history
slack 서버의 네트워크 관련 구성, 설정등을 알 수 없음. 따라서, Reactor Netty Docs(https://projectreactor.io/docs/netty/1.0.21/reference/index.html\#faq.connection-closed) 의 내용을 토대로 추정하여 대응한다.
  • Loading branch information
sakjung authored Apr 1, 2024
1 parent 1e6c325 commit 75652b6
Showing 1 changed file with 14 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,14 @@
import com.woowacourse.zzimkkong.dto.slack.SlackResponse;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.MediaType;
import org.springframework.http.client.reactive.ReactorClientHttpConnector;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.reactive.function.client.WebClient;
import reactor.netty.http.client.HttpClient;
import reactor.netty.resources.ConnectionProvider;

import java.time.Duration;
import java.util.Objects;

@Service
Expand All @@ -19,7 +23,14 @@ public class SlackService {
public SlackService(@Value("${service.url}") final String titleLink,
final WebClient webClient) {
this.titleLink = titleLink;
slackWebClient = webClient;
ConnectionProvider provider = ConnectionProvider.builder("slack-pool")
.maxConnections(10)
.maxIdleTime(Duration.ofSeconds(2L))
.maxLifeTime(Duration.ofSeconds(2L))
.lifo()
.build();
HttpClient httpClient = HttpClient.create(provider);
slackWebClient = webClient.mutate().clientConnector(new ReactorClientHttpConnector(httpClient)).build();
}

public void sendCreateMessage(SlackResponse slackResponse) {
Expand All @@ -39,10 +50,8 @@ public void sendDeleteMessage(SlackResponse slackResponse) {

private void send(final Attachments attachments, final String slackUrl) {
if (!Objects.isNull(slackUrl)) {
slackWebClient.mutate()
.baseUrl(slackUrl)
.build()
.post()
slackWebClient.post()
.uri(slackUrl)
.contentType(MediaType.APPLICATION_JSON)
.bodyValue(attachments.toString())
.retrieve()
Expand Down

0 comments on commit 75652b6

Please sign in to comment.