MAC RabbitMq 설치, springboot HelloWorld 예제

MAC RabbitMq 설치, springboot HelloWorld 예제

http://www.rabbitmq.com/install-standalone-mac.html
brew설치되어 있다고 가정하고 터미널에서 아래 명령어 실행

[simterm]
$ brew install rabbitmq
…..설치완료 후
$ cd /usr/local/sbin
$ ./rabbitmq-server
구동완료
[/simterm]

spring.rabbitmq.host=localhost
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guest
package com.htrucci.bootmessaging;

import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitMessagingTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Component;
import sun.tools.jar.CommandLine;

@SpringBootApplication
public class BootmessagingApplication implements CommandLineRunner {

    @Autowired
    Sender sender;

    public static void main(String[] args) {
        SpringApplication.run(BootmessagingApplication.class, args);
    }


    @Override
    public void run(String... args) throws Exception {
        sender.send("Hello Message!!!");
    }
}

@Component
class Sender{
    @Autowired
    RabbitMessagingTemplate template;

    @Bean
    Queue queue(){
        return new Queue("TestQ", false);
    }

    public void send(String message){
        template.convertAndSend("TestQ", message);
    }
}

@Component
class Receiver{
    @RabbitListener(queues = "TestQ")
    public void processMessage(String content){
        System.out.println(content);
    }
}

 

You may also like...

답글 남기기

이메일은 공개되지 않습니다. 필수 입력창은 * 로 표시되어 있습니다.