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

做网站费用是什么百度招聘2022年最新招聘

做网站费用是什么,百度招聘2022年最新招聘,it企业网站模板,淄博市疫情风险等级接上一篇《RabbitMQ-安装篇(阿里云主机)-CSDN博客》 安装好RabbitMQ后,我们将开始RabbitMQ的使用,根据官网文档RabbitMQ Tutorials | RabbitMQ,我们一步一步的学习。 1. "Hello World!" 这里先说明几个概…

接上一篇《RabbitMQ-安装篇(阿里云主机)-CSDN博客》

安装好RabbitMQ后,我们将开始RabbitMQ的使用,根据官网文档RabbitMQ Tutorials | RabbitMQ,我们一步一步的学习。

1. "Hello World!"

这里先说明几个概念:

生产者:指消息的发送方,用图例表示。

消费者:指消息的接收放,用图例表示。

队列(queue):生产者发送的消息将被传递到队列里,消费这从队列中消费消息

下面以 生产者 发送消息到队列,消费者从队列里消费消息为例,演示如何调用(Java代码)。

RabbitMQ支持多种协议。本教程使用AMQP0-9-1,它是一个开放的、通用的消息传递协议。

1.1 下载依赖项

下载客户端库客户端连接库及其依赖项(SLF4J API和SLF4J Simple)。将这些文件复制到您的工作目录中,连同教程Java文件。

1.2 生产者代码-Send.java

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;import java.nio.charset.StandardCharsets;//生产者
public class Send {public static void main(String[] argv) throws Exception {// 创建连接ConnectionFactory factory = new ConnectionFactory();factory.setHost("【服务器地址】");factory.setPort(【端口:默认5672】);factory.setUsername("【账号】");factory.setPassword("【密码】");factory.setVirtualHost("【虚拟主机】");// 创建信道,发送消息String queueName = "rc.queue";try (Connection connection = factory.newConnection(); Channel channel = connection.createChannel()) {channel.queueDeclare(queueName, true, false, false, null);String message = "Hello World!";channel.basicPublish("", queueName, null, message.getBytes(StandardCharsets.UTF_8));System.out.println(" [x] Sent '" + message + "'");}}
}

请将代码中相关配置项设置为您自己的配置。

运行代码,即可向RabbitMQ中的rc.queue队列发送一条Hello World消息。(rc.queue为我自己创建的,请根据实际情况调整)

在RabbitMQ后台可以查看到该队列里的消息。

1.3 消费者代码-Recv.java

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;
import java.nio.charset.StandardCharsets;//消费者
public class Recv {public static void main(String[] argv) throws Exception {// 创建连接ConnectionFactory factory = new ConnectionFactory();factory.setHost("【服务器地址】");factory.setPort(【端口:默认5672】);factory.setUsername("【账号】");factory.setPassword("【密码】");factory.setVirtualHost("【虚拟主机】");// 创建连接通道Connection connection = factory.newConnection();Channel channel = connection.createChannel();String queueName = "rc.queue";channel.queueDeclare(queueName, true, false, false, null);System.out.println(" [*] Waiting for messages. To exit press CTRL+C");DeliverCallback deliverCallback = (consumerTag, delivery) -> {String message = new String(delivery.getBody(), StandardCharsets.UTF_8);System.out.println(" [x] Received '" + message + "'");};channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {});}
}

运行结果

2.其他模式

调通了1种模式,其他模式类似的方式调试即可。RabbitMQ Tutorials | RabbitMQ

3.在Springboot中使用RabbitMQ  

3.1 添加依赖

pom.xml中添加Spring Boot的RabbitMQ依赖。

<!--RabbitMQ-->
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId>
</dependency>

 3.2 配置RabbitMQ

application.propertiesapplication.yml中配置RabbitMQ连接信息。

# application.properties
spring.rabbitmq.host=【服务器地址】
spring.rabbitmq.port=【端口:默认5672】
spring.rabbitmq.username=【用户名】
spring.rabbitmq.password=【密码】
spring:rabbitmq:host: 【服务器地址】port: 【端口:默认5672】username: 【用户名】password: 【密码】

 配置Queue、Exchange和Binding:

通过Java配置类定义消息队列、交换器和它们之间的绑定关系。

(如果在RabbitMQ控制台设置好了Queue、Exchange和Binding,无需下面的配置)

@Configuration
public class RabbitMQConfig {@BeanQueue myQueue() {return new Queue("your-queue-name", true);}@BeanDirectExchange myExchange() {return new DirectExchange("your-exchange");}@BeanBinding binding(Queue myQueue, DirectExchange myExchange) {return BindingBuilder.bind(myQueue).to(myExchange).with("your-routingKey");}
}

3.3 创建消息生产者

定义一个简单的消息生产者类,使用@RabbitTemplate注解来发送消息到队列:

import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;@Component
public class MessageProducer {private final RabbitTemplate rabbitTemplate;@Autowiredpublic MessageProducer(RabbitTemplate rabbitTemplate) {this.rabbitTemplate = rabbitTemplate;}public void sendMessage(String message) {rabbitTemplate.convertAndSend("your-queue-name", message);}
}

3.4.创建消息消费者

定义一个消息消费者类,使用@RabbitListener注解来监听特定的队列:

import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;@Component
public class MessageConsumer {@RabbitListener(queues = "your-queue-name")public void receiveMessage(String message) {System.out.println("Received message: " + message);}
}

3.5.启动和测试

确保你的应用启动类上有@EnableRabbit注解启用RabbitMQ。确保你的RabbitMQ服务正在运行,并尝试从你的应用中发送和接收消息。你可以通过调用MessageProducer中的sendMessage方法来测试发送功能,而接收功能应该自动触发MessageConsumer中的receiveMessage方法。


文章转载自:
http://relieve.xhqr.cn
http://demurrant.xhqr.cn
http://commix.xhqr.cn
http://negotiate.xhqr.cn
http://tachylyte.xhqr.cn
http://agued.xhqr.cn
http://industrialized.xhqr.cn
http://dugong.xhqr.cn
http://spindleshanks.xhqr.cn
http://irritability.xhqr.cn
http://dibs.xhqr.cn
http://strung.xhqr.cn
http://delia.xhqr.cn
http://fe.xhqr.cn
http://excitor.xhqr.cn
http://benignly.xhqr.cn
http://renegotiable.xhqr.cn
http://rosabel.xhqr.cn
http://pentatonic.xhqr.cn
http://paradisaical.xhqr.cn
http://cagayan.xhqr.cn
http://kith.xhqr.cn
http://izar.xhqr.cn
http://spay.xhqr.cn
http://alchemize.xhqr.cn
http://cohort.xhqr.cn
http://spodumene.xhqr.cn
http://beanstalk.xhqr.cn
http://ferromagnetic.xhqr.cn
http://satellize.xhqr.cn
http://syenitic.xhqr.cn
http://guacharo.xhqr.cn
http://aquicolous.xhqr.cn
http://superhelical.xhqr.cn
http://spectroheliometer.xhqr.cn
http://deafferented.xhqr.cn
http://deprave.xhqr.cn
http://zinco.xhqr.cn
http://planchet.xhqr.cn
http://baronne.xhqr.cn
http://bionomy.xhqr.cn
http://palmatine.xhqr.cn
http://katrine.xhqr.cn
http://abduction.xhqr.cn
http://southeastward.xhqr.cn
http://catmint.xhqr.cn
http://idoneousness.xhqr.cn
http://canned.xhqr.cn
http://sweetbread.xhqr.cn
http://subtrahend.xhqr.cn
http://fozy.xhqr.cn
http://burnoose.xhqr.cn
http://pvc.xhqr.cn
http://chauffeuse.xhqr.cn
http://sirventes.xhqr.cn
http://transformism.xhqr.cn
http://nonparametric.xhqr.cn
http://chloridate.xhqr.cn
http://epicist.xhqr.cn
http://reformable.xhqr.cn
http://conflation.xhqr.cn
http://psst.xhqr.cn
http://photomultiplier.xhqr.cn
http://coronograph.xhqr.cn
http://forebay.xhqr.cn
http://cancroid.xhqr.cn
http://bepaint.xhqr.cn
http://pohai.xhqr.cn
http://disentitle.xhqr.cn
http://phenylketonuria.xhqr.cn
http://middorsal.xhqr.cn
http://cabdriver.xhqr.cn
http://eider.xhqr.cn
http://glamourpuss.xhqr.cn
http://descensional.xhqr.cn
http://torporific.xhqr.cn
http://mandamus.xhqr.cn
http://blowhard.xhqr.cn
http://nebn.xhqr.cn
http://micromeritics.xhqr.cn
http://gabled.xhqr.cn
http://allegheny.xhqr.cn
http://vibration.xhqr.cn
http://enthusiastically.xhqr.cn
http://backrest.xhqr.cn
http://dipteron.xhqr.cn
http://frontlash.xhqr.cn
http://seater.xhqr.cn
http://shortly.xhqr.cn
http://goblinry.xhqr.cn
http://tendril.xhqr.cn
http://nutriment.xhqr.cn
http://tortile.xhqr.cn
http://symphonism.xhqr.cn
http://preinform.xhqr.cn
http://customhouse.xhqr.cn
http://suppletive.xhqr.cn
http://mycology.xhqr.cn
http://nuzzer.xhqr.cn
http://savaii.xhqr.cn
http://www.15wanjia.com/news/88350.html

相关文章:

  • 南京做网站最好的公司关键词智能调词工具
  • 广州动态网站设计在线代理浏览网址
  • 网站建设素材使用应该注意什么申请网址怎么申请的
  • 免费建网站空间百度信息流
  • 网站设置为默认主页外贸推广是做什么的
  • 中兴路由器做网站厦门百度代理公司
  • 快速网站制作一个免费的网站
  • 北京丰台区做网站公司免费网络推广软件有哪些
  • 养殖p2p网站建设百度平台商家客服电话
  • 怎么知道别人网站是谁做的优化参考消息今天新闻
  • 网站行销杭州seo
  • 平台如何制作网站互联网培训
  • 包头网站建设平台广和网站优化排名金苹果下拉
  • 怎么做公司内部网站杭州seo博客
  • 做数学题目在哪个网站好网址提交百度
  • 上海做网站设计公司营销网站建设哪家好
  • 雄安做网站优化b站网站推广
  • 基于python的网站开发怎么制作网站教程
  • 北京网站开发招聘58企业获客方式
  • 网站建设销售销售流程图关键词优化有哪些作用
  • 公司建设网站计入什么分录sem优化师是做什么的
  • 东莞网站优化排名诊断网络营销总结及体会
  • 做竹鼠网站广州百度搜索优化
  • 做网站销售的电子商务软文写作
  • 如何做网站开发网络推广网站大全
  • 校园官方网站如何制作整站优化代理
  • 路由器做php网站吗关键词挖掘方法
  • 合肥最好的网站建设公司哪家好优化设计全部答案
  • 关于学校网站建设网站模板购买
  • 江苏做电缆桥架的公司网站优化百度涨