1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Bdf\QueueMessengerBundle\Transport\Stamp; |
4
|
|
|
|
5
|
|
|
use Bdf\Queue\Message\Message; |
6
|
|
|
use Symfony\Component\Messenger\Stamp\StampInterface; |
7
|
|
|
|
8
|
|
|
/** |
9
|
|
|
* DestinationStamp configuration |
10
|
|
|
*/ |
11
|
|
|
class DestinationStamp implements StampInterface |
12
|
|
|
{ |
13
|
|
|
const RPC_TIMEOUT = 1000; |
14
|
|
|
|
15
|
|
|
private $messageName; |
16
|
|
|
private $maxTries; |
17
|
|
|
private $noStore; |
18
|
|
|
private $rpcTimeout = self::RPC_TIMEOUT; |
19
|
|
|
private $needsReply; |
20
|
|
|
private $headers = []; |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* @param string|null $messageName |
24
|
|
|
* |
25
|
|
|
* @return $this |
26
|
|
|
*/ |
27
|
|
|
public function setMessageName(?string $messageName) |
28
|
|
|
{ |
29
|
|
|
$this->messageName = $messageName; |
30
|
|
|
|
31
|
|
|
return $this; |
32
|
|
|
} |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @return string|null |
36
|
|
|
*/ |
37
|
|
|
public function getMessageName(): ?string |
38
|
|
|
{ |
39
|
|
|
return $this->messageName; |
40
|
|
|
} |
41
|
|
|
|
42
|
|
|
/** |
43
|
|
|
* Change the message max retry count |
44
|
|
|
* If set to zero, default retry count is used |
45
|
|
|
* |
46
|
|
|
* @param int $value |
47
|
|
|
* |
48
|
|
|
* @return $this |
49
|
|
|
*/ |
50
|
|
|
public function setMaxTries(?int $value) |
51
|
|
|
{ |
52
|
|
|
$this->maxTries = $value; |
53
|
|
|
|
54
|
|
|
return $this; |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
/** |
58
|
|
|
* Get max number of retry |
59
|
|
|
* |
60
|
|
|
* @return int |
61
|
|
|
*/ |
62
|
|
|
public function getMaxTries(): ?int |
63
|
|
|
{ |
64
|
|
|
return $this->maxTries; |
65
|
|
|
} |
66
|
|
|
|
67
|
|
|
/** |
68
|
|
|
* Disable storing job when failed |
69
|
|
|
* |
70
|
|
|
* @param bool $flag |
71
|
|
|
* |
72
|
|
|
* @return $this |
73
|
|
|
*/ |
74
|
|
|
public function disableStore(bool $flag = true) |
75
|
|
|
{ |
76
|
|
|
$this->noStore = $flag; |
77
|
|
|
|
78
|
|
|
return $this; |
79
|
|
|
} |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Does the job should be saved when failed to execute ? |
83
|
|
|
* If the return value is true, the failed job should not be stored |
84
|
|
|
* |
85
|
|
|
* @return null|true |
86
|
|
|
*/ |
87
|
|
|
public function noStore(): bool |
88
|
|
|
{ |
89
|
|
|
return (bool)$this->noStore; |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/** |
93
|
|
|
* Change the rpc timeout (in milliseconds) |
94
|
|
|
* |
95
|
|
|
* @param int $value |
96
|
|
|
* |
97
|
|
|
* @return $this |
98
|
|
|
*/ |
99
|
|
|
public function setRpcTimeout(int $value) |
100
|
|
|
{ |
101
|
|
|
$this->rpcTimeout = $value; |
102
|
|
|
|
103
|
|
|
return $this; |
104
|
|
|
} |
105
|
|
|
|
106
|
|
|
/** |
107
|
|
|
* Get the rpc timeout |
108
|
|
|
* |
109
|
|
|
* @return int |
110
|
|
|
*/ |
111
|
|
|
public function getRpcTimeout(): int |
112
|
|
|
{ |
113
|
|
|
return $this->rpcTimeout; |
114
|
|
|
} |
115
|
|
|
|
116
|
|
|
/** |
117
|
|
|
* Defines if the message needs a reply or not |
118
|
|
|
* |
119
|
|
|
* @param bool $needsReply true for enable reply |
120
|
|
|
* |
121
|
|
|
* @return $this |
122
|
|
|
* |
123
|
|
|
* @see PromiseInterface |
124
|
|
|
*/ |
125
|
|
|
public function setNeedsReply(bool $needsReply = true): Message |
126
|
|
|
{ |
127
|
|
|
$this->needsReply = $needsReply; |
128
|
|
|
|
129
|
|
|
return $this; |
|
|
|
|
130
|
|
|
} |
131
|
|
|
|
132
|
|
|
/** |
133
|
|
|
* Check whether the message needs reply |
134
|
|
|
* |
135
|
|
|
* @return bool |
136
|
|
|
*/ |
137
|
|
|
public function getNeedsReply(): bool |
138
|
|
|
{ |
139
|
|
|
return (bool)$this->needsReply; |
140
|
|
|
} |
141
|
|
|
|
142
|
|
|
/** |
143
|
|
|
* Set the message driver options |
144
|
|
|
* |
145
|
|
|
* @param array $headers |
146
|
|
|
* |
147
|
|
|
* @return $this |
148
|
|
|
*/ |
149
|
|
|
public function setHeaders(array $headers) |
150
|
|
|
{ |
151
|
|
|
$this->headers = $headers; |
152
|
|
|
|
153
|
|
|
return $this; |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Get all message headers. |
158
|
|
|
* |
159
|
|
|
* @return array |
160
|
|
|
*/ |
161
|
|
|
public function getHeaders(): array |
162
|
|
|
{ |
163
|
|
|
return $this->headers; |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* @param string $topic |
168
|
|
|
* @return $this |
169
|
|
|
*/ |
170
|
|
|
public function setTopic(string $topic) |
171
|
|
|
{ |
172
|
|
|
$this->headers['topic'] = $topic; |
173
|
|
|
|
174
|
|
|
return $this; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $value |
179
|
|
|
* @return $this |
180
|
|
|
*/ |
181
|
|
|
public function setReplyTo(string $value) |
182
|
|
|
{ |
183
|
|
|
$this->headers['replyTo'] = $value; |
184
|
|
|
|
185
|
|
|
return $this; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $value |
190
|
|
|
* @return $this |
191
|
|
|
*/ |
192
|
|
|
public function setCorrelationId(string $value) |
193
|
|
|
{ |
194
|
|
|
$this->headers['correlationId'] = $value; |
195
|
|
|
|
196
|
|
|
return $this; |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|