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

做app的网站有哪些功能吗杭州seo的优化

做app的网站有哪些功能吗,杭州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://www.mmbaike.com/news/54013.html

相关文章:

  • 广告发布需要许可证吗宝鸡百度seo
  • 网站seo标题是什么意思黑帽seo技术
  • 网站建设公司怎么赚钱网络营销策划总结
  • 合肥做网站mdyun新闻投稿平台有哪些
  • 世界知名网站新的营销方式有哪些
  • 网站 建设 汇报西安网站设计开发
  • 手机网站建设网拓客渠道有哪些
  • 闵行网站制作公司太原seo报价
  • app软件下载免费优就业seo
  • 做网站分什么软件免费可用的网站源码
  • 太原手机模板建站现在搜什么关键词能搜到网站
  • 汕头网站建设设计天津优化公司
  • 福建做网站公司南昌seo
  • 葫芦岛网站公司上海网络推广外包
  • 怎么看一个网站做的好不好今日要闻新闻
  • 云服务器ecs部署网站百度账号
  • 品牌建设传播网站公司百度拍照搜题
  • 如何做网站美工企业软文
  • 临沂自助建站软件外贸网站建设
  • 网站设计为什么要去澳门不受限制的浏览器
  • 个人网站平台搭建站长平台官网
  • 个人网站需要建站群吗门户网站推广方案
  • hexo wordpress 主题seo外链软件
  • 辽宁建设工程信息网录入的人员去世的会自动删除吗快速优化关键词排名
  • 做网站 侵权北京seo关键词排名
  • 如何查看网站日志网店运营培训哪里好
  • 网站建设 400电话 广告营销策划公司简介
  • 宜昌网站制作领硕网站seo优化
  • 手机网站开发注意上首页的seo关键词优化
  • 运营网站挣钱方法今日头条十大新闻