-
Notifications
You must be signed in to change notification settings - Fork 55
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] Can't consume messages from third-party GPS publisher #130
Comments
Hi again, I've managed to make the Consumer work but faced mulitple issues. The first one is that the body is not a serialized string but a JSON this time, so I had to create a custom Serializer in order to consume the messages. Does anyone have any idea on what I should do next to have the headers properly interpreted please? Here are my codes working so far:
framework:
messenger:
default_bus: default
transports:
pubsub_queue:
dsn: 'enqueue://gps?queue[name]=%env(resolve:PUBSUB_SUBSCRIPTION_NAME)%&topic[name]=%env(resolve:PUBSUB_TOPIC_NAME)%'
serializer: App\Serializer\MessengerJsonSerializer
routing:
App\Message\Shopify\PubSubMessage: pubsub_queue
<?php
declare(strict_types=1);
namespace App\Message\Shopify;
class PubSubMessage
{
private array $payload;
public function __construct(array $payload)
{
$this->payload = $payload;
}
public function getPayload(): array
{
return $this->payload;
}
}
<?php
declare(strict_types=1);
namespace App\MessageHandler\Shopify;
use App\Message\Shopify\PubSubMessage;
use Symfony\Component\Messenger\Attribute\AsMessageHandler;
#[AsMessageHandler]
final class PubSubMessageHandler
{
public function __invoke(PubSubMessage $message): void
{
$payload = $message->getPayload();
}
}
<?php
declare(strict_types=1);
namespace App\Serializer;
use App\Message\Shopify\PubSubMessage;
use Symfony\Component\Messenger\Envelope;
use Symfony\Component\Messenger\Exception\MessageDecodingFailedException;
use Symfony\Component\Messenger\Stamp\SerializedMessageStamp;
use Symfony\Component\Messenger\Transport\Serialization\SerializerInterface;
use Symfony\Component\Serializer\SerializerInterface as SymfonySerializerInterface;
use function json_validate;
class MessengerJsonSerializer implements SerializerInterface
{
private SymfonySerializerInterface $serializer;
private string $format;
public function __construct(SymfonySerializerInterface $serializer, string $format = 'json')
{
$this->serializer = $serializer;
$this->format = $format;
}
public function decode(array $encodedEnvelope): Envelope
{
if (empty($encodedEnvelope['body'])) {
throw new MessageDecodingFailedException('Encoded envelope should have at least a "body", or maybe you should implement your own serializer.');
}
$body = $encodedEnvelope['body'];
if (!json_validate($body)) {
throw new MessageDecodingFailedException('Invalid JSON data: ' . json_last_error_msg());
}
$message = new PubSubMessage(json_decode($body, true));
return new Envelope($message, []);
}
public function encode(Envelope $envelope): array
{
$message = $envelope->getMessage();
$headers = ['type' => get_class($message)];
$body = $this->serializer->serialize($message, $this->format);
return [
'body' => $body,
'headers' => $headers,
];
}
} Thanks for your help. |
Hi, I'm trying to setup Google Pub/Sub (GPS) with Shopify and Symfony 6.4, but even though messages seem to be published on GPS (can see them in the Google Cloud Console), no matter which configuration I try, it doesn't seem to consume the messages.
I've installed the following packages:
sroze/messenger-enqueue-transport
(version 0.8.0)enqueue/gps
(version 0.10.19)Here's my configuration files:
config/packages/messenger.yaml
:config/packages/enqueue.yaml
:.env.dev.local
:Then I run the command
php bin/console messenger:consume shopify_webhook_queue -vvv
and nothing happens.Additional information
php bin/console enqueue:consume --setup-broker -vvv
, I get the following error:... but I'm trying to connect to an actual Google Pub/Sub project for my tests, not the emulator
-sub
, or is it the same as the topic name ? For now, I've been using the name shown in the Google Cloud Console.Thank you for your help.
The text was updated successfully, but these errors were encountered: