Skip to content
This repository has been archived by the owner on Jan 11, 2019. It is now read-only.

Add EventDispatcher to producer #45

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

ernestre
Copy link

No description provided.

@ernestre ernestre closed this Jul 20, 2017
@ernestre ernestre reopened this Jul 21, 2017
Copy link
Member

@lchrusciel lchrusciel left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm mostly ok with it, I've pointed out only minor changes. But can you provide any live example of usage? I'm just curious.

@@ -59,111 +59,128 @@ function it_publishes_product_created_events(ProducerInterface $producer)
'data' => [['amount' => 20, 'currency' => 'USD']],
],
],
],
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indent

],
];


Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Too many blank lines

'code' => 'X_SELL',
'labels' => [
'en_US' => 'Cross sell',
'fr_FR' => 'Vente croisée',
],
],
];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wrong indent

function it_should_be_constructed_correctly()
{
$payload = [
'foo' => 'bar'
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could be fitted into one line

$producer->publish(json_encode([
'type' => 'message_type',
'payload' => $item,
'recordedOn' => (new \DateTime())->format('Y-m-d H:i:s'),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just an idea. We could extract this format to some constant, WDYT?


use Symfony\Component\EventDispatcher\Event;

class MessageEvent extends Event
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this class be extendable?


/**
* @param ProducerInterface $producer
* @param $messageType
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing typehint

Copy link
Contributor

@pamil pamil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks OK, but this kind of support for events should be added in a ItemWriterInterface decorator named like EventDispatchingItemWriter - then we wouldn't need to modify all the specs and modify existing classes but just add this one and change dependency injection configuration, separating the concerns.

@ernestre
Copy link
Author

@lchrusciel, these events are useful when you want do have some additional logic after message was published. For example, Akeneo stores categories in a nested set model i want to have this model in my system as well. By extending Akeneo's CategoryNormalizer class you can sync the category model with additional fields (left, right, level, root), however you also need to update parent nodes after category insertion. By listening to this event, you can get parent nodes which were affected by inserted category and publish them to the same queue.

@pamil, OK, I'll create the decorator.

Also, i see that different ItemProjector services are registered without an id, I think it would be nice to add service id's for each ItemProjector, this way you can reuse or inject projectors somewhere else. WDUT?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants