$ composer require enqueue/stomp
<?php
use Enqueue\Stomp\StompConnectionFactory;
// connects to localhost
$factory = new StompConnectionFactory();
// same as above
$factory = new StompConnectionFactory('stomp:');
// same as above
$factory = new StompConnectionFactory([]);
// connect to stomp broker at example.com port 1000 using
$factory = new StompConnectionFactory([
'host' => 'example.com',
'port' => 1000,
'login' => 'theLogin',
]);
// same as above but given as DSN string
$factory = new StompConnectionFactory('stomp://example.com:1000?login=theLogin');
$psrContext = $factory->createContext();
// if you have enqueue/enqueue library installed you can use a function from there to create the context
$psrContext = \Enqueue\dsn_to_context('stomp:');
<?php
/** @var \Enqueue\Stomp\StompContext $psrContext */
$message = $psrContext->createMessage('Hello world!');
$fooTopic = $psrContext->createTopic('foo');
$psrContext->createProducer()->send($fooTopic, $message);
<?php
/** @var \Enqueue\Stomp\StompContext $psrContext */
$message = $psrContext->createMessage('Hello world!');
$fooQueue = $psrContext->createQueue('foo');
$psrContext->createProducer()->send($fooQueue, $message);
<?php
/** @var \Enqueue\Stomp\StompContext $psrContext */
$fooQueue = $psrContext->createQueue('foo');
$consumer = $psrContext->createConsumer($fooQueue);
$message = $consumer->receive();
// process a message
$consumer->acknowledge($message);
// $consumer->reject($message);
back to index