@@ -16,72 +16,83 @@ class QueueConfig
1616
1717 protected int $ queueMaxPriority = 2 ;
1818
19- protected ? string $ exchange = null ;
19+ protected string $ exchange = '' ;
2020
2121 protected string $ exchangeType = 'direct ' ;
2222
2323 protected string $ exchangeRoutingKey = '%s ' ;
2424
2525 protected bool $ rerouteFailed = false ;
2626
27- protected ? string $ failedExchange = null ;
27+ protected string $ failedExchange = '' ;
2828
2929 protected string $ failedRoutingKey = '%s.failed ' ;
3030
3131 protected bool $ quorum = false ;
3232
3333 protected array $ options = [];
3434
35+ /**
36+ * Holds the default queue name
37+ *
38+ * When no queue name is provided by laravel queue / workers via the QueueApi method's,
39+ * this value is used to publish messages.
40+ */
3541 public function getQueue (): string
3642 {
3743 return $ this ->queue ;
3844 }
3945
40- public function setQueue (? string $ queue ): QueueConfig
46+ public function setQueue (string $ queue ): QueueConfig
4147 {
42- $ this ->queue = $ queue ?: ' default ' ;
48+ $ this ->queue = $ queue ;
4349
4450 return $ this ;
4551 }
4652
53+ /**
54+ * Returns &true; as indication that jobs should be dispatched after all database transactions
55+ * have been committed.
56+ */
4757 public function isDispatchAfterCommit (): bool
4858 {
4959 return $ this ->dispatchAfterCommit ;
5060 }
5161
5262 public function setDispatchAfterCommit ($ dispatchAfterCommit ): QueueConfig
5363 {
54- $ this ->dispatchAfterCommit = ! empty ($ dispatchAfterCommit );
55-
56- return $ this ;
57- }
58-
59- public function getOptions (): array
60- {
61- return $ this ->options ;
62- }
63-
64- public function setOptions (?array $ options ): QueueConfig
65- {
66- $ this ->options = $ options ?: [];
64+ $ this ->dispatchAfterCommit = $ this ->toBoolean ($ dispatchAfterCommit );
6765
6866 return $ this ;
6967 }
7068
69+ /**
70+ * Get the Job::class to use when processing messages
71+ */
7172 public function getAbstractJob (): string
7273 {
7374 return $ this ->abstractJob ;
7475 }
7576
76- public function setAbstractJob (? string $ abstract ): QueueConfig
77+ public function setAbstractJob (string $ abstract ): QueueConfig
7778 {
78- $ this ->abstractJob = $ abstract ?: RabbitMQJob::class ;
79+ $ this ->abstractJob = $ abstract ;
7980
8081 return $ this ;
8182 }
8283
8384 /**
8485 * Returns &true;, if delayed messages should be prioritized.
86+ *
87+ * RabbitMQ queues work with the FIFO method. So when there are 10000 messages in the queue and
88+ * the delayed message is put back to the queue (at the end) for further processing the delayed message won´t
89+ * process before all 10000 messages are processed. The same is true for requeueing.
90+ *
91+ * This may not what you desire.
92+ * When you want the message to get processed immediately after the delayed time expires or when requeueing, we can
93+ * use prioritization.
94+ *
95+ * @see[https://www.rabbitmq.com/queues.html#basics]
8596 */
8697 public function isPrioritizeDelayed (): bool
8798 {
@@ -90,7 +101,7 @@ public function isPrioritizeDelayed(): bool
90101
91102 public function setPrioritizeDelayed ($ prioritizeDelayed ): QueueConfig
92103 {
93- $ this ->prioritizeDelayed = ! empty ($ prioritizeDelayed );
104+ $ this ->prioritizeDelayed = $ this -> toBoolean ($ prioritizeDelayed );
94105
95106 return $ this ;
96107 }
@@ -109,51 +120,67 @@ public function getQueueMaxPriority(): int
109120
110121 public function setQueueMaxPriority ($ queueMaxPriority ): QueueConfig
111122 {
112- if (is_numeric ($ queueMaxPriority )) {
123+ if (is_numeric ($ queueMaxPriority ) && intval ( $ queueMaxPriority ) > 1 ) {
113124 $ this ->queueMaxPriority = (int ) $ queueMaxPriority ;
114125 }
115126
116127 return $ this ;
117128 }
118129
119130 /**
120- * Get the exchange name, or &null; as default value.
131+ * Get the exchange name, or empty string; as default value.
132+ *
133+ * The default exchange is an unnamed pre-declared direct exchange. Usually, an empty string
134+ * is frequently used to indicate it. If you choose default exchange, your message will be delivered
135+ * to a queue with the same name as the routing key.
136+ * With a routing key that is the same as the queue name, every queue is immediately tied to the default exchange.
121137 */
122- public function getExchange (): ? string
138+ public function getExchange (): string
123139 {
124140 return $ this ->exchange ;
125141 }
126142
127- public function setExchange (? string $ exchange ): QueueConfig
143+ public function setExchange (string $ exchange ): QueueConfig
128144 {
129- $ this ->exchange = $ exchange ?: null ;
145+ $ this ->exchange = $ exchange ;
130146
131147 return $ this ;
132148 }
133149
150+ /**
151+ * Get the exchange type
152+ *
153+ * There are four basic RabbitMQ exchange types in RabbitMQ, each of which uses different parameters
154+ * and bindings to route messages in various ways, These are: 'direct', 'topic', 'fanout', 'headers'
155+ *
156+ * The default type is set as 'direct'
157+ */
134158 public function getExchangeType (): string
135159 {
136160 return $ this ->exchangeType ;
137161 }
138162
139- public function setExchangeType (? string $ exchangeType ): QueueConfig
163+ public function setExchangeType (string $ exchangeType ): QueueConfig
140164 {
141- $ this ->exchangeType = $ exchangeType ?: ' direct ' ;
165+ $ this ->exchangeType = $ exchangeType ;
142166
143167 return $ this ;
144168 }
145169
146170 /**
147- * @return string
171+ * Get the routing key when using an exchange other than the direct exchange.
172+ * The routing key is a message attribute taken into account by the exchange when deciding how to route a message.
173+ *
174+ * The default routing-key is the given destination: '%s'.
148175 */
149- public function getExchangeRoutingKey (): ? string
176+ public function getExchangeRoutingKey (): string
150177 {
151178 return $ this ->exchangeRoutingKey ;
152179 }
153180
154- public function setExchangeRoutingKey (? string $ exchangeRoutingKey ): QueueConfig
181+ public function setExchangeRoutingKey (string $ exchangeRoutingKey ): QueueConfig
155182 {
156- $ this ->exchangeRoutingKey = $ exchangeRoutingKey ?: ' %s ' ;
183+ $ this ->exchangeRoutingKey = $ exchangeRoutingKey ;
157184
158185 return $ this ;
159186 }
@@ -168,48 +195,84 @@ public function isRerouteFailed(): bool
168195
169196 public function setRerouteFailed ($ rerouteFailed ): QueueConfig
170197 {
171- $ this ->rerouteFailed = ! empty ($ rerouteFailed );
198+ $ this ->rerouteFailed = $ this -> toBoolean ($ rerouteFailed );
172199
173200 return $ this ;
174201 }
175202
176- public function getFailedExchange (): ?string
203+ /**
204+ * Get the exchange name with messages are published against.
205+ * The default exchange is empty, so messages will be published directly to a queue.
206+ */
207+ public function getFailedExchange (): string
177208 {
178209 return $ this ->failedExchange ;
179210 }
180211
181- public function setFailedExchange (? string $ failedExchange ): QueueConfig
212+ public function setFailedExchange (string $ failedExchange ): QueueConfig
182213 {
183- $ this ->failedExchange = $ failedExchange ?: null ;
214+ $ this ->failedExchange = $ failedExchange ;
184215
185216 return $ this ;
186217 }
187218
188219 /**
189- * Get the routing-key for failed messages
190- * The default routing-key is the given destination substituted by '.failed'.
220+ * Get the substitution string for failed messages
221+ * The default routing-key is the given destination substituted by '%s .failed'.
191222 */
192223 public function getFailedRoutingKey (): string
193224 {
194225 return $ this ->failedRoutingKey ;
195226 }
196227
197- public function setFailedRoutingKey (? string $ failedRoutingKey ): QueueConfig
228+ public function setFailedRoutingKey (string $ failedRoutingKey ): QueueConfig
198229 {
199- $ this ->failedRoutingKey = $ failedRoutingKey ?: ' %s.failed ' ;
230+ $ this ->failedRoutingKey = $ failedRoutingKey ;
200231
201232 return $ this ;
202233 }
203234
235+ /**
236+ * Returns &true;, if queue is marked or set as quorum queue.
237+ */
204238 public function isQuorum (): bool
205239 {
206240 return $ this ->quorum ;
207241 }
208242
209243 public function setQuorum ($ quorum ): QueueConfig
210244 {
211- $ this ->quorum = ! empty ($ quorum );
245+ $ this ->quorum = $ this ->toBoolean ($ quorum );
246+
247+ return $ this ;
248+ }
249+
250+ /**
251+ * Holds all unknown queue options provided in the connection config
252+ */
253+ public function getOptions (): array
254+ {
255+ return $ this ->options ;
256+ }
257+
258+ public function setOptions (array $ options ): QueueConfig
259+ {
260+ $ this ->options = $ options ;
212261
213262 return $ this ;
214263 }
264+
265+ /**
266+ * Filters $value to boolean value
267+ *
268+ * Returns: &true;
269+ * For values: 1, '1', true, 'true', 'yes'
270+ *
271+ * Returns: &false;
272+ * For values: 0, '0', false, 'false', '', null, [] , 'ok', 'no', 'no not a bool', 'yes a bool'
273+ */
274+ protected function toBoolean ($ value ): bool
275+ {
276+ return filter_var ($ value , FILTER_VALIDATE_BOOLEAN );
277+ }
215278}
0 commit comments