@@ -12,6 +12,7 @@ class Producer extends BaseAmqp implements ProducerInterface
12
12
{
13
13
protected $ contentType = 'text/plain ' ;
14
14
protected $ deliveryMode = 2 ;
15
+ protected $ defaultRoutingKey = '' ;
15
16
16
17
public function setContentType ($ contentType )
17
18
{
@@ -27,6 +28,13 @@ public function setDeliveryMode($deliveryMode)
27
28
return $ this ;
28
29
}
29
30
31
+ public function setDefaultRoutingKey ($ defaultRoutingKey )
32
+ {
33
+ $ this ->defaultRoutingKey = $ defaultRoutingKey ;
34
+
35
+ return $ this ;
36
+ }
37
+
30
38
protected function getBasicProperties ()
31
39
{
32
40
return array ('content_type ' => $ this ->contentType , 'delivery_mode ' => $ this ->deliveryMode );
@@ -40,7 +48,7 @@ protected function getBasicProperties()
40
48
* @param array $additionalProperties
41
49
* @param array $headers
42
50
*/
43
- public function publish ($ msgBody , $ routingKey = '' , $ additionalProperties = array (), array $ headers = null )
51
+ public function publish ($ msgBody , $ routingKey = null , $ additionalProperties = array (), array $ headers = null )
44
52
{
45
53
if ($ this ->autoSetupFabric ) {
46
54
$ this ->setupFabric ();
@@ -53,7 +61,8 @@ public function publish($msgBody, $routingKey = '', $additionalProperties = arra
53
61
$ msg ->set ('application_headers ' , $ headersTable );
54
62
}
55
63
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 );
57
66
$ this ->logger ->debug ('AMQP message published ' , array (
58
67
'amqp ' => array (
59
68
'body ' => $ msgBody ,
0 commit comments