Skip to content

Commit cffcbfc

Browse files
committed
Merge pull request #345 from dakorpar/publish_with_headers
Allow setting "application_headers" on publishing message RabbitMq\Producer::publish()
2 parents 09be4be + ead4230 commit cffcbfc

File tree

1 file changed

+9
-1
lines changed

1 file changed

+9
-1
lines changed

RabbitMq/Producer.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use OldSound\RabbitMqBundle\RabbitMq\BaseAmqp;
66
use PhpAmqpLib\Message\AMQPMessage;
7+
use PhpAmqpLib\Wire\AMQPTable;
78

89
/**
910
* Producer, that publishes AMQP Messages
@@ -38,14 +39,21 @@ protected function getBasicProperties()
3839
* @param string $msgBody
3940
* @param string $routingKey
4041
* @param array $additionalProperties
42+
* @param array $headers
4143
*/
42-
public function publish($msgBody, $routingKey = '', $additionalProperties = array())
44+
public function publish($msgBody, $routingKey = '', $additionalProperties = array(), array $headers = null)
4345
{
4446
if ($this->autoSetupFabric) {
4547
$this->setupFabric();
4648
}
4749

4850
$msg = new AMQPMessage((string) $msgBody, array_merge($this->getBasicProperties(), $additionalProperties));
51+
52+
if(!empty($headers)){
53+
$headersTable = new AMQPTable($headers);
54+
$msg->set('application_headers', $headersTable);
55+
}
56+
4957
$this->getChannel()->basic_publish($msg, $this->exchangeOptions['name'], (string) $routingKey);
5058
}
5159
}

0 commit comments

Comments
 (0)