Synchronous AMQP from PHP

蓝咒 提交于 2019-12-23 11:57:45

问题


Can PHP treat AMQP like an RPC service, and send a message and block until a reply is returned? Are there any good examples of this, and do any libraries wrap such functionality up in an easy-to-use way?

I'd like to have the flexibility of a brokered messaging system, but shield the web tier from needing to know about its asynchronous nature.


回答1:


Sure, absolutely. Look at how an RPC-style request flows around a system:

  1. A request is issued
  2. The requester now blocks waiting for a reply to that request

That's completely implementable with an asynchronous message system like AMQP. You just need to do the RPC correlation yourself:

  1. Send your request within an asynchronous message with a unique ID within it (this does not block)
  2. Receive messages from the messaging system and block until you get a message back with the same unique ID (that means you've just received your reply)

RabbitMQ, an AMQP broker, offers documentation online on how to do exactly this.



来源:https://stackoverflow.com/questions/9381909/synchronous-amqp-from-php

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!