How to read message from Topic in ActiveMQ + PHP + Stomp?

1.2k views Asked by At

I have to read messages from Topic in ActiveMQ + PHP(Stomp), for that I did below code,

try {
    $stomp = new Stomp('tcp://localhost:61613');
} catch (StompException $e) {
    die('Connection failed: ' . $e->getMessage());
}

$topic='/topic/mytopic';
$stomp->subscribe($topic);
$frame = $stomp->readFrame();
var_dump($frame);

But when I got result in var_dump($frame) as bool(false). Instead of that in my topic there is some message. which I could not get it.

Can anybody suggest me solution?

2

There are 2 answers

0
akinzhou On

the publisher is down?you only can receive the message when the topic message publish.

you can test at this step: 1、run publisher command 2、run the comsumer command(the first run publisher no quit)

1
Mahesh J On

I got the solutions.

for topic please refer https://github.com/dejanb/stomp-php Here you need to install library through composer. $ php composer.phar install More detail refer link.

Thank you,