/** * Publish the given Message by serializing it and handing it over to a RabbitMQ producer * * @{inheritdoc} */ public function publish($message) { $serializedMessage = $this->serializer->wrapAndSerialize($message); $routingKey = $this->routingKeyResolver->resolveRoutingKeyFor($message); $additionalProperties = $this->additionalPropertiesResolver->resolveAdditionalPropertiesFor($message); $this->producer->publish($serializedMessage, $routingKey, $additionalProperties); }
/** * Serialize a Message by wrapping it in an Envelope and serializing the envelope. This decoration will * take the SimpleBus envelope and add it in a json message. * * {@inheritdoc} */ public function wrapAndSerialize($originalMessage) { $serializedMessage = $this->serializer->wrapAndSerialize($originalMessage); $message = []; foreach ($this->headers as $name => $value) { if (empty($value)) { continue; } $message['headers'][] = ['key' => $name, 'value' => $value]; } $message['body'] = $serializedMessage; // Add a hash where the secret key is baked in. $message['headers'][] = ['key' => 'hash', 'value' => sha1($this->secretKey . $serializedMessage)]; $event = new PrePublishMessage($message, is_object($originalMessage) ? get_class($originalMessage) : gettype($originalMessage)); $this->eventDispatcher->dispatch(PrePublishMessage::NAME, $event); return json_encode($event->getMessage()); }