rabbitMQ.php 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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. 'name' => 'groupBuyQueue',
  85. 'passive' => false,
  86. 'durable' => true,
  87. ],
  88. ],
  89. /**
  90. * 交换和队列之间的关系称为绑定
  91. * 列出绑定: rabbitmqctl list_bindings
  92. */
  93. 'bindings' => [
  94. [
  95. 'queue' => 'customQueue',
  96. 'exchange' => 'customExchange',
  97. 'routing_keys' => ['customRoute'],
  98. ],
  99. [
  100. 'queue' => 'stockQueue',
  101. 'exchange' => 'stockExchange',
  102. 'routing_keys' => ['stockRoute'],
  103. ],
  104. [
  105. 'queue' => 'notifyQueue',
  106. 'exchange' => 'notifyExchange',
  107. 'routing_keys' => ['notifyRoute'],
  108. ],
  109. [
  110. 'queue' => 'ptQueue',
  111. 'exchange' => 'ptExchange',
  112. 'routing_keys' => ['ptRoute'],
  113. ],
  114. [
  115. 'queue' => 'limitBuyQueue',
  116. 'exchange' => 'limitBuyDelayExchange',
  117. 'routing_keys' => ['limitBuyDelayRoute'],
  118. ],
  119. [
  120. 'queue' => 'birthdayGiftQueue',
  121. 'exchange' => 'limitBuyDelayExchange',
  122. 'routing_keys' => ['birthdayGiftDelayRoute'],
  123. ],
  124. [
  125. 'queue' => 'groupBuyQueue',
  126. 'exchange' => 'limitBuyDelayExchange',
  127. 'routing_keys' => ['groupBuyDelayRoute'],
  128. ],
  129. ],
  130. /**
  131. * 生产者
  132. */
  133. 'producers' => [
  134. [
  135. //客户操作生产者
  136. 'name' => 'customProducer',
  137. ],
  138. [
  139. //库存管理生产者
  140. 'name' => 'stockProducer',
  141. ],
  142. [
  143. //通知生产者
  144. 'name' => 'notifyProducer',
  145. ],
  146. [
  147. //跑腿下单生产者
  148. 'name' => 'ptProducer',
  149. ]
  150. ],
  151. /**
  152. * 消费者
  153. */
  154. 'consumers' => [
  155. [
  156. //客户操作消费者
  157. 'name' => 'customConsumer',
  158. 'callbacks' => [
  159. 'customQueue' => '\common\components\rabbitmq\customConsumer',
  160. ]
  161. ],
  162. [
  163. //库存管理消费者
  164. 'name' => 'stockConsumer',
  165. 'callbacks' => [
  166. 'stockQueue' => '\common\components\rabbitmq\stockConsumer',
  167. //'limitBuyQueue' => '\common\components\rabbitmq\cancelLimitBuyConsumer',
  168. 'limitBuyQueue' => '\common\components\rabbitmq\stockConsumer',
  169. 'birthdayGiftQueue' => '\common\components\rabbitmq\stockConsumer', //生日礼物队列
  170. 'groupBuyQueue' => '\common\components\rabbitmq\stockConsumer', //拼团到期队列
  171. ]
  172. ],
  173. [
  174. //通知消费者
  175. 'name' => 'notifyConsumer',
  176. 'callbacks' => [
  177. 'notifyQueue' => '\common\components\rabbitmq\notifyConsumer',
  178. ]
  179. ],
  180. [
  181. //跑腿下单消费者
  182. 'name' => 'ptConsumer',
  183. 'callbacks' => [
  184. 'ptQueue' => '\common\components\rabbitmq\ptConsumer',
  185. ]
  186. ],
  187. // [ // 生日礼物队列不独创自己的消费者
  188. // 'name' => 'birthdayGiftConsumer',
  189. // 'callbacks' => [
  190. // 'birthdayGiftQueue' => '\common\components\rabbitmq\birthdayGiftConsumer',
  191. // ]
  192. // ]
  193. ],
  194. ];
  195. return $rabbitMQ;