zoukankan      html  css  js  c++  java
  • rabbitmq:

    rabbitmq:
    准备:
    · 安装rabbitmq; brew install rabbitmq    
    · php需要引入php-amqplib composer require php-amqplib/php-amqplib
    
    注意:
    · 手动ack
    customer 端 basic_consume no_act 设置为false,
    在callback里面    $msg->delivery_info['channel']->basic_ack($msg->delivery_info['delivery_tag']); 手动ack
    不手动ack则默认mq直接删除消息,容易造成消息丢失。
    但要注意如果忘记ack,则会造成消息重发,或者mq 占大内容
    · 消息持久化(简单,不是百分百保证不丢失)
    productor,customer queue_declare 是durable 设置为true 【队列持久化】
    new mesaage 时 增加参数 delivery_mode => AMQPMessage::DELIVERY_MODE_PERSISTENT 【信息持久化】
    · 非循环投递
    默认多customer,循环投递(比如 2个customer,则一个odd,一个even)
    customer 端 basic_consume 之前调用 $channel->basic_qos( null, 1, null );可设置mq给每个customer 1个任务,当其ack之后,在投递新的任务。不会让customer累的累死,闲的闲死
    · 以上参考url 【http://www.rabbitmq.com/tutorials/tutorial-two-php.html】
    
    · publis/submit [fanout => broadcast]
    订阅模式需要productor ,customer 声明相同的 exchange,exchange 的类型为 fanout;
    productor baisc_publish 执行exchangename 信息;
    customer 需要list( $queue, ,) = $channel->queue_declare("", false, false, true, false );生成唯一随机的队列名称,并且 $channel->queue_bind( $queue, 'log' );绑定到exchange上面。
    如果没有customer ,那么productor的消息会被丢弃。
    · 参考url 【http://www.rabbitmq.com/tutorials/tutorial-three-php.html】
    
    · routing [diret]
    相比于订阅模式,routing模式相当于对数据做了下筛选。
    productor,consumer 声明相同的exchange,exchange type 为 direct
    productor basic_publish 时,routing_key 需要指定
    consumer 需要list( $queue, ,) = $channel->queue_declare("", false, false, true, false );生成唯一随机的队列名称,并且 $channel->queue_bind( $queue, 'log', routing_key );绑定到exchange上面。同时routing_key 为必填。$channel->queue_bind可以执行多次,绑定多个routing_key
    未被consumer匹配到的routing_key的消息,会被丢弃
    多个consumer的routing_key 可以重复。
    · 参考url【http://www.rabbitmq.com/tutorials/tutorial-four-php.html】
    
    · topics [topic]
    routing模式筛选不够灵活,使用topic则可以灵活的进行匹配
    # 代表所有的routing_key; *.xxx *可以匹配任何字符,但后面.xxx则必须相符 ;xxx 则类似于diret
    只用使用.(dot)来进行分割routing_key
    · 参考url 【http://www.rabbitmq.com/tutorials/tutorial-five-php.html】
    
    
  • 相关阅读:
    CSS的display小记
    Oracle PL/SQL中的循环处理(sql for循环)
    Windows下Git服务器搭建及使用过程中的一些问题
    IIS故障问题(Connections_Refused)分析及处理
    [转载]Function.apply and Function.call in JavaScript
    CentOS中文乱码问题的解决方法
    sed之G、H、g、h使用
    Linux命令:chgrp chown chmod
    javascirpt倒计时
    linux:sed高级命令之n、N
  • 原文地址:https://www.cnblogs.com/lxdd/p/10002418.html
Copyright © 2011-2022 走看看