栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 前沿技术 > 大数据 > 大数据系统

rabbitmq推送消息给前端(rabbitmq实时消息推送)

rabbitmq推送消息给前端(rabbitmq实时消息推送)

package com.demo.common;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;


@Configuration
public class RabbitConfig {

    @Bean
    Queue testQueue(){
        System.out.println("testQueue--------------------");
        // 队列名称
        return new Queue("testQueue");
    }

    
    @Bean
    DirectExchange testExchange(){
        return new DirectExchange("testExchange");
    }

    
    @Bean
    Binding testBinding(){
        return BindingBuilder
                .bind(testQueue())
                .to(testExchange())
                .with("testKey");
    }
}


 

package com.demo.controller;

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 SendMsgController {

    @Autowired
    private RabbitTemplate rabbitTempate;
    // 这个接口用于发送消息

    @GetMapping("/send")
    public String sendMsg(String msg) {
        rabbitTempate.convertAndSend("testExchange","testKey",msg);
        return "OK";
    }

}
server.port=8081
spring.application.name=mq
spring.rabbitmq.host=
# 下面为默认值,在没有修改的情况下可写可不写
spring.rabbitmq.username=
spring.rabbitmq.password=
spring.rabbitmq.port=5672
package com.demo;

import javafx.application.Application;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;


@SpringBootApplication(scanbasePackages={"com.demo"})

public class App {


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


}
 
        org.springframework.boot
        spring-boot-starter-parent
        2.1.4.RELEASE
    


    
        
            org.springframework.boot
            spring-boot-starter-amqp
        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
            org.projectlombok
            lombok
            true
        
        
            org.springframework.boot
            spring-boot-starter-test
            test
            
                
                    org.junit.vintage
                    junit-vintage-engine
                
            
        
        
            org.springframework.amqp
            spring-rabbit-test
            test
        

    

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/771841.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号