Skip to content

Latest commit

 

History

History
76 lines (51 loc) · 1.41 KB

stomp.md

File metadata and controls

76 lines (51 loc) · 1.41 KB

STOMP transport

Installation

$ composer require enqueue/stomp

Create context

<?php
use Enqueue\Stomp\StompConnectionFactory;

$connectionFactory = new StompConnectionFactory([
    'host' => '127.0.0.1',
    'port' => 61613,
    'login' => 'guest',
    'password' => 'guest',
    'vhost' => '/',
]);

$psrContext = $connectionFactory->createContext();

Send message to topic

<?php
/** @var \Enqueue\Stomp\StompContext $psrContext */

$message = $psrContext->createMessage('Hello world!');

$fooTopic = $psrContext->createTopic('foo');

$psrContext->createProducer()->send($fooTopic, $message);

Send message to queue

<?php
/** @var \Enqueue\Stomp\StompContext $psrContext */

$message = $psrContext->createMessage('Hello world!');

$fooQueue = $psrContext->createQueue('foo');

$psrContext->createProducer()->send($fooQueue, $message);

Consume 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