|
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
|
|
|
public 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
|
|
|
* @return $this |
|
24
|
|
|
*/ |
|
25
|
|
|
public function setMessageName(?string $messageName) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->messageName = $messageName; |
|
28
|
|
|
|
|
29
|
|
|
return $this; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function getMessageName(): ?string |
|
33
|
|
|
{ |
|
34
|
|
|
return $this->messageName; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* Change the message max retry count |
|
39
|
|
|
* If set to zero, default retry count is used. |
|
40
|
|
|
* |
|
41
|
|
|
* @param int $value |
|
42
|
|
|
* |
|
43
|
|
|
* @return $this |
|
44
|
|
|
*/ |
|
45
|
|
|
public function setMaxTries(?int $value) |
|
46
|
|
|
{ |
|
47
|
|
|
$this->maxTries = $value; |
|
48
|
|
|
|
|
49
|
|
|
return $this; |
|
50
|
|
|
} |
|
51
|
|
|
|
|
52
|
|
|
/** |
|
53
|
|
|
* Get max number of retry. |
|
54
|
|
|
* |
|
55
|
|
|
* @return int |
|
56
|
|
|
*/ |
|
57
|
|
|
public function getMaxTries(): ?int |
|
58
|
|
|
{ |
|
59
|
|
|
return $this->maxTries; |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Disable storing job when failed. |
|
64
|
|
|
* |
|
65
|
|
|
* @return $this |
|
66
|
|
|
*/ |
|
67
|
|
|
public function disableStore(bool $flag = true) |
|
68
|
|
|
{ |
|
69
|
|
|
$this->noStore = $flag; |
|
70
|
|
|
|
|
71
|
|
|
return $this; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Does the job should be saved when failed to execute ? |
|
76
|
|
|
* If the return value is true, the failed job should not be stored. |
|
77
|
|
|
*/ |
|
78
|
|
|
public function noStore(): bool |
|
79
|
|
|
{ |
|
80
|
|
|
return (bool) $this->noStore; |
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* Change the rpc timeout (in milliseconds). |
|
85
|
|
|
* |
|
86
|
|
|
* @return $this |
|
87
|
|
|
*/ |
|
88
|
|
|
public function setRpcTimeout(int $value) |
|
89
|
|
|
{ |
|
90
|
|
|
$this->rpcTimeout = $value; |
|
91
|
|
|
|
|
92
|
|
|
return $this; |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
/** |
|
96
|
|
|
* Get the rpc timeout. |
|
97
|
|
|
*/ |
|
98
|
|
|
public function getRpcTimeout(): int |
|
99
|
|
|
{ |
|
100
|
|
|
return $this->rpcTimeout; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Defines if the message needs a reply or not. |
|
105
|
|
|
* |
|
106
|
|
|
* @param bool $needsReply true for enable reply |
|
107
|
|
|
* |
|
108
|
|
|
* @return $this |
|
109
|
|
|
* |
|
110
|
|
|
* @see PromiseInterface |
|
111
|
|
|
*/ |
|
112
|
|
|
public function setNeedsReply(bool $needsReply = true): Message |
|
113
|
|
|
{ |
|
114
|
|
|
$this->needsReply = $needsReply; |
|
115
|
|
|
|
|
116
|
|
|
return $this; |
|
|
|
|
|
|
117
|
|
|
} |
|
118
|
|
|
|
|
119
|
|
|
/** |
|
120
|
|
|
* Check whether the message needs reply. |
|
121
|
|
|
*/ |
|
122
|
|
|
public function getNeedsReply(): bool |
|
123
|
|
|
{ |
|
124
|
|
|
return (bool) $this->needsReply; |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* Set the message driver options. |
|
129
|
|
|
* |
|
130
|
|
|
* @return $this |
|
131
|
|
|
*/ |
|
132
|
|
|
public function setHeaders(array $headers) |
|
133
|
|
|
{ |
|
134
|
|
|
$this->headers = $headers; |
|
135
|
|
|
|
|
136
|
|
|
return $this; |
|
137
|
|
|
} |
|
138
|
|
|
|
|
139
|
|
|
/** |
|
140
|
|
|
* Get all message headers. |
|
141
|
|
|
*/ |
|
142
|
|
|
public function getHeaders(): array |
|
143
|
|
|
{ |
|
144
|
|
|
return $this->headers; |
|
145
|
|
|
} |
|
146
|
|
|
|
|
147
|
|
|
/** |
|
148
|
|
|
* @return $this |
|
149
|
|
|
*/ |
|
150
|
|
|
public function setTopic(string $topic) |
|
151
|
|
|
{ |
|
152
|
|
|
$this->headers['topic'] = $topic; |
|
153
|
|
|
|
|
154
|
|
|
return $this; |
|
155
|
|
|
} |
|
156
|
|
|
|
|
157
|
|
|
/** |
|
158
|
|
|
* @return $this |
|
159
|
|
|
*/ |
|
160
|
|
|
public function setReplyTo(string $value) |
|
161
|
|
|
{ |
|
162
|
|
|
$this->headers['replyTo'] = $value; |
|
163
|
|
|
|
|
164
|
|
|
return $this; |
|
165
|
|
|
} |
|
166
|
|
|
|
|
167
|
|
|
/** |
|
168
|
|
|
* @return $this |
|
169
|
|
|
*/ |
|
170
|
|
|
public function setCorrelationId(string $value) |
|
171
|
|
|
{ |
|
172
|
|
|
$this->headers['correlationId'] = $value; |
|
173
|
|
|
|
|
174
|
|
|
return $this; |
|
175
|
|
|
} |
|
176
|
|
|
} |
|
177
|
|
|
|