- docker-compose.yml
version: '3'
services:
rabbitmq:
image: rabbitmq:3-management-alpine
container_name: rabbitmq-stream
ports:
- 5672:5672
- 15672:15672
environment:
RABBITMQ_DEFAULT_USER: admin
RABBITMQ_DEFAULT_PASS: admin
- 실행
$ docker-compose up -d
- RabbitMQ 관리자 화면
spring:
cloud:
stream:
bindings:
input:
destination: queue.log.messages
binder: local_rabbit
output:
destination: queue.pretty.log.messages
binder: local_rabbit
binders:
local_rabbit:
type: rabbit
environment:
spring:
rabbitmq:
host: localhost
port: 5672
username: admin
password: admin
virtual-host: /
spring.cloud.stream.binders
에 바인딩 하는 미들웨어 정보 기술spring.cloud.stream.bindings
에 채널 바인딩 정보 기술
Spring Cloud Stream QuickStart
- Consumer 를 이용한 단일 메시지 핸들러 구현 (framework convention)
- RabbitMQ 관리자 화면에서 Application 실행 시 생성된 큐로 Person 클래스 JSON 데이터를 publish 하면 메시지 수신 로그 출력
{"name":"sam smith"}
Introduction to Spring Cloud Stream
- Processor binding sample
- listens to input binding and sends a response to output binding
- RabbitMQ admin 에서 publish message
{"message":"test message"}
- TextPlainMessageConvert 로 메시지 변환 처리
- MimeType 으로 text/plain 메시지만 converter 로 처리
- RabbitMQ 메시지 발송 시 헤더에
contentType
을text/plain
으로 지정
public TextPlainMessageConverter() {
super(new MimeType("text", "plain"));
}
Introduction to Spring Cloud Stream
- Custom channel sample
public interface MyProcessor {
String INPUT = "myInput";
@Input // #1
SubscribableChannel myInput();
@Output("myOutput") // #2
MessageChannel anOutput();
@Output // #3
MessageChannel anotherOutput();
}
- 어노테이션으로 이름 지정, 아니면 메소드 이름
- input channel 의 이름은
myInput
- output channel 의 이름은
myOutput
- output channel 의 이름은
anotherOutput
- input channel 의 이름은