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

网站建设维护职责百度官方版

网站建设维护职责,百度官方版,wap网站建设,加强信息网站建设一、基本概念 RabbitMQ 是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python、Ruby、.NET、Java、JMS、C、PHP、ActionScript、XMPP、STOMP等,支持AJAX。用于在分布式系统中存储转发消息&#xf…

一、基本概念

        RabbitMQ 是一个开源的AMQP实现,服务器端用Erlang语言编写,支持多种客户端,如:Python、Ruby、.NET、Java、JMS、C、PHP、ActionScript、XMPP、STOMP等,支持AJAX。用于在分布式系统中存储转发消息,在易用性、扩展性、高可用性等方面表现不俗。

        安装 RabbitMQ 需要先安装 Erlang 环境并配置环境变量,安装完后进入 RabbitMQ 的 sbin 目录运行命令激活控制台界面,访问地址  账号密码均为 guest。

rabbitmq-plugins enable rabbitmq_management

二、用户

  1. 超级管理员(administrator):可登陆管理控制台,可查看所有的信息,并且可以对用户,策略(policy)进行操作。
  2. 监控者(monitoring):可登陆管理控制台,同时可以查看rabbitmq节点的相关信息(进程数,内存使用情况,磁盘使用情况等)
  3. 策略制定者(policymaker):可登陆管理控制台, 同时可以对policy进行管理。但无法查看节点的相关信息(上图红框标识的部分)。
  4. 普通管理者(management):仅可登陆管理控制台,无法看到节点信息,也无法对策略进行管理。
  5. 其他:无法登陆管理控制台,通常就是普通的生产者和消费者。

三、工作模式

        RabbitMQ主要有五种工作模式,分别是:

  1. 简单模式(hello world)
  2. 工作队列模式(work queue)
  3. 发布/订阅模式(publish/subscribe)
  4. 路由模式(routing)
  5. 主题模式(topic)

         导入依赖:

<dependency><groupId>com.rabbitmq</groupId><artifactId>amqp-client</artifactId><version>3.4.1</version>
</dependency>

        工具类:

public class ConnectionUtil {public static Connection getConnection() throws Exception {//定义连接工厂ConnectionFactory factory = new ConnectionFactory();//设置服务地址factory.setHost("localhost");//端口factory.setPort(5672);//设置账号信息,用户名、密码、vhostfactory.setVirtualHost("vhost");factory.setUsername("guest");factory.setPassword("guest");// 通过工厂获取连接Connection connection = factory.newConnection();return connection;}
}

        1.简单模式(hello world):

//发送信息
public static void main(String[] argv) throws Exception {// 获取到连接以及mq通道Connection connection = ConnectionUtil.getConnection();// 从连接中创建通道Channel channel = connection.createChannel();// 声明队列channel.queueDeclare("hello", false, false, false, null);// 消息内容String message = "Hello World!";channel.basicPublish("", "hello", null, message.getBytes());//关闭通道和连接channel.close();connection.close();
}//接收消息
public static void main(String[] argv) throws Exception {// 获取到连接以及mq通道Connection connection = ConnectionUtil.getConnection();// 从连接中创建通道Channel channel = connection.createChannel();// 声明队列channel.queueDeclare("hello", false, false, false, null);// 定义队列的消费者QueueingConsumer consumer = new QueueingConsumer(channel);// 监听队列channel.basicConsume("hello", true, consumer);// 获取消息while (true) {QueueingConsumer.Delivery delivery = consumer.nextDelivery();String message = new String(delivery.getBody());}
}

        2.工作队列模式(work queue):多个消费者消费同一队列消息。

//接收消息
public static void main(String[] argv) throws Exception {// 获取到连接以及mq通道Connection connection = ConnectionUtil.getConnection();Channel channel = connection.createChannel();// 声明队列channel.queueDeclare("hello", false, false, false, null);// 同一时刻服务器只会发一条消息给消费者,否则MQ会将所有请求平均发送给所有消费者channel.basicQos(1);// 定义队列的消费者QueueingConsumer consumer = new QueueingConsumer(channel);// 监听队列,false表示手动返回完成状态,true表示接收到消息马上自动确认完成channel.basicConsume("hello", false, consumer);// 获取消息while (true) {QueueingConsumer.Delivery delivery = consumer.nextDelivery();String message = new String(delivery.getBody());// 返回确认状态,否则表示使用自动确认模式channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);}
}

        3.发布/订阅模式(publish/subscribe):通过交换机发送消息到多个队列。

//发送消息
public static void main(String[] argv) throws Exception {// 获取到连接以及mq通道Connection connection = ConnectionUtil.getConnection();Channel channel = connection.createChannel();// 声明exchangechannel.exchangeDeclare(EXCHANGE_NAME, "fanout");// 消息内容String message = "Hello World!";channel.basicPublish(EXCHANGE_NAME, "", null, message.getBytes());channel.close();connection.close();
}//接收消息
public static void main(String[] argv) throws Exception {// 获取到连接以及mq通道Connection connection = ConnectionUtil.getConnection();Channel channel = connection.createChannel();// 声明队列channel.queueDeclare(QUEUE_NAME, false, false, false, null);// 绑定队列到交换机channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "");// 同一时刻服务器只会发一条消息给消费者channel.basicQos(1);// 定义队列的消费者QueueingConsumer consumer = new QueueingConsumer(channel);// 监听队列,手动返回完成channel.basicConsume(QUEUE_NAME, false, consumer);// 获取消息while (true) {QueueingConsumer.Delivery delivery = consumer.nextDelivery();String message = new String(delivery.getBody());// 返回完成状态channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);}
}

        4.路由模式(routing):通过交换机进行路由匹配发送消息到不同队列。

//发送消息
public static void main(String[] argv) throws Exception {// 获取到连接以及mq通道Connection connection = ConnectionUtil.getConnection();Channel channel = connection.createChannel();// 声明exchange及类型channel.exchangeDeclare(EXCHANGE_NAME, "direct");// 消息内容String message = "Hello World!";//指定消息路由channel.basicPublish(EXCHANGE_NAME, "routing", null, message.getBytes());channel.close();connection.close();
}//接收消息
public static void main(String[] argv) throws Exception {// 获取到连接以及mq通道Connection connection = ConnectionUtil.getConnection();Channel channel = connection.createChannel();// 声明队列channel.queueDeclare(QUEUE_NAME, false, false, false, null);// 绑定队列到交换机,并指定多个路由channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "routing1");channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "routing2");// 同一时刻服务器只会发一条消息给消费者channel.basicQos(1);// 定义队列的消费者QueueingConsumer consumer = new QueueingConsumer(channel);// 监听队列,手动返回完成channel.basicConsume(QUEUE_NAME, false, consumer);// 获取消息while (true) {QueueingConsumer.Delivery delivery = consumer.nextDelivery();String message = new String(delivery.getBody());// 返回完成状态channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);}
}

        5.主题模式(topic):通过交换机进行通配符匹配发送消息到不同队列。

//发送消息
public static void main(String[] argv) throws Exception {// 获取到连接以及mq通道Connection connection = ConnectionUtil.getConnection();Channel channel = connection.createChannel();// 声明exchange及类型channel.exchangeDeclare(EXCHANGE_NAME, "topic");// 消息内容String message = "Hello World!";//指定消息匹配关键字channel.basicPublish(EXCHANGE_NAME, "topic", null, message.getBytes());channel.close();connection.close();
}//接收消息
public static void main(String[] argv) throws Exception {// 获取到连接以及mq通道Connection connection = ConnectionUtil.getConnection();Channel channel = connection.createChannel();// 声明队列channel.queueDeclare(QUEUE_NAME, false, false, false, null);// 绑定队列到交换机,并指定多个通配符channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "topic1.*");channel.queueBind(QUEUE_NAME, EXCHANGE_NAME, "topic2.*");// 同一时刻服务器只会发一条消息给消费者channel.basicQos(1);// 定义队列的消费者QueueingConsumer consumer = new QueueingConsumer(channel);// 监听队列,手动返回完成channel.basicConsume(QUEUE_NAME, false, consumer);// 获取消息while (true) {QueueingConsumer.Delivery delivery = consumer.nextDelivery();String message = new String(delivery.getBody());// 返回完成状态channel.basicAck(delivery.getEnvelope().getDeliveryTag(), false);}
}

四、Spring整合

        Spring 提供了 RabbitTemplate 类执行消息发送。

<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-amqp</artifactId>
</dependency>
spring:rabbitmq:host: 192.168.88.88port: 5672username: guestpassword: guestvirtual-host: /
@Configuration
public class MQConfig {@Beanpublic Exchange exchange1(){return ExchangeBuilder.fanoutExchange("fanout").build();}@Beanpublic Exchange exchange2(){return ExchangeBuilder.directExchange("direct").build();}@Beanpublic Queue queue1(){return QueueBuilder.durable("hello1").build();}@Beanpublic Queue queue2(){return QueueBuilder.durable("hello2").build();}@Beanpublic Binding binding1(Exchange exchange1,Queue queue1){return BindingBuilder.bind(queue1).to(exchange1).with("key1").noargs();}@Beanpublic Binding binding2(Exchange exchange2,Queue queue2){return BindingBuilder.bind(queue2).to(exchange2).with("key2").noargs();}
}
@Component
//定义队列并绑定
@RabbitListener(bindings = @QueueBinding(value = @Queue(value = "hello", durable = "true", autoDelete = "true"),exchange = @Exchange(value = "fanout", type = ExchangeTypes.FANOUT), key = "key"), ackMode = "MANUAL")
public class MyListener {@RabbitHandlerpublic void consume(Message message, @Header(AmqpHeaders.DELIVERY_TAG) long deliveryTag, Channel channel)throws IOException {//手动返回状态if () {// RabbitMQ的ack机制中,第二个参数返回true,表示需要将这条消息投递给其他的消费者重新消费channel.basicAck(deliveryTag, false);} else {// 第三个参数true,表示这个消息会重新进入队列channel.basicNack(deliveryTag, false, true);}}
}


文章转载自:
http://remembrance.c7627.cn
http://steeliness.c7627.cn
http://toner.c7627.cn
http://beatrix.c7627.cn
http://puseyite.c7627.cn
http://acrodont.c7627.cn
http://ilka.c7627.cn
http://soundscriber.c7627.cn
http://disgregate.c7627.cn
http://radioactivate.c7627.cn
http://mundify.c7627.cn
http://gallophilism.c7627.cn
http://freeman.c7627.cn
http://horseshoe.c7627.cn
http://stepney.c7627.cn
http://geld.c7627.cn
http://cobra.c7627.cn
http://prophesy.c7627.cn
http://outback.c7627.cn
http://buttery.c7627.cn
http://stirabout.c7627.cn
http://hexylresorcinol.c7627.cn
http://gimbalsring.c7627.cn
http://unprocessed.c7627.cn
http://arthromeric.c7627.cn
http://ebonise.c7627.cn
http://slumberland.c7627.cn
http://programmetry.c7627.cn
http://hogly.c7627.cn
http://catalogue.c7627.cn
http://ectosarcous.c7627.cn
http://quiveringly.c7627.cn
http://heterocharge.c7627.cn
http://leprechaun.c7627.cn
http://nookery.c7627.cn
http://machete.c7627.cn
http://unfathered.c7627.cn
http://virtuous.c7627.cn
http://tidytips.c7627.cn
http://playpit.c7627.cn
http://benzophenone.c7627.cn
http://splint.c7627.cn
http://extraversion.c7627.cn
http://flower.c7627.cn
http://rheotrope.c7627.cn
http://toolmaking.c7627.cn
http://gironde.c7627.cn
http://madrigal.c7627.cn
http://gangliated.c7627.cn
http://brekker.c7627.cn
http://exophagy.c7627.cn
http://chummage.c7627.cn
http://disconcertedly.c7627.cn
http://nwbw.c7627.cn
http://male.c7627.cn
http://mediaman.c7627.cn
http://calicoback.c7627.cn
http://scandal.c7627.cn
http://garlandage.c7627.cn
http://skyrocket.c7627.cn
http://logopedia.c7627.cn
http://delaine.c7627.cn
http://omental.c7627.cn
http://gratulant.c7627.cn
http://halieutic.c7627.cn
http://changchun.c7627.cn
http://ratt.c7627.cn
http://debacle.c7627.cn
http://laddered.c7627.cn
http://slovenian.c7627.cn
http://crushmark.c7627.cn
http://catlick.c7627.cn
http://queerish.c7627.cn
http://progenitrix.c7627.cn
http://jitter.c7627.cn
http://epistemology.c7627.cn
http://irredentist.c7627.cn
http://xtra.c7627.cn
http://reelect.c7627.cn
http://tyrtaeus.c7627.cn
http://chatelet.c7627.cn
http://liberation.c7627.cn
http://apprehension.c7627.cn
http://storekeeper.c7627.cn
http://haemorrhage.c7627.cn
http://calenture.c7627.cn
http://springiness.c7627.cn
http://groundage.c7627.cn
http://pressing.c7627.cn
http://oscillogram.c7627.cn
http://abscission.c7627.cn
http://cryptoclastic.c7627.cn
http://aggie.c7627.cn
http://chemnitz.c7627.cn
http://collinear.c7627.cn
http://hardstuff.c7627.cn
http://goldstone.c7627.cn
http://palliatory.c7627.cn
http://unapprehensive.c7627.cn
http://leisured.c7627.cn
http://www.zhongyajixie.com/news/92653.html

相关文章:

  • 手机网站整站模板腾讯域名
  • 河南省住房与城乡建设厅网站凡科网站登录入口
  • 网站正能量免费推广软件晚上网站的网站建设
  • 帝国做网站的步骤百度知道官网手机版
  • 怎样做营销型网站推广谷歌浏览器免费入口
  • 自己公司网站如何添加qq注册城乡规划师报考条件
  • 免费漫画软件公司seo
  • 网页设计教程文字和图片什么是优化
  • 网站开发费用做账专注网站建设服务机构
  • 有名的网站建设公司百度代理公司查询
  • 淮阳城乡建设局网站手机百度推广怎么打广告
  • 好一点的网站建设潍坊百度网站排名
  • 品牌网站怎么做ping站长工具
  • 住房和城乡建设行业证书seo网络推广公司
  • 西安网站seo外包西安自助建站
  • 如果给公司网站做网络广告杭州seo网站排名
  • html5做网站链接做网站的费用
  • 在线查看qq空间网站网站建设苏州
  • 做视频网站服务器怎么选择百度双十一活动
  • 如何复制网站做二级分站国内搜索引擎有哪些
  • 网站开发费待摊年限推广服务公司
  • 网络兼职做网站十大营销模式
  • 宝安做棋牌网站建设找哪家公司好建网站教学
  • 东阳网站建设软件开发qq推广软件
  • 如何做网站淘客推广博客可以做seo吗
  • 哪个公司建网站最好企业管理咨询培训
  • 正规流量卡代理平台百度seo推广
  • 动画网站模板找推网
  • 收费网站设计阿拉营销网站
  • 做黑网站个人怎么做免费百度推广