rabbitMQ.php 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188
  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. 'name' => 'ptExchange',
  37. 'type' => 'direct',
  38. 'durable' => true,
  39. ],
  40. [
  41. 'name' => 'limitBuyDelayExchange',
  42. 'type' => 'x-delayed-message',
  43. 'durable' => true,
  44. 'arguments' => new \PhpAmqpLib\Wire\AMQPTable([
  45. 'x-delayed-type' => 'direct',
  46. ]),
  47. ]
  48. ],
  49. /**
  50. * 队列
  51. */
  52. 'queues' => [
  53. [
  54. 'name' => 'customQueue',
  55. 'passive' => false,
  56. 'durable' => true,
  57. ],
  58. [
  59. 'name' => 'stockQueue',
  60. 'passive' => false,
  61. 'durable' => true,
  62. ],
  63. [
  64. 'name' => 'notifyQueue',
  65. 'passive' => false,
  66. 'durable' => true,
  67. ],
  68. [
  69. 'name' => 'ptQueue',
  70. 'passive' => false,
  71. 'durable' => true,
  72. ],
  73. [
  74. 'name' => 'limitBuyQueue',
  75. 'passive' => false,
  76. 'durable' => true,
  77. ],
  78. [
  79. 'name' => 'birthdayGiftQueue',
  80. 'passive' => false,
  81. 'durable' => true,
  82. ],
  83. ],
  84. /**
  85. * 交换和队列之间的关系称为绑定
  86. * 列出绑定: rabbitmqctl list_bindings
  87. */
  88. 'bindings' => [
  89. [
  90. 'queue' => 'customQueue',
  91. 'exchange' => 'customExchange',
  92. 'routing_keys' => ['customRoute'],
  93. ],
  94. [
  95. 'queue' => 'stockQueue',
  96. 'exchange' => 'stockExchange',
  97. 'routing_keys' => ['stockRoute'],
  98. ],
  99. [
  100. 'queue' => 'notifyQueue',
  101. 'exchange' => 'notifyExchange',
  102. 'routing_keys' => ['notifyRoute'],
  103. ],
  104. [
  105. 'queue' => 'ptQueue',
  106. 'exchange' => 'ptExchange',
  107. 'routing_keys' => ['ptRoute'],
  108. ],
  109. [
  110. 'queue' => 'limitBuyQueue',
  111. 'exchange' => 'limitBuyDelayExchange',
  112. 'routing_keys' => ['limitBuyDelayRoute'],
  113. ],
  114. [
  115. 'queue' => 'birthdayGiftQueue',
  116. 'exchange' => 'limitBuyDelayExchange',
  117. 'routing_keys' => ['birthdayGiftDelayRoute'],
  118. ]
  119. ],
  120. /**
  121. * 生产者
  122. */
  123. 'producers' => [
  124. [
  125. //客户操作生产者
  126. 'name' => 'customProducer',
  127. ],
  128. [
  129. //库存管理生产者
  130. 'name' => 'stockProducer',
  131. ],
  132. [
  133. //通知生产者
  134. 'name' => 'notifyProducer',
  135. ],
  136. [
  137. //跑腿下单生产者
  138. 'name' => 'ptProducer',
  139. ]
  140. ],
  141. /**
  142. * 消费者
  143. */
  144. 'consumers' => [
  145. [
  146. //客户操作消费者
  147. 'name' => 'customConsumer',
  148. 'callbacks' => [
  149. 'customQueue' => '\common\components\rabbitmq\customConsumer',
  150. ]
  151. ],
  152. [
  153. //库存管理消费者
  154. 'name' => 'stockConsumer',
  155. 'callbacks' => [
  156. 'stockQueue' => '\common\components\rabbitmq\stockConsumer',
  157. //'limitBuyQueue' => '\common\components\rabbitmq\cancelLimitBuyConsumer',
  158. 'limitBuyQueue' => '\common\components\rabbitmq\stockConsumer',
  159. 'birthdayGiftQueue' => '\common\components\rabbitmq\stockConsumer', //生日礼物队列
  160. ]
  161. ],
  162. [
  163. //通知消费者
  164. 'name' => 'notifyConsumer',
  165. 'callbacks' => [
  166. 'notifyQueue' => '\common\components\rabbitmq\notifyConsumer',
  167. ]
  168. ],
  169. [
  170. //跑腿下单消费者
  171. 'name' => 'ptConsumer',
  172. 'callbacks' => [
  173. 'ptQueue' => '\common\components\rabbitmq\ptConsumer',
  174. ]
  175. ],
  176. // [ // 生日礼物队列不独创自己的消费者
  177. // 'name' => 'birthdayGiftConsumer',
  178. // 'callbacks' => [
  179. // 'birthdayGiftQueue' => '\common\components\rabbitmq\birthdayGiftConsumer',
  180. // ]
  181. // ]
  182. ],
  183. ];
  184. return $rabbitMQ;