본문으로 바로가기 본문 바로가기
WIKI 기술 지식 베이스

IntelliJ

원문 보기 위키 갱신

Dapr으로 디버깅하도록 IntelliJ 커뮤니티 에디션을 구성하는 방법을 안내해요. Dapr 애플리케이션을 개발할 때 일반적으로 Dapr CLI를 사용해 'Daprized' 서비스를 다음과 같이 시작해요.

dapr run --app-id nodeapp --app-port 3000 --dapr-http-port 3500 app.js

이렇게 하면 (기본적으로 dapr init 시 생성된) 기본 컴포넌트 yaml 파일을 사용해 서비스가 로컬 Redis 컨테이너와 상호 작용할 수 있어요. 이는 막 시작할 때는 좋지만, 서비스에 디버거를 연결해 코드를 한 단계씩 살펴보고 싶다면 어떻게 해야 할까요? 이때 앱을 호출하지 않고 dapr cli를 사용할 수 있어요. 서비스에 디버거를 연결하는 한 가지 방법은 먼저 명령줄에서 dapr run --를 실행한 다음 코드를 시작하고 디버거를 연결하는 거예요. 이는 완벽히 수용 가능한 해결책이지만 몇 가지 추가 단계(예: 터미널과 IDE 사이를 오가는)가 필요하고, 저장소를 클론해 "재생(play)" 버튼을 눌러 디버깅을 시작하려는 개발자에게 몇 가지 안내가 필요해요. 이 문서는 dapr을 IntelliJ에서 직접 사용하는 방법을 설명해요. 사전 요구 사항으로, dapr init로 Dapr의 개발 환경을 초기화했는지 확인하세요. 시작해 볼게요!

출처: Dapr 문서

본문

Dapr을 '외부 도구(External Tool)'로 추가

먼저 구성 파일을 직접 수정하기 전에 IntelliJ를 종료해야 해요.

IntelliJ 구성 파일 위치

2020.1 이상 버전의 경우 도구 구성 파일은 다음 위치에 있어야 해요.

  • Windows
  • Linux
  • MacOS
%USERPROFILE%\AppData\Roaming\JetBrains\IntelliJIdea2020.1\tools\
$HOME/.config/JetBrains/IntelliJIdea2020.1/tools/
~/Library/Application\ Support/JetBrains/IntelliJIdea2020.1/tools/

구성 파일 위치는 2019.3 이하 버전에서는 다르며, 자세한 내용은 여기에서 확인할 수 있어요.

필요하면 경로에서 IntelliJ 버전을 변경해요. <CONFIG PATH>/tools/External\ Tools.xml 파일을 만들거나 편집해요(필요하면 경로의 IntelliJ 버전 변경). <CONFIG PATH>는 위에서 본 것처럼 OS에 따라 달라져요. 새 <tool></tool> 항목을 추가해요.

<toolSet name="External Tools">
...
<!-- 1. Each tool has its own app-id, so create one per application to be debugged -->
<tool name="dapr for DemoService in examples" description="Dapr sidecar" showInMainMenu="false" showInEditor="false" showInProject="false" showInSearchPopup="false" disabled="false" useConsole="true" showConsoleOnStdOut="true" showConsoleOnStdErr="true" synchronizeAfterRun="true">
<exec>
<!-- 2. For Linux or MacOS use: /usr/local/bin/dapr -->
<option name="COMMAND" value="C:\dapr\dapr.exe" />
<!-- 3. Choose app, http and grpc ports that do not conflict with other daprd command entries (placement address should not change). -->
<option name="PARAMETERS" value="run -app-id demoservice -app-port 3000 -dapr-http-port 3005 -dapr-grpc-port 52000" />
<!-- 4. Use the folder where the `components` folder is located -->
<option name="WORKING_DIRECTORY" value="C:/Code/dapr/java-sdk/examples" />
</exec>
</tool>
...
</toolSet>

선택적으로 여러 프로젝트에 걸쳐 재사용할 수 있는 사이드카 도구에 대한 새 항목을 만들 수도 있어요.

<toolSet name="External Tools">
...
<!-- 1. Reusable entry for apps with app port. -->
<tool name="dapr with app-port" description="Dapr sidecar" showInMainMenu="false" showInEditor="false" showInProject="false" showInSearchPopup="false" disabled="false" useConsole="true" showConsoleOnStdOut="true" showConsoleOnStdErr="true" synchronizeAfterRun="true">
<exec>
<!-- 2. For Linux or MacOS use: /usr/local/bin/dapr -->
<option name="COMMAND" value="c:\dapr\dapr.exe" />
<!-- 3. Prompts user 4 times (in order): app id, app port, Dapr's http port, Dapr's grpc port. -->
<option name="PARAMETERS" value="run --app-id $Prompt$ --app-port $Prompt$ --dapr-http-port $Prompt$ --dapr-grpc-port $Prompt$" />
<!-- 4. Use the folder where the `components` folder is located -->
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$" />
</exec>
</tool>
<!-- 1. Reusable entry for apps without app port. -->
<tool name="dapr without app-port" description="Dapr sidecar" showInMainMenu="false" showInEditor="false" showInProject="false" showInSearchPopup="false" disabled="false" useConsole="true" showConsoleOnStdOut="true" showConsoleOnStdErr="true" synchronizeAfterRun="true">
<exec>
<!-- 2. For Linux or MacOS use: /usr/local/bin/dapr -->
<option name="COMMAND" value="c:\dapr\dapr.exe" />
<!-- 3. Prompts user 3 times (in order): app id, Dapr's http port, Dapr's grpc port. -->
<option name="PARAMETERS" value="run --app-id $Prompt$ --dapr-http-port $Prompt$ --dapr-grpc-port $Prompt$" />
<!-- 4. Use the folder where the `components` folder is located -->
<option name="WORKING_DIRECTORY" value="$ProjectFileDir$" />
</exec>
</tool>
...
</toolSet>

실행 구성 생성 또는 편집

이제 디버깅할 애플리케이션에 대한 실행 구성을 만들거나 편집해요. 이 항목은 main() 함수 옆 메뉴에서 찾을 수 있어요.

이제 프로그램 인자와 환경 변수를 추가해요. 이 값들은 위 '외부 도구(External Tool)' 항목에서 정의한 포트와 일치해야 해요.

  • 이 예시의 명령줄 인자: -p 3000
  • 이 예시의 환경 변수: DAPR_HTTP_PORT=3005;DAPR_GRPC_PORT=52000

디버깅 시작

위의 1회성 구성을 마치면 IntelliJ에서 Dapr으로 Java 애플리케이션을 디버깅하려면 두 단계가 필요해요.

  • IntelliJ에서 Tools -> External Tool을 통해 dapr을 시작해요.
  • 앱을 디버그 모드로 시작해요.

마무리

디버깅 후에는 IntelliJ에서 dapr과 앱을 모두 중지해야 해요. 참고: dapr run CLI 명령으로 서비스를 시작했기 때문에, dapr list 명령은 현재 Dapr으로 실행 중인 앱 목록에 IntelliJ의 실행을 표시할 거예요.

즐거운 디버깅 되세요!

관련 링크

  • IntelliJ 구성 디렉터리 위치 변경

더 알아보기 (Learn more)