Skip to content

Commit 23c7c4f

Browse files
committed
[docs] add basic docs for beanstalk
1 parent a00d619 commit 23c7c4f

3 files changed

Lines changed: 86 additions & 1 deletion

File tree

‎README.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ Features:
99

1010
* [Feature rich](docs/quick_tour.md).
1111
* [JMS](https://docs.oracle.com/javaee/7/api/javax/jms/package-summary.html) like transport [abstraction](https://github.com/php-enqueue/psr-queue).
12-
* Supports transports [AMQP (RabbitMQ, ActiveMQ)](docs/transport/amqp.md), [STOMP](docs/transport/stomp.md), [Amazon SQS](docs/transport/sqs.md), [Redis](docs/transport/redis.md), [Doctrine DBAL](docs/transport/dbal.md), [Filesystem](docs/transport/filesystem.md), [Null](docs/transport/null.md).
12+
* Supports transports [AMQP (RabbitMQ, ActiveMQ)](docs/transport/amqp.md), [Beanstalk (Pheanstalk)](docs/transport/pheanstalk.md) [STOMP](docs/transport/stomp.md), [Amazon SQS](docs/transport/sqs.md), [Redis](docs/transport/redis.md), [Doctrine DBAL](docs/transport/dbal.md), [Filesystem](docs/transport/filesystem.md), [Null](docs/transport/null.md).
1313
* [Symfony bundle](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/bundle/quick_tour.md)
1414
* [Magento1 extension](https://github.com/php-enqueue/enqueue-dev/blob/master/docs/magento/quick_tour.md)
1515
* [Message bus](http://www.enterpriseintegrationpatterns.com/patterns/messaging/MessageBus.html) support.

‎docs/index.md‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
* Transports
55
- [Amqp (RabbitMQ, ActiveMQ)](transport/amqp.md)
66
- [Amazon SQS](transport/sqs.md)
7+
- [Beanstalk (Pheanstalk)](transport/pheanstalk.md)
78
- [Stomp](transport/stomp.md)
89
- [Redis](transport/redis.md)
910
- [Doctrine DBAL](transport/dbal.md)

‎docs/transport/pheanstalk.md‎

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
# Beanstalk (Pheanstalk) transport
2+
3+
The transport uses [Beanstalkd](http://kr.github.io/beanstalkd/) job manager.
4+
The transport uses [Pheanstalk](https://github.com/pda/pheanstalk) library internally.
5+
6+
* [Installation](#installation)
7+
* [Create context](#create-context)
8+
* [Send message to topic](#send-message-to-topic)
9+
* [Send message to queue](#send-message-to-queue)
10+
* [Consume message](#consume-message)
11+
12+
## Installation
13+
14+
```bash
15+
$ composer require enqueue/pheanstalk
16+
```
17+
18+
19+
## Create context
20+
21+
```php
22+
<?php
23+
use Enqueue\Pheanstalk\PheanstalkConnectionFactory;
24+
25+
// connects to localhost:11300
26+
$factory = new PheanstalkConnectionFactory();
27+
28+
// same as above
29+
$factory = new PheanstalkConnectionFactory('beanstalk://');
30+
31+
// connects to example host and port 5555
32+
$factory = new PheanstalkConnectionFactory('beanstalk://example:5555');
33+
34+
// same as above but configured by array
35+
$factory = new PheanstalkConnectionFactory([
36+
'host' => 'example',
37+
'port' => 5555
38+
]);
39+
```
40+
41+
## Send message to topic
42+
43+
```php
44+
<?php
45+
/** @var \Enqueue\Pheanstalk\PheanstalkContext $psrContext */
46+
47+
$fooTopic = $psrContext->createTopic('aTopic');
48+
$message = $psrContext->createMessage('Hello world!');
49+
50+
$psrContext->createProducer()->send($fooTopic, $message);
51+
```
52+
53+
## Send message to queue
54+
55+
```php
56+
<?php
57+
/** @var \Enqueue\Pheanstalk\PheanstalkContext $psrContext */
58+
59+
$fooQueue = $psrContext->createQueue('aQueue');
60+
$message = $psrContext->createMessage('Hello world!');
61+
62+
$psrContext->createProducer()->send($fooQueue, $message);
63+
```
64+
65+
## Consume message:
66+
67+
```php
68+
<?php
69+
/** @var \Enqueue\Pheanstalk\PheanstalkContext $psrContext */
70+
71+
$fooQueue = $psrContext->createQueue('aQueue');
72+
$consumer = $psrContext->createConsumer($fooQueue);
73+
74+
$message = $consumer->receive(2000); // wait for 2 seconds
75+
76+
$message = $consumer->receiveNoWait(); // fetch message or return null immediately
77+
78+
// process a message
79+
80+
$consumer->acknowledge($message);
81+
// $consumer->reject($message);
82+
```
83+
84+
[back to index](../index.md)

0 commit comments

Comments
 (0)