Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question about the DetailType parameter #74

Open
dcorrea777 opened this issue Jul 11, 2023 · 3 comments
Open

Question about the DetailType parameter #74

dcorrea777 opened this issue Jul 11, 2023 · 3 comments

Comments

@dcorrea777
Copy link

In the send method of the EventBridgeTransport class I noticed that we don't have control over the DetailType parameter, and this parameter is very important in defining the EventBridge rules.

I noticed it's not on version 1.0 yet, I'd like to know what your plans are.

@mnapoli
Copy link
Member

mnapoli commented Jul 15, 2023

Could you clarify what you mean? I don't understand.

@dcorrea777
Copy link
Author

Sorry for not being clear. @mnapoli .

I installed this package to test the following scenario:

My application publishes a message to my custom EventBus on AWS using the EventBridge service.

Using the AWS SDK to publish a message on the Bus, it is possible to do as follows:

// SDK AWS 
// https://docs.aws.amazon.com/aws-sdk-php/v3/api/api-eventbridge-2015-10-07.html#putevents
$result = $client->putEvents([
    'EndpointId' => '<string>',
    'Entries' => [ // REQUIRED
        [
            'Detail' => '<string>',
            'DetailType' => '<string>',
            'EventBusName' => '<string>',
            'Resources' => ['<string>', ...],
            'Source' => '<string>',
            'Time' => <integer || string || DateTime>,
            'TraceHeader' => '<string>',
        ],
        // ...
    ],
]);

Note that in the AWS example, it is possible to pass the DetailType parameter and the Source.
In your EventBridgeTransport object, I cannot control the DetailType parameter, and it is essential for a consumer to be able to filter a message type.

Your class

    // https://github.com/brefphp/symfony-messenger/blob/master/src/Service/EventBridge/EventBridgeTransport.php
    public function send(Envelope $envelope): Envelope
    {
        $encodedMessage = $this->serializer->encode($envelope);
        $arguments = [
            'Entries' => [
                [
                    'Detail' => json_encode($encodedMessage, JSON_THROW_ON_ERROR),
                    // Ideally here we could put the class name of the message, but how to retrieve it?
                    'DetailType' => 'Symfony Messenger message',
                    'Source' => $this->source,
                ],
            ],
        ];

        if ($this->eventBusName) {
            $arguments['Entries'][0]['EventBusName'] = $this->eventBusName;
        }

        try {
            $result = $this->eventBridge->putEvents($arguments);
            $failedCount = $result->getFailedEntryCount();
        } catch (Throwable $e) {
            throw new TransportException($e->getMessage(), 0, $e);
        }

        if ($failedCount > 0) {
            foreach ($result->getEntries() as $entry) {
                $reason = $entry->getErrorMessage() ?? 'no reason provided';
                throw new TransportException("$failedCount message(s) could not be published to EventBridge: $reason.");
            }
        }

        return $envelope;
    }

@mnapoli
Copy link
Member

mnapoli commented Jul 17, 2023

Ahh ok, thanks for explaining.

There are no specific plans for now, it's open to ideas. I'm happy to merge pull requests or be hired to work on this topic (I don't have an immediate need for this feature personally).

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

No branches or pull requests

2 participants