简体   繁体   English

PHP理论中的Stomp / ActiveMQ-如何模拟Java的MDB?

[英]Stomp / ActiveMQ in PHP theory - how to emulate Java's MDBs?

How does one go about creating an equivalent of a Message-Driven Bean in PHP? 如何在PHP中创建等效于消息驱动的Bean?

So, I understand that it is possible to send() messages to ActiveMQ via Stomp protocol, and also that it is possible to connect() to ActiveMQ and then to readFrame() when there is a message available in the queue in ActiveMQ. 因此,我知道可以通过Stomp协议向ActiveMQ发送()消息,并且在ActiveMQ队列中有可用消息时,可以将()连接到ActiveMQ,然后再读取到readFrame()。

What I don't understand is how does one solve the problem of asynchronous processing of received messages from the queue. 我不了解的是如何解决从队列接收的消息的异步处理问题。

If you have one thread that is constantly waiting on the queue (and blocking) until something is in it, does that mean that you can only process one message at a time in PHP? 如果您有一个线程一直在队列中等待(并阻塞)直到有线程进入,这是否意味着您一次只能在PHP中处理一条消息?

In Java EE MDBs you don't worry about threads, since the app server instantiates MDBs when they are needed, but I don't understand how to create a high-throughput application in PHP which listens on an ActiveMQ Queue. 在Java EE MDB中,您不必担心线程,因为应用服务器会在需要时实例化MDB,但是我不了解如何在PHP中创建一个侦听ActiveMQ队列的高吞吐量应用程序。

Any ideas? 有任何想法吗?

It's not really clear in which sense you refer to PHP, PHP as in the language or PHP as in runtime used with a web server? 目前还不清楚您在哪种意义上是指PHP,Web所用语言中的PHP或Web服务器中使用的运行时中的PHP?

However, I would create a separate php script and start it separately from any script invoked from a web application. 但是,我将创建一个单独的php脚本,并将其与从Web应用程序调用的任何脚本分开启动。 Such as when the server boots up and has a loop that reads STOMP messages, just like you describe. 例如,当服务器启动并具有读取STOMP消息的循环时,就像您描述的那样。

How would you get it to communicate with the web application then? 然后,您将如何使其与Web应用程序通信? Simply process and store the content of the messages somehow in the web application database. 简单地以某种方式处理消息的内容并将其存储在Web应用程序数据库中。 This is essentially how JavaEE MDBs work as well, but there is a container to handle starting of MDB threads, as you have notice. 从本质上讲,这也是JavaEE MDB的工作方式,但是,您已经注意到,有一个容器来处理MDB线程的启动。

About threading: you could fork processes in PHP, although threading is not really an option. 关于线程:尽管并不是真正的选择,但您可以在PHP中派生进程。 look at this example: http://us.php.net/pcntl_fork 看这个例子: http : //us.php.net/pcntl_fork

// fork a php script into two processes. Then make each process
if (pcntl_fork() == -1) {
 die('Forking failed');
} 
// This is run twice in different processes, one main process and one child.
run_message_listener_loop(); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM