IT/서버

RabbitMQ 스프링에서 큐 만들고 바인딩 하기 +큐 삭제하기

thesse 2022. 6. 2. 15:00
300x250
반응형

conf 파일에 amqpAdmin 추가

    @Bean
    public AmqpAdmin amqpAdmin(ConnectionFactory connectionFactory){
        return new RabbitAdmin(connectionFactory);
    }

 

 

컨트롤러

    @Autowired
    private AmqpAdmin amqpAdmin;
    

    // 큐 추가
    @PostMapping("/queue")
    public ResponseEntity createQueue(@RequestParam("queueName") String queueName,
                                      @RequestParam("routingKey") String routingKey){
        Queue queue = new Queue(queueName, true, false, false);
        Binding binding = new Binding(queueName, Binding.DestinationType.QUEUE, EXCHANGE_NAME, routingKey, null);
        amqpAdmin.declareQueue(queue);
        amqpAdmin.declareBinding(binding);
        return ResponseEntity.ok().build();
    }
    
    // 큐 삭제
    @DeleteMapping("/queue")
    public ResponseEntity delelteQueue(@RequestParam("queueName") String queueName){
        amqpAdmin.deleteQueue(queueName);
        return ResponseEntity.ok().build();
    }

 

300x250
반응형