码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • RabbtiMQ的安装与使用


    一、安装Erlang与Rabbitmq

     安装教程本教程是在centos8下试验的,其实linux系统的都差不多RabbitMQ官方:Messaging that just works — RabbitMQRabbitMQ是开源AMQP实现,服务器端用Erlang语言编写,Python、Ruby、 NET、Java、JMS、c、PHP、action screcrive AMQP (高级消息队列协议)和高级消息队列协议是APP应用层协议的开放标准,是为面向消息的中间件而设计的。消息中间件主要用于组件之间的解耦,其中消息的发送方不需要知道消息使用者的存在,反之_rabbitmq安装https://blog.csdn.net/weixin_44545251/article/details/128216395

    二、在springboot中使用rabbitmq

    1.导入依赖

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

    2.编写配置文件

    spring:
     rabbitmq:
       host: localhost
       port: 5672
       username: guest
       password: guest

    3.配置一个队列

    1. package com.example.Rabbtimq.config;
    2. import org.springframework.amqp.core.Queue;
    3. import org.springframework.context.annotation.Bean;
    4. import org.springframework.context.annotation.Configuration;
    5. @Configuration
    6. public class QueueAndExchangeConfig {
    7. @Bean("myFirstQueue")
    8. public Queue getFirstQueue(){
    9. return new Queue("my-first-queue");
    10. }
    11. }

    4.编写一个生产者类

    1. package com.example.Rabbtimq.controller;
    2. import org.springframework.amqp.rabbit.core.RabbitTemplate;
    3. import org.springframework.beans.factory.annotation.Autowired;
    4. import org.springframework.stereotype.Controller;
    5. import org.springframework.web.bind.annotation.GetMapping;
    6. import org.springframework.web.bind.annotation.RequestMapping;
    7. import org.springframework.web.bind.annotation.RestController;
    8. @RestController
    9. @RequestMapping("producer")
    10. public class RabbitMqController {
    11. @Autowired
    12. private RabbitTemplate rabbitTemplate;
    13. @GetMapping("producerSendFirstQueue")
    14. public String sendMsg(String msg){
    15. rabbitTemplate.convertAndSend("my-first-queue",msg);
    16. return msg;
    17. }
    18. }

    5.编写一个消费者监听队列中的消息

    1. package com.example.Rabbtimq.controller;
    2. import org.springframework.amqp.rabbit.annotation.RabbitListener;
    3. import org.springframework.amqp.rabbit.core.RabbitTemplate;
    4. import org.springframework.beans.factory.annotation.Autowired;
    5. import org.springframework.stereotype.Component;
    6. import org.springframework.web.bind.annotation.GetMapping;
    7. import org.springframework.web.bind.annotation.RequestMapping;
    8. import org.springframework.web.bind.annotation.RestController;
    9. @Component
    10. public class ConsumerHandler {
    11. @RabbitListener(queues = "my-first-queue")
    12. public void getFirstQueue(String msg){
    13. System.out.println("消费者1:"+msg);
    14. }
    15. }

    6.使用接口工具调生产接口

    7.查看图形化界面

  • 相关阅读:
    JavaScript中的隐含参数arguments
    【剑指 Offer 05. 替换空格】
    【数据结构】建立二叉树以及哈夫曼树及哈夫曼编码
    淘宝天猫API_获取商品详情原数据
    MATLAB APP纯小白入门 两数相加
    SpringBoot整合百度云人脸识别功能
    undefined /swagger/v1/swagger.json错误解决
    纯文本邮件发送:java
    Python和SQLite游标处理多行数据
    「前端+鸿蒙」核心技术HTML5+CSS3(十)
  • 原文地址:https://blog.csdn.net/m0_75015491/article/details/132698725
  • 最新文章
  • 攻防演习之三天拿下官网站群
    数据安全治理学习——前期安全规划和安全管理体系建设
    企业安全 | 企业内一次钓鱼演练准备过程
    内网渗透测试 | Kerberos协议及其部分攻击手法
    0day的产生 | 不懂代码的"代码审计"
    安装scrcpy-client模块av模块异常,环境问题解决方案
    leetcode hot100【LeetCode 279. 完全平方数】java实现
    OpenWrt下安装Mosquitto
    AnatoMask论文汇总
    【AI日记】24.11.01 LangChain、openai api和github copilot
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1
正则表达式工具 cron表达式工具 密码生成工具

京公网安备 11010502049817号