美文网首页
SpringBoot整合中间件RabbitMQ(二)

SpringBoot整合中间件RabbitMQ(二)

作者: Invi | 来源:发表于2019-05-06 09:53 被阅读0次

    exchange.direct

    打开:http://localhost:15672/#/exchanges

    1.新增Exchanges:

    Name Type Features Message rate in Message rate out +/-
    (AMQP default) direct D
    amq.direct direct D
    amq.fanout fanout D
    amq.headers headers D
    amq.match headers D
    amq.rabbitmq.trace topic D I
    amq.topic topic D
    exchange.direct direct D
    exchanges.fanout fanout D
    exchanges.topic topic D

    Durability:durable 持久化的

    2.新增Queues:

    Overview Messages Message rates +/-
    Name Features State Ready Unacked Total incoming deliver / get ack
    unionpaysmart D idle 0 0 0
    unionpaysmart.news D idle 0 0 0
    invi D idle 0 0 0
    invi.emps D idle 0 0 0
    invi.idea D idle 0 0 0
    invi.news D idle 0 0 0

    3.将exchange和Queues绑定。

    Exchange: exchange.direct
    To Routing key Arguments
    unionpaysmart unionpaysmart
    unionpaysmart.news unionpaysmart.news
    invi invi
    invi.emps invi.emps
    invi.idea invi.idea
    invi.news invi.news
    Exchange: exchanges.fanout
    To Routing key Arguments
    unionpaysmart unionpaysmart
    unionpaysmart.news unionpaysmart.news
    invi invi
    invi.emps invi.emps
    invi.idea invi.idea
    invi.news invi.news

    Exchange: exchanges.topic

    To Routing key Arguments
    unionpaysmart.news *.news
    invi invi.#
    invi.emps invi.#
    invi.idea invi.#
    invi.news *.news
    invi.news invi.#

    ”#“ 匹配 0 或者多个单词

    ”*“ 匹配 1个单词

    4.发送/接收消息

    exchange.direct 点对点
    • Publish message(发布消息):

      Routing key:invi

      Payload:direct.exchange.msg.helloword

      direct 完全匹配路由键的 所以只有 invi 能收到消息。

    • 刷新,查看队列结果:

      Overview Messages Message rates +/-
      Name Features State Ready Unacked Total incoming deliver / get ack
      unionpaysmart D idle 0 0 0
      unionpaysmart.news D idle 0 0 0
      invi D idle 1 0 1 0.00/s
      invi.emps D idle 0 0 0
      invi.idea D idle 0 0 0
      invi.news D idle 0 0 0
    • 查看队列消息:

      The server reported 0 messages remaining.

      Exchange exchange.direct
      Routing Key invi
      Redelivered
      Properties delivery_mode:1headers:
      Payload29 bytesEncoding: string direct.exchange.msg.helloword
    exchanges.fanout 点对所有
    • Publish message(发布消息):

      Routing key:invi.news

      Payload:fanout.exchanges.msg.hahahahahaha

    • 刷新,查看队列结果:

      Overview Messages Message rates +/-
      Name Features State Ready Unacked Total incoming deliver / get ack
      unionpaysmart D idle 1 0 1 0.00/s
      unionpaysmart.news D idle 1 0 1 0.00/s
      invi D idle 2 0 2 0.00/s 0.00/s 0.00/s
      invi.emps D idle 1 0 1 0.00/s
      invi.idea D idle 1 0 1 0.00/s
      invi.news D idle 1 0 1 0.00/s

      所有的队列收到消息+1。

    • 查看队列消息:

      The server reported 0 messages remaining.

      Exchange exchanges.fanout
      Routing Key invi.news
      Redelivered
      Properties delivery_mode:1headers:
      Payload33 bytesEncoding: string fanout.exchanges.msg.hahahahahaha
    Exchange: exchanges.topic 按照指定格式匹配
    • 示例1.Publish message(发布消息):

      Routing key:invi.news

      Payload:topic.exchanges.msg.哈哈哈哈哈哈

      符合:invi.#

      又符合:*.news

      除了:unionpaysmart 应该都能收到消息。

    • 查看队列消息:

      Overview Messages Message rates +/-
      Name Features State Ready Unacked Total incoming deliver / get ack
      unionpaysmart D idle 1 0 1 0.00/s
      unionpaysmart.news D idle 2 0 2 0.00/s
      invi D idle 3 0 3 0.00/s 0.00/s 0.00/s
      invi.emps D idle 2 0 2 0.00/s
      invi.idea D idle 2 0 2 0.00/s 0.00/s 0.00/s
      invi.news D idle 2 0 2 0.00/s

      发现 invi 开头 news后缀的队列都加了1.

    • 示例2.Publish message(发布消息):

      Routing key: hello.news

      Payload:topic.exchanges.msg.嘿嘿嘿嘿

      只符合:*.news

      只有 news后缀的能收到消息

    • 查看队列消息:

      Overview Messages Message rates +/-
      Name Features State Ready Unacked Total incoming deliver / get ack
      unionpaysmart D idle 1 0 1 0.00/s 0.00/s 0.00/s
      unionpaysmart.news D idle 3 0 3 0.00/s
      invi D idle 3 0 3 0.00/s 0.00/s 0.00/s
      invi.emps D idle 2 0 2 0.00/s
      invi.idea D idle 2 0 2 0.00/s 0.00/s 0.00/s
      invi.news D idle 3 0 3 0.00/s 0.00/s 0.00/s

      只有 news后缀的队列+1.

    查看并删除消息:

    Queues

    Get messages

    Ack Mode:Ack messages requeues false

    相关文章

      网友评论

          本文标题:SpringBoot整合中间件RabbitMQ(二)

          本文链接:https://www.haomeiwen.com/subject/wbgloqtx.html