@@ -12,6 +12,7 @@ class Producer extends BaseAmqp implements ProducerInterface
1212{
1313 protected $ contentType = 'text/plain ' ;
1414 protected $ deliveryMode = 2 ;
15+ protected $ defaultRoutingKey = '' ;
1516
1617 public function setContentType ($ contentType )
1718 {
@@ -27,6 +28,13 @@ public function setDeliveryMode($deliveryMode)
2728 return $ this ;
2829 }
2930
31+ public function setDefaultRoutingKey ($ defaultRoutingKey )
32+ {
33+ $ this ->defaultRoutingKey = $ defaultRoutingKey ;
34+
35+ return $ this ;
36+ }
37+
3038 protected function getBasicProperties ()
3139 {
3240 return array ('content_type ' => $ this ->contentType , 'delivery_mode ' => $ this ->deliveryMode );
@@ -40,7 +48,7 @@ protected function getBasicProperties()
4048 * @param array $additionalProperties
4149 * @param array $headers
4250 */
43- public function publish ($ msgBody , $ routingKey = '' , $ additionalProperties = array (), array $ headers = null )
51+ public function publish ($ msgBody , $ routingKey = null , $ additionalProperties = array (), array $ headers = null )
4452 {
4553 if ($ this ->autoSetupFabric ) {
4654 $ this ->setupFabric ();
@@ -53,7 +61,8 @@ public function publish($msgBody, $routingKey = '', $additionalProperties = arra
5361 $ msg ->set ('application_headers ' , $ headersTable );
5462 }
5563
56- $ this ->getChannel ()->basic_publish ($ msg , $ this ->exchangeOptions ['name ' ], (string )$ routingKey );
64+ $ real_routingKey = $ routingKey != null ? $ routingKey : $ this ->defaultRoutingKey ;
65+ $ this ->getChannel ()->basic_publish ($ msg , $ this ->exchangeOptions ['name ' ], (string )$ real_routingKey );
5766 $ this ->logger ->debug ('AMQP message published ' , array (
5867 'amqp ' => array (
5968 'body ' => $ msgBody ,
0 commit comments