Skip to content

Commit d807b87

Browse files
authored
Merge pull request #863 from sylfabre/patch-3
Key concepts
2 parents b58edbe + 61390fe commit d807b87

File tree

2 files changed

+83
-0
lines changed

2 files changed

+83
-0
lines changed

Diff for: docs/concepts.md

+82
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
# Key concepts
2+
3+
If you are new to queuing system, there are some key concepts to understand to make the most of this lib.
4+
5+
The library consist of several components. The components could be used independently or as integral part.
6+
7+
## Components
8+
9+
### Transport
10+
11+
The transport is the underlying vendor-specific library that provides the queuing features: a way for programs to create, send, read messages.
12+
Based on [queue interop](https://github.com/queue-interop/queue-interop) interfaces. Use transport directly if you need full control or access to vendor specific features.
13+
14+
The most famous transports are [RabbitMQ](transport/amqp_lib.md), [Amazon SQS](transport/sqs.md), [Redis](transport/redis.md), [Filesystem](transport/filesystem.md).
15+
16+
- *connection factory* creates a connection to the vendor service with vendor-specific config.
17+
- *context* provides the Producer, the Consumer and helps creates Messages. It is the most commonly used object and an implementation of [abstract factory](https://en.wikipedia.org/wiki/Abstract_factory_pattern) pattern.
18+
- *destination* is a concept of a destination to which messages can be sent. Choose queue or topic. Destination represents broker state so expect to see same names at broker side.
19+
- *queue* is a named destination to which messages can be sent. Messages accumulate on queues until they are retrieved by programs (called consumer) that service those queues.
20+
- *topic* implements [publish and subscribe](https://en.wikipedia.org/wiki/Publish%E2%80%93subscribe_pattern) semantics. When you publish a message it goes to all the subscribers who are interested - so zero to many subscribers will receive a copy of the message. Some brokers do not support Pub\Sub.
21+
- *message* describes data sent to (or received from) a destination. It has body, headers, properties.
22+
- *producer* sends a message to the destination. The producer implements vendor-specific logic and in charge of converting messages between Enqueue and vendor-specific message format.
23+
- *consumer* fetches a message from a destination. The consumer implements vendor-specific logic and in charge of converting messages between vendor-specific message format and Enqueue.
24+
- *subscription consumer* provides a way to consume messages from several destinations simultaneity. Some brokers do not support this feature.
25+
- *processor* is an optional concept useful for sharing message processing logic. Vendor independent. Implements your business logic.
26+
27+
Additional terms we might refer to:
28+
- *receive and delete delivery*: the queue deletes the message when it's fetched by consumer. If processing fails, then the message is lost and won't be processed again. This is called _at most once_ processing.
29+
- *peek and lock delivery*: the queue locks for a short amount of time a message when it's fetched by consumer, making it invisible to other consumers, in order to prevent duplicate processing and message lost. If there is no acknowledgment before the lock times out, failure is assumed and then the message is made visible again in the queue for another try. This is called _at least once_ processing.
30+
- *an explicit acknowledgement*: the queue locks a message when it's fetched by consumer, making it invisible to other consumers, in order to prevent duplicate processing and message lost. If there is no explicit acknowledgment received before the connection is closed, failure is assumed and then the message is made visible again in the queue for another try. This is called _at least once_ processing.
31+
- *message delivery delay*: messages are sent to the queue but won't be visible right away to consumers to fetch them. You may need it to plan an action at a specific time.
32+
- *message expiration*: messages could be dropped of a queue within some period of time without processing. You may need it to not process stale messages. Some transports do not support the feature.
33+
- *message priority*: message could be sent with higher priority, therefor being consumed faster. It violates first in first out concept and should be used with precautions. Some transports do not support the feature.
34+
- *first in first out*: messages are processed in the same order than they have entered the queue.
35+
36+
Lifecycle
37+
38+
A queuing system is divided in two main parts: producing and consuming.
39+
The [transport section of the Quick Start](quick_tour.md#transport) shows some code example for both parts.
40+
41+
Producing part
42+
1. The application creates a Context with a Connection factory
43+
2. The Context helps the application to create a Message
44+
3. The application gets a Producer from the Context
45+
4. The application uses the Producer to send the Message to the queue
46+
47+
Consuming part
48+
1. The application gets a Consumer from the Context
49+
2. The Consumer receives Messages from the queue
50+
3. The Consumer uses a Processor to process a Message
51+
4. The Processor returns a status (like `Interop\Queue\Processor::ACK`) to the Consumer
52+
5. The Consumer requeue or remove the Message from the queue depending on the Processor returned status
53+
54+
### Consumption
55+
56+
The consumption component is based on top of transport.
57+
The most important class is [QueueConsumer](https://github.com/php-enqueue/enqueue-dev/blob/master/pkg/enqueue/Consumption/QueueConsumer.php).
58+
Could be used with any queue interop compatible transport.
59+
It provides extension points which could be ad-hoc into processing flow. You can register [existing extensions](consumption/extensions.md) or write a custom one.
60+
61+
### Client
62+
63+
Enqueue Client is designed for as simple as possible developer experience.
64+
It provides high-level, very opinionated API.
65+
It manage all transport differences internally and even emulate missing features (like publish-subscribe).
66+
Please note: Client has own logic for naming transport destinations. Expect a different transport queue\topic name from the Client topic, command name. The prefix behavior could be disabled.
67+
68+
- *Topic:* Send a message to the topic when you want to notify several subscribers that something has happened. There is no way to get subscriber results. Uses the router internally to deliver messages.
69+
- *Command:* guaranty that there is exactly one command processor\subscriber. Optionally, you can get a result. If there is not a command subscriber an exception is thrown.
70+
- *Router:* copy a message sent to the topic and duplicate it for every subscriber and send.
71+
- *Driver* contains vendor specific logic.
72+
- *Producer* is responsible for sending messages to the topic or command. It has nothing to do with transport's producer.
73+
- *Message* contains data to be sent. Please note that on consumer side you have to deal with transport message.
74+
- *Consumption:* rely on consumption component.
75+
76+
## How to use Enqueue?
77+
78+
There are different ways to use Enqueue: both reduce the boiler plate code you have to write to start using the Enqueue feature.
79+
- as a [Client](client/quick_tour.md): relies on a [DSN](client/supported_brokers.md) to connect
80+
- as a [Symfony Bundle](bundle/index.md): recommended if you are using the Symfony framework
81+
82+
[back to index](index.md)

Diff for: docs/index.md

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ Enqueue is an MIT-licensed open source project with its ongoing development made
1919
## Documentation.
2020

2121
* [Quick tour](quick_tour.md)
22+
* [Key concepts](concepts.md)
2223
* [Transports](#transports)
2324
- Amqp based on [the ext](transport/amqp.md), [bunny](transport/amqp_bunny.md), [the lib](transport/amqp_lib.md)
2425
- [Amazon SNS-SQS](transport/snsqs.md)

0 commit comments

Comments
 (0)