패키는 큐를 생성하지 않을 때 자동으로 봄의 부트 게시자가 보내 msg

0

질문

패키는 큐를 생성하지 않을 때 자동으로 봄의 부트 게시자가 보내 msg... 나는 그것을 이 방법은 그래서 그것은 설명서 없이 구성 이것은 나의 구성///////패키는 큐를 생성하지 않을 때 자동으로 봄의 부트 게시자가 보내 msg... 나는 그것을 이 방법은 그래서 그것은 설명서 없이 구성 이것은 나의 구성

package com.hariri_stocks.MQ;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.core.TopicExchange;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;


public class msgConfiguration {

    
    public static final String ROUTING_KEY1 = "routingKey1";
    public static final String STOCKS_EXCHANGE = "stocks_exchange";
    public static final String STOCKS_QUEUE = "stocks_queue";
    @Bean
    public Queue queue() {
        return new Queue(STOCKS_QUEUE , false);
    }
    @Bean
    public TopicExchange exchange() {
        return new TopicExchange(STOCKS_EXCHANGE );
    }
    @Bean
    public Binding binding()
    {
        return BindingBuilder.bind(queue()).to(exchange()).with(ROUTING_KEY1);
    }
    @Bean
    public MessageConverter converter()
    {
        return new Jackson2JsonMessageConverter();
    }

    @Bean
    public AmqpTemplate template(ConnectionFactory cf) {
        final RabbitTemplate rt = new RabbitTemplate(cf);
        rt.setMessageConverter(converter());
        return rt;
    }
}

package com.hariri_stocks.MQ;

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class Givver {

    @Autowired
    private RabbitTemplate template;
    
    @GetMapping("/msg")
    public String send() {
        msgStatus m = new msgStatus("ok","damn");
        template.convertSendAndReceive(msgConfiguration.STOCKS_EXCHANGE, msgConfiguration.ROUTING_KEY1,m);
        return "ok";
    }
}

입력한 이미지는 여기에 설명

spring.datasource.url=jdbc:mysql://localhost:3306/hariri_stocks
spring.datasource.username=root
spring.datasource.password=

spring.thymeleaf.enabled=true
spring.thymeleaf.check-template-location=true

spring.jpa.hibernate.ddl-auto=update
spring.jpa.generate-ddl=true 
spring.jpa.show-sql=true

server.port=9091
spring.application.name=hariri

1

최고의 응답

0

클래스 msgConfiguration 될 필요가 주석으로 @Configuration 한 콩을 추가하는 응용 프로그램이다.

또한 필요하지 않습 template 콩 봄 부팅이 자동 와이어 컨버터 콩으로 자동 구성된 RabbitTemplate.

2021-11-23 20:46:44

omg,근데요 그래요 나는 잊어 버렸지
muhammad

omg,근데요 그래요 나는 잊어 버렸지
muhammad

Gary Russell

다른 언어로

이 페이지는 다른 언어로되어 있습니다

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
हिन्दी
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................