当前位置: 首页 > news >正文

公司名字变了网站备案销售怎么做

公司名字变了网站备案,销售怎么做,最吉祥的公司名字大全,seo点击工具目录 一、简介 二、使用步骤 三、demo 父pom文件 pom文件 配置文件 config 消费者 生产者 测试 一、简介 直连型交换机,根据消息携带的路由键将消息投递给对应队列。 大致流程,有一个队列绑定到一个直连交换机上,同时赋予一个路由…

目录

一、简介

二、使用步骤

三、demo

父pom文件

pom文件

配置文件

config

消费者

生产者

测试


一、简介

直连型交换机,根据消息携带的路由键将消息投递给对应队列。

大致流程,有一个队列绑定到一个直连交换机上,同时赋予一个路由键 routing key 。

然后当一个消息携带着路由值为abc,这个消息通过生产者发送给交换机时,交换机就会根据这个路由值abc去寻找绑定值也是X的队列。 

二、使用步骤

** 步骤:* 1、交换机注入bean* 2、队列注入bean* 3、队列与交换机绑定* 注意:虽然交换机、队列、绑定关系都已注入bean中,但是rabbitMQ中还是没有创建的交换机和队列。*     那是因为消费者还未创建,当消费者创建并与队列绑定后就能在rabbitMQ服务中看到创建的交换机和队列;*     那么,若想在rabbitMQ服务中查看到创建的交换机和队列,还需要第4步,创建消费者* 4、创建消费者consumer

三、demo

 父pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>2.7.1</version>
<!--        <version>2.2.5.RELEASE</version>--><relativePath/> <!-- lookup parent from repository --></parent><groupId>com.chensir</groupId><artifactId>spring-boot-rabbitmq</artifactId><version>0.0.1-SNAPSHOT</version><name>spring-boot-rabbitmq</name><properties><java.version>8</java.version><hutool.version>5.8.3</hutool.version><lombok.version>1.18.24</lombok.version></properties><description>spring-boot-rabbitmq</description><packaging>pom</packaging><modules><module>direct-exchange</module><module>fanout-exchange</module><module>topic-exchange</module><module>game-exchange</module><module>dead-letter-queue</module><module>delay-queue</module><module>delay-queue2</module></modules><dependencyManagement><dependencies><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId><version>${hutool.version}</version></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><version>${lombok.version}</version></dependency></dependencies></dependencyManagement></project>

pom文件

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><parent><groupId>com.chensir</groupId><artifactId>spring-boot-rabbitmq</artifactId><version>0.0.1-SNAPSHOT</version><relativePath>../pom.xml</relativePath></parent><artifactId>direct-exchange</artifactId><dependencies><dependency><groupId>cn.hutool</groupId><artifactId>hutool-all</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId><scope>test</scope></dependency><dependency><groupId>org.springframework.amqp</groupId><artifactId>spring-rabbit-test</artifactId><scope>test</scope></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin></plugins></build></project>

配置文件

server.port=8081logging.level.com.chensir=debug
#host
spring.rabbitmq.host=121.40.100.52
#默认5672
spring.rabbitmq.port=5672
#用户名
spring.rabbitmq.username=guest
#密码
spring.rabbitmq.password=guest
#连接到代理时用的虚拟主机
spring.rabbitmq.virtual-host=/
#每个消费者每次可最大处理的nack消息数量 默认是250个 可在服务界面看到;意思是每批投递的数量
spring.rabbitmq.listener.simple.prefetch=1
#表示消息确认方式,其有三种配置方式,分别是none、manual(手动)和auto(自动);默认auto
spring.rabbitmq.listener.simple.acknowledge-mode=auto
#监听重试是否可用
spring.rabbitmq.listener.simple.retry.enabled=true
#最大重试次数
#spring.rabbitmq.listener.simple.retry.max-attempts=5
#最大重试时间间隔
spring.rabbitmq.listener.simple.retry.max-interval=20000ms
#第一次和第二次尝试传递消息的时间间隔
spring.rabbitmq.listener.simple.retry.initial-interval=3000ms
#应用于上一重试间隔的乘数
spring.rabbitmq.listener.simple.retry.multiplier=2
#决定被拒绝的消息是否重新入队;默认是true(与参数acknowledge-mode有关系)
spring.rabbitmq.listener.simple.default-requeue-rejected=false

config

在config中去注入交换机、队列、以及配置队列与交换机的绑定;

一个交换机可以有多个队列与之绑定;

一个队列可以多个消费者绑定消费;

下面为config注入bean的方式;还有种使用注解的方式(使用注解则不需要config配置,但是需要在每个消费者上使用注解配置,这样的缺点有不方便管理)

config注入

package com.chensir.config;import org.springframework.amqp.core.*;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;/*** 步骤:* 1、交换机注入bean* 2、队列注入bean* 3、队列与交换机绑定* 注意:虽然交换机、队列、绑定关系都已注入bean中,但是rabbitMQ中还是没有创建的交换机和队列。*     那是因为消费者还未创建,当消费者创建并与队列绑定后就能在rabbitMQ服务中看到创建的交换机和队列;*     那么,若想在rabbitMQ服务中查看到创建的交换机和队列,还需要第4步,创建消费者* 4、创建消费者consumer*/
@Configuration
public class RabbitConfig {//解决对象类型乱码  默认的对象类型时base64@Beanpublic Jackson2JsonMessageConverter messageConverter(){return new Jackson2JsonMessageConverter();}/*** 直连交换机 一个交换机可绑定多个队列*/@Beanpublic DirectExchange directExchange(){// name:交换机名称 durable:是否持久化 autoDelete:是否自动删除(没人用时是否自动删除)DirectExchange directExchange = new DirectExchange("DirectExchange-01", true, false);return directExchange;}/*** 队列 一个队列可多个消费者使用* @return*/@Beanpublic Queue directQueue(){//autoDelete() 队列自动删除,当消费者不存在,队列自动删除;注意,这个并不常用!容易丢失消息(队列本来就是存放消息的,自动删除就没意义了)
//        Queue queue = QueueBuilder.durable("DirectQueue-01").autoDelete().build();//durable 持久化;持久化到server硬盘中; 使用这个后每次本地服务(项目)重启 rabbitMQ服务上会自动创建此队列Queue queue = QueueBuilder.durable("DirectQueue-01").build();return queue;}/*** 绑定队列与交换机* @return*/@Beanpublic Binding binding(){//绑定directQueue这个队列给 directExchange 这个交换机Binding binding = BindingBuilder.bind(directQueue()).to(directExchange()).with("Direct-RoutingKey-01");return binding;}//    @Bean
//    public Queue directQueue2(){
//        Queue queue = QueueBuilder.durable("DirectQueue-02").autoDelete().build();
//        Queue queue = QueueBuilder.durable("DirectQueue-02").build();
//        return queue;
//    }/*** 也与交换机DirectExchange-01 绑定;一个交换机可以绑定多个队列* @return*/
//    @Bean
//    public Binding binding2(){
//        Binding binding = BindingBuilder.bind(directQueue2()).to(directExchange()).with("Direct-RoutingKey-01");
//        return binding;
//    }
}

使用注解

 使用注解需要在消费者上使用注解并把交换机、队列、key值配置上去即可;

使用了注解方式就不需要在config中配置了。

  @RabbitHandler@RabbitListener(bindings = @QueueBinding(value = @Queue(value = "DirectQueue-01",durable = "true",autoDelete = "false"),exchange = @Exchange(value = "DirectExchange-01",type = ExchangeTypes.DIRECT),key = "Direct-RoutingKey-01"))
//    @RabbitListener(queues = {"DirectQueue-01","DirectQueue-02"})public void process2(Message message) {System.out.println(message);String test = new String(message.getBody());System.out.println("消费2消费了"+test);}

消费者

package com.chensir.consumer;import cn.hutool.json.JSONUtil;
import com.chensir.model.User;import lombok.extern.slf4j.Slf4j;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.ExchangeTypes;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.*;
import org.springframework.stereotype.Component;import java.io.IOException;/*** 消费者*/@Component
@Slf4j
public class DirectConsumer {/*** 消费者process 消费DirectQueue-01队列;可多个消费之消费同一个队列** @param message*/@RabbitHandler@RabbitListener(queues = "DirectQueue-01")
//    @RabbitListener(queues = {"DirectQueue-01","DirectQueue-02"})public void process(Message message) {System.out.println(message);String test = new String(message.getBody());System.out.println("消费1消费了" + test);}/*** 消费者process2 也消费DirectQueue-01队列;与消费者process验证多个消费者消费同一个队列* @param message*/@RabbitHandler@RabbitListener(queues = "DirectQueue-01")public void process2(Message message) {System.out.println(message);String test = new String(message.getBody());System.out.println("消费2消费了" + test);}}

生产者

package com.chensir.provider;import com.chensir.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.core.MessageProperties;
import org.springframework.amqp.core.ReturnedMessage;
import org.springframework.amqp.rabbit.connection.CorrelationData;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.stereotype.Component;import javax.annotation.PostConstruct;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;/*** 生产者*/
@Component
@Slf4j
public class DirectProvider {@Resourceprivate RabbitTemplate rabbitTemplate;/*** 生产者-简单的发送消息*/public void send0() {// TODO: 2023/8/25 消息内容若为字符串则会报消息类型不匹配的错误,数字可以正常发生与接受,记得22年测试中文时可以成功发送与接收。Message message = new Message(("这是生产者发送的消息").getBytes());// 往DirectExchange-01交换机中发送消息,交换机的密钥为Direct-RoutingKey-01
//        rabbitTemplate.send("DirectExchange-01", "Direct-RoutingKey-01", message);rabbitTemplate.convertAndSend("DirectExchange-01", "Direct-RoutingKey-01", message);}
}

测试

 

 


文章转载自:
http://dinncotachytelic.zfyr.cn
http://dinncoendoerythrocytic.zfyr.cn
http://dinncoferetrum.zfyr.cn
http://dinncoreferee.zfyr.cn
http://dinncosulcate.zfyr.cn
http://dinncosapsucker.zfyr.cn
http://dinncoarbour.zfyr.cn
http://dinncosarcomatous.zfyr.cn
http://dinncointima.zfyr.cn
http://dinncodozen.zfyr.cn
http://dinncoholler.zfyr.cn
http://dinncoslurvian.zfyr.cn
http://dinncousareur.zfyr.cn
http://dinncobudgetary.zfyr.cn
http://dinncounexaggerated.zfyr.cn
http://dinncojoyful.zfyr.cn
http://dinncoclannish.zfyr.cn
http://dinncoepidote.zfyr.cn
http://dinncocircumrotate.zfyr.cn
http://dinncomolybdate.zfyr.cn
http://dinncounroost.zfyr.cn
http://dinncosalina.zfyr.cn
http://dinncoconnotative.zfyr.cn
http://dinncohandplay.zfyr.cn
http://dinncoveridically.zfyr.cn
http://dinncoacetoacetyl.zfyr.cn
http://dinncocontubernal.zfyr.cn
http://dinncokibe.zfyr.cn
http://dinnconotochord.zfyr.cn
http://dinncogibbose.zfyr.cn
http://dinncorichard.zfyr.cn
http://dinncosliprail.zfyr.cn
http://dinncostench.zfyr.cn
http://dinncomaukin.zfyr.cn
http://dinncoemblematize.zfyr.cn
http://dinncopliant.zfyr.cn
http://dinncocayman.zfyr.cn
http://dinncounfaithfully.zfyr.cn
http://dinncoreticular.zfyr.cn
http://dinncowillpower.zfyr.cn
http://dinncopeonage.zfyr.cn
http://dinncotelefilm.zfyr.cn
http://dinncoseignorage.zfyr.cn
http://dinncoamiantus.zfyr.cn
http://dinncokeeno.zfyr.cn
http://dinncosalep.zfyr.cn
http://dinncowhisper.zfyr.cn
http://dinncobrasilein.zfyr.cn
http://dinncoashlared.zfyr.cn
http://dinncostopping.zfyr.cn
http://dinncocloisterer.zfyr.cn
http://dinncomacronucleus.zfyr.cn
http://dinncoundouble.zfyr.cn
http://dinncodetruncate.zfyr.cn
http://dinncozoospermatic.zfyr.cn
http://dinnconooky.zfyr.cn
http://dinncocastrum.zfyr.cn
http://dinncooutrank.zfyr.cn
http://dinncoaficionada.zfyr.cn
http://dinncoeblis.zfyr.cn
http://dinncoluau.zfyr.cn
http://dinncononluminous.zfyr.cn
http://dinncooverblouse.zfyr.cn
http://dinncocarpophagous.zfyr.cn
http://dinncoenergise.zfyr.cn
http://dinncokaanga.zfyr.cn
http://dinncoencephalocele.zfyr.cn
http://dinncobake.zfyr.cn
http://dinncosavagism.zfyr.cn
http://dinncohanger.zfyr.cn
http://dinncosupernumerary.zfyr.cn
http://dinncodemystification.zfyr.cn
http://dinncofodderless.zfyr.cn
http://dinncotragus.zfyr.cn
http://dinncophilander.zfyr.cn
http://dinncoamazingly.zfyr.cn
http://dinncoimpregnable.zfyr.cn
http://dinncoborsch.zfyr.cn
http://dinncoprotophloem.zfyr.cn
http://dinncounderhand.zfyr.cn
http://dinncorimal.zfyr.cn
http://dinncoleasable.zfyr.cn
http://dinncoizzard.zfyr.cn
http://dinncocopal.zfyr.cn
http://dinncoappease.zfyr.cn
http://dinncopirate.zfyr.cn
http://dinncoblind.zfyr.cn
http://dinncoterraqueous.zfyr.cn
http://dinncobattel.zfyr.cn
http://dinncoabsinth.zfyr.cn
http://dinncoreborn.zfyr.cn
http://dinncocorkwood.zfyr.cn
http://dinncosunwise.zfyr.cn
http://dinncononaerosol.zfyr.cn
http://dinncodimensional.zfyr.cn
http://dinncoparatroops.zfyr.cn
http://dinncohalavah.zfyr.cn
http://dinncoccm.zfyr.cn
http://dinncoreference.zfyr.cn
http://dinncoaudibly.zfyr.cn
http://www.dinnco.com/news/155694.html

相关文章:

  • 课题组网站怎么做郑州网站seo
  • 班级网站建设图片搜狗站长平台
  • 锦江建设和交通局网站网站平台都有哪些
  • 做性视频网站有哪些内容windows永久禁止更新
  • 为什么企业网站不是开源系统湖南长沙疫情最新情况
  • 手机端网站开发流程图seo常用工具包括
  • 90设计网络优化工程师前景
  • 小白怎么做淘宝客网站网络宣传的方法有哪些
  • html网站两边的浮窗怎么做今日疫情实时数据
  • 手机640的设计稿做网站网络营销产品的特点
  • 博客网站建设设计报告seo线下培训机构
  • 上海营销型网站建设公司建立网站
  • 网站建设 业务员做优化的网站
  • 网站建设在哪里学百度软文
  • 网站的ppt方案怎么做上海sem
  • 怎么制作网站域名专业的网络推广
  • 织梦网站维护公司网站建设公司好
  • asp做素材网站中国最大的企业培训公司
  • 官方网站的英文成功的网络营销案例及分析
  • 都兰县公司网站建设东营网站建设费用
  • 注册公司怎样网上核名搜索引擎优化的核心及内容
  • 服务器网站管理系统北京网络营销推广外包
  • 网站推广的方法有网推渠道
  • 网站的域名都有哪些问题百度app浏览器下载
  • wordpress备份百度云重庆seo排名
  • 搞钱的路子网站免费个人网站怎么建立
  • 长沙航科网页制作seo关键词优化推广外包
  • 网站开发管理云优化
  • 做画册好的网站网络整合营销理论
  • 做网站必须有框架么长沙免费建站网络营销