/** * 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); }
public function parse($sourceType, $sourceUrl) { $this->producer->publish('Hello world'); // switch ($sourceType) { // case self::PARSE_TYPE_CATALOG: // $this // } }
/** * @param App\CoreBundle\Event\BuildFinishedEvent */ public function onBuildKilled(BuildKilledEvent $event) { $build = $event->getBuild(); /** @todo write a producer that accepts Message objects */ $this->logger->info('sending build.killed message', ['build' => $build->getId()]); $message = $this->factory->createBuildKilled($build); $this->producer->publish((string) $message); }
public function generateInvoice(Order $order) { $document = $this->createDocumentFromOrder($order); $this->eventDispatcher->dispatch(DocumentEvent::INVOICE_GENERATE_START, new DocumentEvent($document)); $this->documentManager->persist($document); $this->documentManager->flush(); $this->documentProducer->publish($document->getId(), 'document.invoice'); }
/** * @param Campaign $campaign * @param $event */ public function preFlush(Campaign $campaign, $event) { if ($campaign->getHashId() && $campaign->getStatus() !== $campaign->getOldStatus()) { if ($campaign->isNew() && $campaign->getStatus() == Campaign::STATUS_ON) { // $campaign->setIsNew(false); $this->rabbitProducer->publish($campaign->getId()); } } }
public function delayedPublish($delay, $msgBody, $routingKey = '', $additionalProperties = array()) { if (!is_integer($delay) || $delay < 0) { throw new \UnexpectedValueException('Publish delay should be a positive integer.'); } # expire the queue a little bit after the delay, but minimum 1 second $expiration = 1000 + floor(1.1 * $delay); $name = sprintf('%s-exchange', $this->prefix); $id = sprintf('%s-waiting-queue-%s-%d', $this->prefix, $routingKey, $delay); $producer = new Producer($this->connection); $producer->setExchangeOptions(array('name' => $name, 'type' => 'direct')); $producer->setQueueOptions(array('name' => $id, 'routing_keys' => array($id), 'arguments' => array('x-message-ttl' => array('I', $delay), 'x-dead-letter-exchange' => array('S', $this->destination_exchange), 'x-dead-letter-routing-key' => array('S', $routingKey), 'x-expires' => array('I', $expiration)))); $producer->setupFabric(); $producer->publish($msgBody, $id, $additionalProperties); }
public function publish($msgBody, $routingKey = '', $additionalProperties = array()) { try { parent::publish($msgBody, $routingKey, $additionalProperties); } catch (\Exception $e) { if (isset($this->logger)) { $this->logger->error("Can't publish message. Error is " . $e->getMessage()); } } }
private function loadProducers($app) { $_this = $this; $app['rabbit.producer'] = $app->share(function ($app) use($_this) { if (!isset($app['rabbit.producers'])) { return; } $producers = array(); foreach ($app['rabbit.producers'] as $name => $options) { $connection = $_this->getConnection($app, $options, $app['rabbit.connections']); $producer = new Producer($connection); $producer->setExchangeOptions($options['exchange_options']); if (array_key_exists('auto_setup_fabric', $options) && !$options['auto_setup_fabric']) { $producer->disableAutoSetupFabric(); } $producers[$name] = $producer; } return $producers; }); }
/** * @param Bundle $bundle * * @return boolean */ public function removeRepo(Bundle $bundle) { if ($this->bundleUpdateProducer) { // Create a Message object $message = array('bundle_id' => $bundle->getId(), 'action' => 'remove'); // RabbitMQ, publish my message! $this->bundleUpdateProducer->publish(json_encode($message)); return true; } return false; }
/** * {@inheritDoc} */ public function execute(AMQPMessage $msg) { if ($this->logger) { $this->logger->info('[GithubHookConsumer] Received a github post push hook'); } if (null === ($message = json_decode($msg->body))) { if ($this->logger) { $this->logger->err('[GithubHookConsumer] Unable to decode payload'); } return; } $payload = $message->payload; $bundle = $this->manager->getRepository('KnpBundlesBundle:Bundle')->findOneBy(array('name' => $payload->repository->name, 'ownerName' => $payload->repository->owner->name)); if (!$bundle) { if ($this->logger) { $this->logger->warn(sprintf('[GithubHookConsumer] unknown bundle %s/%s', $payload->repository->name, $payload->repository->owner->name)); } return; } $this->producer->publish(serialize(array('bundle_id' => $bundle->getId()))); }
/** * @param JobCalendarDeletedEvent $event */ public function deleted(JobCalendarDeletedEvent $event) { $entity = $event->getEntity(); foreach ($entity->getCalendar()->getGoogleConnections() as $connection) { $googleLink = $this->getGoogleLink($connection, $entity); if (null === $googleLink) { continue; } $message = new GoogleCalendarEvent(); $message->setConnection($connection)->setLinkId($googleLink->getId()); $this->googleDeleteProducer->publish($this->serializer->serialize($message, 'json')); } }
private function loadProducers($app) { $app['rabbit.producer'] = $app->share(function ($app) { if (!isset($app['rabbit.producers'])) { return; } $producers = []; foreach ($app['rabbit.producers'] as $name => $options) { $connection = $this->getConnection($app, $options, $app['rabbit.connections']); $producer = new Producer($connection); $producer->setExchangeOptions($options['exchange_options']); //this producer doesn't define a queue if (!isset($options['queue_options'])) { $options['queue_options']['name'] = null; } $producer->setQueueOptions($options['queue_options']); if (array_key_exists('auto_setup_fabric', $options) && !$options['auto_setup_fabric']) { $producer->disableAutoSetupFabric(); } $producers[$name] = $producer; } return $producers; }); }
/** * @param \stdClass $content */ public function process($content) { $this->producer->publish(json_encode($content->payload)); }
/** * @param $data */ public function process($data) { $this->producer->publish(json_encode($data)); }