Skip to content

Commit

Permalink
Producer::publish() accepts message headers
Browse files Browse the repository at this point in the history
  • Loading branch information
paveljanda committed May 9, 2017
1 parent fdc220b commit 6753ec9
Showing 1 changed file with 5 additions and 8 deletions.
13 changes: 5 additions & 8 deletions src/Producer/Producer.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,17 +54,14 @@ public function __construct(
}


/**
* @todo Headers
*/
public function publish(string $message): void
public function publish(string $message, array $headers = []): void
{
if ($this->queue) {
$this->publishToQueue($message);
$this->publishToQueue($message, $headers);
}

if ($this->exchange) {
$this->publishToExchange($message);
$this->publishToExchange($message, $headers);
}
}

Expand All @@ -80,12 +77,12 @@ private function publishToQueue(string $message, array $headers = []): void
}


private function publishToExchange(string $message): void
private function publishToExchange(string $message, array $headers = []): void
{
foreach ($this->exchange->getQueueBindings() as $queueBinding) {
$queueBinding->getQueue()->getConnection()->getChannel()->publish(
$message,
[],
$headers,
$this->exchange->getName(),
$queueBinding->getRoutingKey()
);
Expand Down

0 comments on commit 6753ec9

Please sign in to comment.