docker run -d --name rabbitmq -p
5672:5672 -p 15672:15672 --restart=unless-stopped rabbitmq:management
- port 5672 : RabbitMQ Broker
- port 15672 : RabbitMQ 웹 관리 콘솔 (application.yml의 username, password 참고)
localhost:15672
에 접속해서 관련 설정을 확인하고 조작할 수 있다.- Direct Exchange를 확인하기 위해, application.yml에 설정된 (queue, key)와는 다른 (queue, key)를 만든다.
![image](https://private-user-images.githubusercontent.com/81238093/350670506-8046dfa3-c083-405d-bb79-8d29d98c5c73.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUyMzY2NzQsIm5iZiI6MTcyNTIzNjM3NCwicGF0aCI6Ii84MTIzODA5My8zNTA2NzA1MDYtODA0NmRmYTMtYzA4My00MDVkLWJiNzktOGQyOWQ5OGM1YzczLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTAyVDAwMTkzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTY5N2Q1Yzk0YzllMzI2M2Y0NzhjYTZiYzE4N2ZmYTAxMTgwZDExNWNkN2U1MDBlOWM5OWQ3Y2IyMDM4ODQzOWMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.2tWMsjGoM3lshHJpjQwb0NU2s1uWltFTa5o6ooRupBQ)
- Application을 실행하고
http://localhost:8080/send/message
로 요청을 보낸다. - RabbitTemplate이 제공하는
convertAndSend
메서드를 이용한sendMessage
서비스 메서드의 동작을 확인한다. Direct Exchange 전략을 사용하므로, exchange는 application.yml에 등록된 routing key와 일치하는 queue로 바인딩한다.
![image](https://private-user-images.githubusercontent.com/81238093/350672277-2737f74a-266e-4175-ad18-8ea9ebc22ecb.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUyMzY2NzQsIm5iZiI6MTcyNTIzNjM3NCwicGF0aCI6Ii84MTIzODA5My8zNTA2NzIyNzctMjczN2Y3NGEtMjY2ZS00MTc1LWFkMTgtOGVhOWViYzIyZWNiLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTAyVDAwMTkzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTE5YzhlY2ZkNmRmODZjNzA0Mzg4YTJhYWY0YzcyYzA3YzY3NzBhMzkzNWY0ZjcxNTU0MjFlNjI1YTFmYThhZjUmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.6rD_Tidsezpf4KpeFOh8W4YqOMnOXGkfDBVh8Z2AraE)
sample-queue
: routing key와 일치하는 queue, 메시지를 받아서 처리했음을 알 수 있다.
![image](https://private-user-images.githubusercontent.com/81238093/350672351-7ed8ae65-2fb0-4049-934d-07d49f7d91c9.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUyMzY2NzQsIm5iZiI6MTcyNTIzNjM3NCwicGF0aCI6Ii84MTIzODA5My8zNTA2NzIzNTEtN2VkOGFlNjUtMmZiMC00MDQ5LTkzNGQtMDdkNDlmN2Q5MWM5LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTAyVDAwMTkzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWFkY2Y2NGM3ZGJiNjkxMDUxODI0MDgzNWQ1Nzk1ZTM0MjQ2YTM5NDI2YTg1Y2RlOTYzNjVjZTM5Mzc4ZDQ2MTkmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.tIb1vYAYMtQXNp8qm0vuuUODmquqzMX1-prt2cJ4ZnY)
test-queue
: routing key와 일치하지 않는 queue, routing key가 달라 test-queue에 바인딩되지 않으므로, 처리한 메시지가 없다.
![image](https://private-user-images.githubusercontent.com/81238093/350672377-3b58665d-1a9c-4fbf-a933-dd1caccfb3a7.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUyMzY2NzQsIm5iZiI6MTcyNTIzNjM3NCwicGF0aCI6Ii84MTIzODA5My8zNTA2NzIzNzctM2I1ODY2NWQtMWE5Yy00ZmJmLWE5MzMtZGQxY2FjY2ZiM2E3LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA5MDIlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwOTAyVDAwMTkzNFomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPTFiMTkxMzU3ZTI4NzkzNTQ5ZGJmZGUxZjBiNWZjOTYzZTU4MTI5YmM2N2M0N2QyOWI4ZmI1ZWE0MWViNzdkZDMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0._ZjMxHlLW2_jZutUWVe7yNGCy_XBuEIhjH5QEi9BzQQ)