2024年最全rabbitmq 工作模式(未完全版只demo)(1),330页PDF10万字的知识点总结

img
img

网上学习资料一大堆,但如果学到的知识不成体系,遇到问题时只是浅尝辄止,不再深入研究,那么很难做到真正的技术提升。

需要这份系统化资料的朋友,可以戳这里获取

一个人可以走的很快,但一群人才能走的更远!不论你是正从事IT行业的老鸟或是对IT行业感兴趣的新人,都欢迎加入我们的的圈子(技术交流、学习资源、职场吐槽、大厂内推、面试辅导),让我们一起学习成长!

@RabbitListener(queues = "send1")
public void send1(String s) throws InterruptedException {
    Thread.sleep(Long.parseLong("1000"));
    System.out.println("当前1 "+s);

}
@RabbitListener(queues = "send1")
public void send2(String s){
    System.out.println("当前2 "+s);
}

}


### Publish(广播模式)


#### 调用



package com.example.demo.Publish;

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;
import java.util.HashMap;
import java.util.Map;
@RestController
public class publish {
@Autowired
RabbitTemplate rabbitTemplate;
@GetMapping(“/ces”)
public void testSendPublish(){

    //1.交换机的名称 2.你的规则,发布订阅模式为空 3.消息的主题
    try {
        rabbitTemplate.convertAndSend("logs","","work message");
    }catch (Exception e){
        e.printStackTrace();
    }
}

}


### 接收



package com.example.demo.Publish;
import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;
// d定义一个 log交换机 类型为 fanout
/*@Queue注解为我们提供了队列相关的一些属性,具体如下:
name: 队列的名称;
durable: 是否持久化;
exclusive: 是否独享、排外的;
autoDelete: 是否自动删除;
arguments:队列的其他属性参数,有如下可选项,可参看图2的arguments:*/

@Component
public class PublishListen {
@RabbitListener(bindings = {
@QueueBinding(exchange = @Exchange(value = “logs”,type = “fanout”),//绑定交换机 类型为fanout
value=@Queue // 创建临时队列

        )
})
public void receive(String message){
    System.out.println("receive1 =" +message);
}
@RabbitListener(bindings = {
        @QueueBinding(exchange = @Exchange(value = "logs",type = "fanout"),//绑定交换机 类型为fanout
                value=@Queue // 创建临时队列
        )
})
public void receive2(String message){
    System.out.println("receive2 =" +message);
}

}


### route(路由模式)


#### 创建



package com.example.demo.cesdir;

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;

import java.util.HashMap;
import java.util.Map;
@RestController
public class Publish1{
@Autowired
RabbitTemplate rabbitTemplate;
@GetMapping(“/ces11”)
public void testSendPublish(){

    //1.交换机的名称 2.你的规则,发布订阅模式为空 3.消息的主题
    for (int i = 0; i <6 ; i++) {

String a=“a”+i;
try {
rabbitTemplate.convertAndSend(“cesdir”,a,a);
}catch (Exception e){
e.printStackTrace();
}
}
}

}


### 接收



package com.example.demo.cesdir;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.context.annotation.Configuration;

@Configuration
public class PublishListen1 {
@RabbitListener(bindings = @QueueBinding(
key = {“a1”,“a2”},
exchange=@Exchange(value = “cesdir”,type = “direct”),
value = @Queue
))
public void ces1(String a){
System.out.println(" a1 a2 : "+a);
}

@RabbitListener(bindings = @QueueBinding(
value = @Queue,
exchange = @Exchange(value = “cesdir”,type = “direct”),
key = {“a3”,“a4”}
))
public void ces2(String a){
System.out.println(" a3 a4 : “+a);
}
@RabbitListener(bindings = @QueueBinding(
value = @Queue,
exchange = @Exchange(value = “cesdir”,type = “direct”),
key = {“a4”,“a5”,“a3”}
))
public void ces3(String a){
System.out.println(” a3 a4 a5 : "+a);
}

}


### Topics(主题模式)


#### 创建 主题模式和路由模式区别为key 绑定 路由模式key={“key1”,“key2”} 主题模式key={"*.key.#"} \* # , #”表示匹配一个或多个词,符号“*”表示匹配一个词。



package com.example.demo.cesTip;

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 Publish2 {
@Autowired
RabbitTemplate rabbitTemplate;
@GetMapping(“ces222”)
public void ces222(){
for (int i = 0; i < 6; i++) {
String a1=“ces.a.”+i+“c”;
System.out.println("a1 "+a1);
rabbitTemplate.convertAndSend(“Topics”,a1,a1);
}
}
}


### 接收



package com.example.demo.cesTip;

import org.springframework.amqp.rabbit.annotation.Exchange;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.QueueBinding;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

@Component
public class PublishListen2 {

@RabbitListener( bindings = @QueueBinding(
        value = @Queue, //创建临时队列
        exchange = @Exchange(value = "Topics", type = "topic"),
        key = {"ces.\*.\*"}
)
)
public void receive1(String message){
    System.out.println("receive 1 = " + message);
}
@RabbitListener( bindings = @QueueBinding(
        value = @Queue, //创建临时队列
        exchange = @Exchange(value = "Topics", type = "topic"),
        key = {"ces.#"}
)
)
public void receive2(String message){
    System.out.println("receive 2 = " + message);
}


@RabbitListener( bindings = @QueueBinding(
        value = @Queue, //创建临时队列
        exchange = @Exchange(value = "Topics", type = "topic"),
        key = {"#.a.\*"}
)
)
public void receive3(String message){
    System.out.println("receive 3 = " + message);
}

}

img
img
img

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

9)]
[外链图片转存中…(img-5w4k1xlv-1715281419089)]

既有适合小白学习的零基础资料,也有适合3年以上经验的小伙伴深入学习提升的进阶课程,涵盖了95%以上大数据知识点,真正体系化!

由于文件比较多,这里只是将部分目录截图出来,全套包含大厂面经、学习笔记、源码讲义、实战项目、大纲路线、讲解视频,并且后续会持续更新

需要这份系统化资料的朋友,可以戳这里获取

  • 29
    点赞
  • 16
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值