rabbitMQ.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. <?php
  2. /**
  3. * rabbitmq的配置
  4. */
  5. $rabbitMQ = [
  6. 'class' => 'mikemadisonweb\rabbitmq\Configuration',
  7. 'connections' => [
  8. [
  9. 'host' => '127.0.0.1',
  10. 'port' => '5672',
  11. 'user' => 'admin',
  12. 'password' => 'Kn3oaz138w52kzmm9',
  13. 'vhost' => '/', //虚拟主机
  14. ]
  15. ],
  16. /**
  17. * 交换器
  18. */
  19. 'exchanges' => [
  20. [
  21. 'name' => 'customExchange',
  22. 'type' => 'direct',
  23. 'durable' => true,
  24. ],
  25. [
  26. 'name' => 'stockExchange',
  27. 'type' => 'direct',
  28. 'durable' => true,
  29. ],
  30. [
  31. 'name' => 'notifyExchange',
  32. 'type' => 'direct',
  33. 'durable' => true,
  34. ]
  35. ],
  36. /**
  37. * 队列
  38. */
  39. 'queues' => [
  40. [
  41. 'name' => 'customQueue',
  42. 'passive' => false,
  43. 'durable' => true,
  44. ],
  45. [
  46. 'name' => 'stockQueue',
  47. 'passive' => false,
  48. 'durable' => true,
  49. ],
  50. [
  51. 'name' => 'notifyQueue',
  52. 'passive' => false,
  53. 'durable' => true,
  54. ],
  55. ],
  56. /**
  57. * 交换和队列之间的关系称为绑定
  58. * 列出绑定: rabbitmqctl list_bindings
  59. */
  60. 'bindings' => [
  61. [
  62. 'queue' => 'customQueue',
  63. 'exchange' => 'customExchange',
  64. 'routing_keys' => ['customRoute'],
  65. ],
  66. [
  67. 'queue' => 'stockQueue',
  68. 'exchange' => 'stockExchange',
  69. 'routing_keys' => ['stockRoute'],
  70. ],
  71. [
  72. 'queue' => 'notifyQueue',
  73. 'exchange' => 'notifyExchange',
  74. 'routing_keys' => ['notifyRoute'],
  75. ]
  76. ],
  77. /**
  78. * 生产者
  79. */
  80. 'producers' => [
  81. [
  82. //客户操作生产者
  83. 'name' => 'customProducer',
  84. ],
  85. [
  86. //库存管理生产者
  87. 'name' => 'stockProducer',
  88. ],
  89. [
  90. //通知生产者
  91. 'name' => 'notifyProducer',
  92. ]
  93. ],
  94. /**
  95. * 消费者
  96. */
  97. 'consumers' => [
  98. [
  99. //客户操作消费者
  100. 'name' => 'customConsumer',
  101. 'callbacks' => [
  102. 'customQueue' => '\common\components\rabbitmq\customConsumer',
  103. ]
  104. ],
  105. [
  106. //库存管理消费者
  107. 'name' => 'stockConsumer',
  108. 'callbacks' => [
  109. 'stockQueue' => '\common\components\rabbitmq\stockConsumer',
  110. ]
  111. ],
  112. [
  113. //通知消费者
  114. 'name' => 'notifyConsumer',
  115. 'callbacks' => [
  116. 'notifyQueue' => '\common\components\rabbitmq\notifyConsumer',
  117. ]
  118. ]
  119. ],
  120. ];
  121. return $rabbitMQ;