Skip to content

Commit 68aed1f

Browse files
author
John Kelly
committed
Merge branch 'mvonahn-master'
2 parents 438392d + 59811a2 commit 68aed1f

File tree

4 files changed

+35
-10
lines changed

4 files changed

+35
-10
lines changed

lib/Thumper/BaseAmqp.php

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,9 @@
3939

4040
abstract class BaseAmqp
4141
{
42+
const NON_PERSISTENT = 1;
43+
const PERSISTENT = 2;
44+
4245
/**
4346
* @var AbstractConnection
4447
*/
@@ -88,6 +91,13 @@ abstract class BaseAmqp
8891
*/
8992
protected $routingKey = '';
9093

94+
/**
95+
* @var array
96+
*/
97+
protected $parameters = array(
98+
'content_type' => 'text/plain'
99+
);
100+
91101
/**
92102
* BaseAmqp constructor.
93103
* @param AbstractConnection $connection
@@ -226,4 +236,21 @@ private function isValidExchangeName($exchangeName)
226236
{
227237
return preg_match('/^[A-Za-z0-9_\-\.\;]*$/', $exchangeName);
228238
}
239+
240+
/**
241+
* @param string $key
242+
* @param string $value
243+
*/
244+
public function setParameter($key, $value)
245+
{
246+
$this->parameters[$key] = $value;
247+
}
248+
249+
/**
250+
* @return array
251+
*/
252+
public function getParameters()
253+
{
254+
return $this->parameters;
255+
}
229256
}

lib/Thumper/Producer.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,12 @@ public function publish($messageBody, $routingKey = '')
6161
}
6262
$this->exchangeReady = true;
6363
}
64+
65+
$this->setParameter('delivery_mode', self::PERSISTENT);
6466

6567
$message = new AMQPMessage(
6668
$messageBody,
67-
array('content_type' => 'text/plain', 'delivery_mode' => 2)
69+
$this->getParameters()
6870
);
6971
$this->channel->basic_publish(
7072
$message,

lib/Thumper/RpcClient.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,12 @@ public function addRequest($messageBody, $server, $requestId, $routingKey = '')
8080
if (empty($requestId)) {
8181
throw new \InvalidArgumentException("You must provide a request ID");
8282
}
83+
$this->setParameter('correlation_id', $requestId);
84+
$this->setParameter('reply_to', $this->queueName);
8385

8486
$message = new AMQPMessage(
8587
$messageBody,
86-
array(
87-
'content_type' => 'text/plain',
88-
'reply_to' => $this->queueName,
89-
'correlation_id' => $requestId
90-
)
88+
$this->getParameters()
9189
);
9290

9391
$this->channel

lib/Thumper/RpcServer.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -103,12 +103,10 @@ public function processMessage(AMQPMessage $message)
103103
*/
104104
protected function sendReply($result, $client, $correlationId)
105105
{
106+
$this->setParameter('correlation_id', $correlationId);
106107
$reply = new AMQPMessage(
107108
$result,
108-
array(
109-
'content_type' => 'text/plain',
110-
'correlation_id' => $correlationId
111-
)
109+
$this->getParameters()
112110
);
113111
$this->channel
114112
->basic_publish($reply, '', $client);

0 commit comments

Comments
 (0)