Skip to content

Commit

Permalink
Start preparing navigation structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Steveb-p authored and Paweł Niedzielski committed May 27, 2019
1 parent 8e7a0f1 commit ce6ca69
Show file tree
Hide file tree
Showing 53 changed files with 664 additions and 415 deletions.
10 changes: 7 additions & 3 deletions docs/async_event_dispatcher/quick_tour.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: default
nav_exclude: true
---
<h2 align="center">Supporting Enqueue</h2>

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:
Expand All @@ -9,9 +13,9 @@ Enqueue is an MIT-licensed open source project with its ongoing development made

# Async event dispatcher (Symfony)

The doc shows how you can setup async event dispatching in plain PHP.
The doc shows how you can setup async event dispatching in plain PHP.
If you are looking for the ways to use it in Symfony application [read this post instead](../bundle/async_events.md)

* [Installation](#installation)
* [Configuration](#configuration)
* [Dispatch event](#dispatch-event)
Expand Down Expand Up @@ -47,7 +51,7 @@ $context = (new FsConnectionFactory('file://'.__DIR__.'/queues'))->createContext
$eventQueue = $context->createQueue('symfony_events');

$registry = new SimpleRegistry(
['the_event' => 'default'],
['the_event' => 'default'],
['default' => new PhpSerializerEventTransformer($context)]
);

Expand Down
8 changes: 6 additions & 2 deletions docs/bundle/async_commands.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: default
nav_exclude: true
---
<h2 align="center">Supporting Enqueue</h2>

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:
Expand Down Expand Up @@ -63,9 +67,9 @@ $promise = $producer->sendCommand(Commands::RUN_COMMAND, new RunCommand('debug:c

// do other stuff.

if ($replyMessage = $promise->receive(5000)) {
if ($replyMessage = $promise->receive(5000)) {
$result = CommandResult::jsonUnserialize($replyMessage->getBody());

echo $result->getOutput();
}
```
Expand Down
34 changes: 19 additions & 15 deletions docs/bundle/async_events.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: default
nav_exclude: true
---
<h2 align="center">Supporting Enqueue</h2>

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:
Expand All @@ -9,9 +13,9 @@ Enqueue is an MIT-licensed open source project with its ongoing development made

# Async events

The EnqueueBundle allows you to dispatch events asynchronously.
Behind the scene it replaces your listener with one that sends a message to MQ.
The message contains the event object.
The EnqueueBundle allows you to dispatch events asynchronously.
Behind the scene it replaces your listener with one that sends a message to MQ.
The message contains the event object.
The consumer, once it receives the message, restores the event and dispatches it to only async listeners.

Async listeners benefits:
Expand Down Expand Up @@ -57,14 +61,14 @@ or to `kernel.event_subscriber`:
```yaml
# app/config/config.yml
services:
services:
test_async_subscriber:
class: 'AcmeBundle\Listener\TestAsyncSubscriber'
tags:
- { name: 'kernel.event_subscriber', async: true }
```

That's basically it. The rest of the doc describes advanced features.
That's basically it. The rest of the doc describes advanced features.

## Advanced Usage.

Expand All @@ -87,8 +91,8 @@ services:

The bundle uses [php serializer](https://github.com/php-enqueue/enqueue-dev/blob/master/pkg/enqueue-bundle/Events/PhpSerializerEventTransformer.php) transformer by default to pass events through MQ.
You can write a transformer for each event type by implementing the `Enqueue\AsyncEventDispatcher\EventTransformer` interface.
Consider the next example. It shows how to send an event that contains Doctrine entity as a subject
Consider the next example. It shows how to send an event that contains Doctrine entity as a subject

```php
<?php
namespace AcmeBundle\Listener;
Expand Down Expand Up @@ -116,22 +120,22 @@ class FooEventTransformer implements EventTransformer
/**
* {@inheritdoc}
*
*
* @param GenericEvent $event
*/
public function toMessage($eventName, Event $event = null)
{
$entity = $event->getSubject();
$entityClass = get_class($entity);
$manager = $this->doctrine->getManagerForClass($entityClass);
$meta = $manager->getClassMetadata($entityClass);
$id = $meta->getIdentifierValues($entity);
$message = new Message();
$message->setBody([
'entityClass' => $entityClass,
'entityClass' => $entityClass,
'entityId' => $id,
'arguments' => $event->getArguments()
]);
Expand All @@ -145,14 +149,14 @@ class FooEventTransformer implements EventTransformer
public function toEvent($eventName, QueueMessage $message)
{
$data = JSON::decode($message->getBody());
$entityClass = $data['entityClass'];
$manager = $this->doctrine->getManagerForClass($entityClass);
if (false == $entity = $manager->find($entityClass, $data['entityId'])) {
return Result::reject('The entity could not be found.');
}
return new GenericEvent($entity, $data['arguments']);
}
}
Expand All @@ -171,7 +175,7 @@ services:
- {name: 'enqueue.event_transformer', eventName: 'foo' }
```

The `eventName` attribute accepts a regexp. You can do next `eventName: '/foo\..*?/'`.
The `eventName` attribute accepts a regexp. You can do next `eventName: '/foo\..*?/'`.
It uses this transformer for all event with the name beginning with `foo.`

[back to index](../index.md)
8 changes: 6 additions & 2 deletions docs/bundle/cli_commands.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: default
nav_exclude: true
---
<h2 align="center">Supporting Enqueue</h2>

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:
Expand All @@ -9,7 +13,7 @@ Enqueue is an MIT-licensed open source project with its ongoing development made

# Cli commands

The EnqueueBundle provides several commands.
The EnqueueBundle provides several commands.
The most useful one `enqueue:consume` connects to the broker and process the messages.
Other commands could be useful during debugging (like `enqueue:topics`) or deployment (like `enqueue:setup-broker`).

Expand Down Expand Up @@ -134,7 +138,7 @@ Help:
```

## enqueue:transport:consume

```
./bin/console enqueue:transport:consume --help
Usage:
Expand Down
4 changes: 4 additions & 0 deletions docs/bundle/config_reference.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: default
nav_exclude: true
---
<h2 align="center">Supporting Enqueue</h2>

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:
Expand Down
6 changes: 5 additions & 1 deletion docs/bundle/consumption_extension.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: default
nav_exclude: true
---
<h2 align="center">Supporting Enqueue</h2>

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:
Expand All @@ -23,7 +27,7 @@ use Enqueue\Consumption\Context\PostMessageReceived;
class CountProcessedMessagesExtension implements PostMessageReceivedExtensionInterface
{
private $processedMessages = 0;

public function onPostMessageReceived(PostMessageReceived $context): void
{
$this->processedMessages += 1;
Expand Down
26 changes: 15 additions & 11 deletions docs/bundle/debugging.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: default
nav_exclude: true
---
<h2 align="center">Supporting Enqueue</h2>

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:
Expand All @@ -11,7 +15,7 @@ Enqueue is an MIT-licensed open source project with its ongoing development made

## Profiler

It may be useful to see what messages were sent during a http request.
It may be useful to see what messages were sent during a http request.
The bundle provides a collector for Symfony [profiler](http://symfony.com/doc/current/profiler.html).
The extension collects all sent messages

Expand All @@ -36,17 +40,17 @@ use Symfony\Component\HttpFoundation\Request;
use Enqueue\Client\Message;
use Enqueue\Client\ProducerInterface;

class DefaultController extends Controller
class DefaultController extends Controller
/**
* @Route("/", name="homepage")
*/
public function indexAction(Request $request)
{
/** @var ProducerInterface $producer */
$producer = $this->get('enqueue.producer');
$producer = $this->get('enqueue.producer');

$producer->sendEvent('foo_topic', 'Hello world');

$producer->sendEvent('bar_topic', ['bar' => 'val']);

$message = new Message();
Expand All @@ -59,10 +63,10 @@ class DefaultController extends Controller
```

For this action you may see something like this in the profiler:

![Symfony profiler](../images/symfony_profiler.png)
## Queues and topics available

## Queues and topics available

There are two console commands `./bin/console enqueue:queues` and `./bin/console enqueue:topics`.
They are here to help you to learn more about existing topics and queues.
Expand All @@ -71,11 +75,11 @@ Here's the result:

![Cli debug commands](../images/cli_debug_commands.png)

## Consume command verbosity
## Consume command verbosity

By default the commands `enqueue:consume` or `enqueue:transport:consume` does not output anything.
By default the commands `enqueue:consume` or `enqueue:transport:consume` does not output anything.
You can add `-vvv` to see more information.

![Consume command verbosity](../images/consume_command_verbosity.png)

[back to index](../index.md)
34 changes: 19 additions & 15 deletions docs/bundle/functional_testing.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
---
layout: default
nav_exclude: true
---
<h2 align="center">Supporting Enqueue</h2>

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:
Expand All @@ -10,17 +14,17 @@ Enqueue is an MIT-licensed open source project with its ongoing development made
# Functional testing

In this chapter we give some advices on how to test message queue related logic.

* [NULL transport](#null-transport)
* [Traceable message producer](#traceable-message-producer)

## NULL transport

While testing the application you don't usually need to send real message to real broker.
Or even have a dependency on a MQ broker.
Here's the purpose of the NULL transport.
It simple do nothing when you ask it to send a message.
Pretty useful in tests.
While testing the application you don't usually need to send real message to real broker.
Or even have a dependency on a MQ broker.
Here's the purpose of the NULL transport.
It simple do nothing when you ask it to send a message.
Pretty useful in tests.
Here's how you can configure it.

```yaml
Expand All @@ -35,7 +39,7 @@ enqueue:
## Traceable message producer
Imagine you have a service `my_service` with a method `someMethod()` that internally sends a message and you have to find out was the message sent or not.
There is a solution for that. You have to enable traceable message producer in test environment.
There is a solution for that. You have to enable traceable message producer in test environment.

```yaml
# app/config/config_test.yml
Expand All @@ -57,28 +61,28 @@ class FooTest extends WebTestCase
{
/** @var \Symfony\Bundle\FrameworkBundle\Client */
private $client;
public function setUp()
{
$this->client = static::createClient();
$this->client = static::createClient();
}
public function testMessageSentToFooTopic()
{
// Use your own business logic here:
$service = $this->client->getContainer()->get('my_service');
// someMethod() is part of your business logic and is calling somewhere $producer->send('fooTopic', 'messageBody');
$service->someMethod();
$traces = $this->getProducer()->getTopicTraces('fooTopic');
$this->assertCount(1, $traces);
$this->assertEquals('messageBody', $traces[0]['message']);
}
/**
* @return TraceableProducer
* @return TraceableProducer
*/
private function getProducer()
{
Expand Down
Loading

0 comments on commit ce6ca69

Please sign in to comment.