8000 snsqs docs · enumag/enqueue-dev@905c471 · GitHub
[go: up one dir, main page]

Skip to content

Commit 905c471

Browse files
committed
snsqs docs
1 parent 3f043ad commit 905c471

File tree

3 files changed

+185
-0
lines changed

3 files changed

+185
-0
lines changed

bin/subtree-split

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ remote rdkafka git@github.com:php-enqueue/rdkafka.git
5858
remote dbal git@github.com:php-enqueue/dbal.git
5959
remote null git@github.com:php-enqueue/null.git
6060
remote sqs git@github.com:php-enqueue/sqs.git
61+
remote sns git@github.com:php-enqueue/sns.git
62+
remote snsqs git@github.com:php-enqueue/snsqs.git
6163
remote gps git@github.com:php-enqueue/gps.git
6264
remote enqueue-bundle git@github.com:php-enqueue/enqueue-bundle.git
6365
remote job-queue git@github.com:php-enqueue/job-queue.git

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ Enqueue is an MIT-licensed open source project with its ongoing development made
1212
* [Quick tour](quick_tour.md)
1313
* [Transports](#transports)
1414
- Amqp based on [the ext](transport/amqp.md), [bunny](transport/amqp_bunny.md), [the lib](transport/amqp_lib.md)
15+
- [Amazon SNS-SQS](transport/snsqs.md)
1516
- [Amazon SQS](transport/sqs.md)
1617
- [Google PubSub](transport/gps.md)
1718
- [Beanstalk (Pheanstalk)](transport/pheanstalk.md)

docs/transport/snsqs.md

Lines changed: 182 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,182 @@
1+
<h2 align="center">Supporting Enqueue</h2>
2+
3+
Enqueue is an MIT-licensed open source project with its ongoing development made possible entirely by the support of community and our customers. If you'd like to join them, please consider:
4+
5+
- [Become a sponsor](https://www.patreon.com/makasim)
6+
- [Become our client](http://forma-pro.com/)
7+
8+
---
9+
10+
# Amazon SNS-SQS transport
11+
12+
Utilize two Amazon services [SNS-SQS](https://docs.aws.amazon.com/sns/latest/dg/sns-sqs-as-subscriber.html) to
13+
implement [Publish-Subscribe](https://www.enterpriseintegrationpatterns.com/patterns/messaging/PublishSubscribeChannel.html)
14+
enterprise integration pattern. As opposed to single SQS transport this adds ability to use [MessageBus](https://www.enterpriseintegrationpatterns.com/patterns/messaging/MessageBus.html)
15+
with enqueue.
16+
17+
A transport for [Amazon SQS](https://aws.amazon.com/sqs/) broker.
18+
It uses internally official [aws sdk library](https://packagist.org/packages/aws/aws-sdk-php)
19+
20+
* [Installation](#installation)
21+
* [Create context](#create-context)
22+
* [Declare topic, queue and bind them together](#declare-topic-queue-and-bind-them-together)
23+
* [Send message to topic](#send-message-to-topic)
24+
* [Send message to queue](#send-message-to-queue)
25+
* [Consume message](#consume-message)
26+
* [Purge queue messages](#purge-queue-messages)
27+
* [Queue from another AWS account](#queue-from-another-aws-account)
28+
29+
## Installation
30+
31+
```bash
32+
$ composer require enqueue/sqs
33+
```
34+
35+
## Create context
36+
37+
```php
38+
<?php
39+
use Enqueue\SnsQs\SnsQsConnectionFactory;
40+
41+
$factory = new SnsQsConnectionFactory([
42+
'key' => 'aKey',
43+
'secret' => 'aSecret',
44+
'region' => 'aRegion',
45+
46+
// or you can segregate options using prefixes "sns_", "sqs_"
47+
'key' => 'aKey', // common option for both SNS and SQS
48+
'sns_region' => 'aSnsRegion', // SNS transport option
49+
'sqs_region' => 'aSqsRegion', // SQS transport option
50+
]);
51+
52+
// same as above but given as DSN string. You may need to url encode secret if it contains special char (like +)
53+
$factory = new SnsQsConnectionFactory('snsqs:?key=aKey&secret=aSecret&region=aRegion');
54+
55+
$context = $factory->createContext();
56+
57+
// if you have enqueue/enqueue library installed you can use a factory to build context from DSN
58+
$context = (new \Enqueue\ConnectionFactoryFactory())->create('snsqs:')->createContext();
59+
```
60+
61+
## Declare topic, queue and bind them together
62+
63+
Declare topic, queue operation creates a topic, queue on a broker side.
64+
Bind creates connection between topic and queue. You publish message to
65+
the topic and topic sends message to each queue connected to the topic.
66+
67+
68+
```php
69+
<?php
70+
/** @var \Enqueue\SnsQs\SnsQsContext $context */
71+
72+
$inTopic = $context->createTopic('in');
73+
$context->declareTopic($inTopic);
74+
75+
$out1Queue = $context->createQueue('out1');
76+
$context->declareQueue($out1Queue);
77+
78+
$out2Queue = $context->createQueue('out2');
79+
$context->declareQueue($out2Queue);
80+
81+
$context->bind($inTopic, $out1Queue);
82+
$context->bind($inTopic, $out2Queue);
83+
84+
// to remove topic/queue use deleteTopic/deleteQueue method
85+
//$context->deleteTopic($inTopic);
86+
//$context->deleteQueue($out1Queue);
87+
//$context->unbind(inTopic, $out1Queue);
88+
```
89+
90+
## Send message to topic
91+
92+
```php
93+
<?php
94+
/** @var \Enqueue\SnsQs\SnsQsContext $context */
95+
96+
$inTopic = $context->createTopic('in');
97+
$message = $context->createMessage('Hello world!');
98+
99+
$context->createProducer()->send($inTopic, $message);
100+
```
101+
102+
## Send message to queue
103+
104+
You can bypass topic and publish message directly to the queue
105+
106+
```php
107+
<?php
108+
/** @var \Enqueue\SnsQs\SnsQsContext $context */
109+
110+
$fooQueue = $context->createQueue('foo');
111+
$message = $context->createMessage('Hello world!');
112+
113+
$context->createProducer()->send($fooQueue, $message);
114+
```
115+
116+
117+
## Consume message:
118+
119+
```php
120+
<?php
121+
/** @var \Enqueue\SnsQs\SnsQsContext $context */
122+
123+
$out1Queue = $context->createQueue('out1');
124+
$consumer = $context->createConsumer($out1Queue);
125+
126+
$message = $consumer->receive();
127+
128+
// process a message
129+
130+
$consumer->acknowledge($message);
131+
// $consumer->reject($message);
132+
```
133+
134+
## Purge queue messages:
135+
136+
```php
137+
<?php
138+
/** @var \Enqueue\SnsQs\SnsQsContext $context */
139+
140+
$fooQueue = $context->createQueue('foo');
141+
142+
$context->purgeQueue($fooQueue);
143+
```
144+
145+
## Queue from another AWS account
146+
147+
SQS allows to use queues from another account. You could set it globally for all queues via option `queue_owner_aws_account_id` or
148+
per queue using `SnsQsQueue::setQueueOwnerAWSAccountId` method.
149+
150+
```php
151+
<?php
152+
use Enqueue\SnsQs\SnsQsConnectionFactory;
153+
154+
// globally for all queues
155+
$factory = new SnsQsConnectionFactory('snsqs:?sqs_queue_owner_aws_account_id=awsAccountId');
156+
157+
$context = (new SnsQsConnectionFactory('snsqs:'))->createContext();
158+
159+
// per queue.
160+
$queue = $context->createQueue('foo');
161+
$queue->setQueueOwnerAWSAccountId('awsAccountId');
162+
```
163+
164+
## Multi region examples
165+
166+
Enqueue SNSQS provides a generic multi-region support. This enables users to specify which AWS Region to send a command to by setting region on SnsQsQueue.
167+
If not specified the default region is used.
168+
169+
```php
170+
<?php
171+
use Enqueue\SnsQs\SnsQsConnectionFactory;
172+
173+
$context = (new SnsQsConnectionFactory('snsqs:?region=eu-west-2'))->createContext();
174+
175+
$queue = $context->createQueue('foo');
176+
$queue->setRegion('us-west-2');
177+
178+
// the request goes to US West (Oregon) Region
179+
$context->declareQueue($queue);
180+
```
181+
182+
[back to index](../index.md)

0 commit comments

Comments
 (0)
0