Rabbitmq नहीं है बनाने कतार स्वचालित रूप से जब वसंत बूट प्रकाशक भेज संदेश

0

सवाल

rabbitmq नहीं है बनाने कतार स्वचालित रूप से जब वसंत बूट प्रकाशक भेज संदेश ... मैं इसे इस तरह से किया है, तो यह बिना मैनुअल विन्यास और यह मेरा विन्यास ///////rabbitmq नहीं है बनाने कतार स्वचालित रूप से जब वसंत बूट प्रकाशक भेज संदेश ... मैं इसे इस तरह से किया है, तो यह बिना मैनुअल विन्यास और यह मेरा विन्यास

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 , ilove यू ... हाँ, मैं भूल गया कि ऐसा करने के लिए
muhammad

omg , ilove यू ... हाँ, मैं भूल गया कि ऐसा करने के लिए
muhammad

अच्छे - देखें stackoverflow.com/help/someone-answers
Gary Russell

अन्य भाषाओं में

यह पृष्ठ अन्य भाषाओं में है

Русский
..................................................................................................................
Italiano
..................................................................................................................
Polski
..................................................................................................................
Română
..................................................................................................................
한국어
..................................................................................................................
Français
..................................................................................................................
Türk
..................................................................................................................
Česk
..................................................................................................................
Português
..................................................................................................................
ไทย
..................................................................................................................
中文
..................................................................................................................
Español
..................................................................................................................
Slovenský
..................................................................................................................

इस श्रेणी में लोकप्रिय

लोकप्रिय सवाल इस श्रेणी में