1. 소개
Apache ActiveMQ 기반의 서비스인 Amazon MQ가 발표되었다. 즉, 매니지드 메세지 브로커 서비스이다.
2. 서비스
- ActiveMQ 콘솔
- 프로토콜 : JMS, NMS, AMQP, STOMP, MQTT 및 WebSocket
3. 콘솔
4. 생성
- AWS 콘솔에서 간단히 브로커 생성이 가능하다.
- 생성하면 바로 생성되지는 않고 약 10분 정도 소요되는 것 같았다.
- 퍼블릭 억세스 가능하다. (단, Security Group 오픈이 필요함)
5. 애플리케이션에서 Amazon MQ 연결 및 메세지 전송
5-1. pom.xml 파일에 추가
* 2018년 2월 현재 AWS를 통한 Active MQ 서버 버전은 5.10.0 이다.
<dependencies> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-client</artifactId> <version>5.15.0</version> </dependency> <dependency> <groupId>org.apache.activemq</groupId> <artifactId>activemq-pool</artifactId> <version>5.15.0</version> </dependency> <dependencies>
5-2. JMS Connection Factory 생성
// Create a connection factory. ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("ssl://b-1234a5b6-78cd-901e-2fgh-3i45j6k178l9-1.mq.us-east-1.amazonaws.com:61617"); // Specify the username and password. connectionFactory.setUserName("MyUsername123"); connectionFactory.setPassword("MyPassword456"); // Create a pooled connection factory. PooledConnectionFactory pooledConnectionFactory = new PooledConnectionFactory(); pooledConnectionFactory.setConnectionFactory(connectionFactory); pooledConnectionFactory.setMaxConnections(10); // Establish a connection for the producer. Connection producerConnection = pooledConnectionFactory.createConnection(); producerConnection.start();
5-3. Session 및 Message Producer 생성
// Create a session. Session producerSession = producerConnection.createSession(false, Session.AUTO_ACKNOWLEDGE); // Create a queue named "MyQueue". Destination producerDestination = producerSession.createQueue("MyQueue"); // Create a producer from the session to the queue. MessageProducer producer = producerSession.createProducer(producerDestination); producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
5-4. 메세지 생성 및 전송
// Create a message. String text = "Hello from Amazon MQ!"; TextMessage producerMessage = producerSession.createTextMessage(text); // Send the message. producer.send(producerMessage); System.out.println("Message sent.");
5-5. Producer 초기화
producer.close(); producerSession.close(); producerConnection.close();
6. 모니터링
2018년 8월부터 CloudWatch 로그를 통해 AMQ 메시지 브로커를 모니터링 할 수 있게 되었다. 일반 로그와 감시 로그의 게시가 가능하며, 브로커 리부팅에 대한 알람을 받거나 여러 오류를 해결할 수 있다.