Giter VIP home page Giter VIP logo

spring-cloud-stream-rabbitmq's Introduction

Spring Cloud Stream example apps

using RabbitMQ

  • 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 관리자 화면

http://localhost:15672

application.yml 바인더 설정

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 에 채널 바인딩 정보 기술

Logging Consumer application

Spring Cloud Stream QuickStart

  • Consumer 를 이용한 단일 메시지 핸들러 구현 (framework convention)
  • RabbitMQ 관리자 화면에서 Application 실행 시 생성된 큐로 Person 클래스 JSON 데이터를 publish 하면 메시지 수신 로그 출력
{"name":"sam smith"}

MyLoggerService application

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 메시지 발송 시 헤더에 contentTypetext/plain 으로 지정
    public TextPlainMessageConverter() {
        super(new MimeType("text", "plain"));
    }

Multiple Outputs application

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();
}

바인딩 채널의 이름 명명 규칙

  • 어노테이션으로 이름 지정, 아니면 메소드 이름
    1. input channel 의 이름은 myInput
    2. output channel 의 이름은 myOutput
    3. output channel 의 이름은 anotherOutput

spring-cloud-stream-rabbitmq's People

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.