Skip to content

Commit c9e853e

Browse files
Merge pull request #50 from needle-project/feature/0.5.0
Feature/0.5.0
2 parents cec13ae + a395935 commit c9e853e

20 files changed

+348
-320
lines changed

.travis.yml

Lines changed: 0 additions & 7 deletions
This file was deleted.

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
# Release Notes for 0.5.x
2+
3+
### [0.5.0](https://github.com/needle-project/laravel-rabbitmq/compare/0.4.3...feature/0.5.0) - 2024-03 - *!NOT RELEASED*
4+
* Add automatically `delivery_mode` to 2 (persistent) for durable entities
5+
* Add additional arguments for entities in order to support `quorum` type
6+
* Add `ticket` argument
7+
* Add properties for AMQP Messages when publishing
8+
* Fixed `wait` for consumers to align with consumer timeout

README.md

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
[![Build Status](https://travis-ci.org/needle-project/process-transaction.svg?branch=master)](https://travis-ci.org/needle-project/process-transaction)
21
[![Scrutinizer Code Quality](https://scrutinizer-ci.com/g/needle-project/laravel-rabbitmq/badges/quality-score.png?b=master)](https://scrutinizer-ci.com/g/needle-project/laravel-rabbitmq/?branch=master)
32
[![Code Coverage](https://scrutinizer-ci.com/g/needle-project/laravel-rabbitmq/badges/coverage.png?b=master)](https://scrutinizer-ci.com/g/needle-project/laravel-rabbitmq/?branch=master)
43
[![Total Downloads](https://poser.pugx.org/needle-project/laravel-rabbitmq/downloads)](https://packagist.org/packages/needle-project/laravel-rabbitmq)
@@ -30,9 +29,16 @@ A simple rabbitmq library for laravel based on Publish–Subscribe pattern where
3029

3130
3.4. [Custom Message Processor](#34-custom-message-processor)
3231

33-
4. [Contribute](#4-contribute)
32+
4. [Examples](#4-examples)
33+
34+
5. [Contribute](#5-contribute)
35+
36+
5.1 [Local Development](#51-local-development)
37+
38+
5.2 [Required Help](#52-required-help)
39+
40+
6. [Special "Thank You"](#6-special-thank-you)
3441

35-
4.1 [Local Development](#41-local-development)
3642

3743
# 1. Install
3844
Run:
@@ -197,7 +203,7 @@ Defining a publishers:
197203
```
198204

199205
### 2.5. Consumers
200-
A consumer will alway get message from a queue.
206+
A consumer will always get message from a queue.
201207
Define a consumer:
202208
```php
203209
'consumers' => [
@@ -290,7 +296,7 @@ php artisan rabbitmq:publish aPublisherName MyMessage
290296
### 3.2. Consuming a message
291297
Consuming message should be done by running a command in deamon mode. While PHP is not intended to do that, you can use [supervisor](http://supervisord.org/index.html) for that.
292298

293-
The **flow** of the consummer is rather simple:
299+
The **flow** of the consumer is rather simple:
294300
CLI Consumers -> Get message -> Passes it to the `message_processor` key from configuration.
295301

296302
A message processor is a class that implements `NeedleProject\LaravelRabbitMq\Processor` interface. If you do no want to handle acknowledgement you can extend `\NeedleProject\LaravelRabbitMq\Processor\AbstractMessageProcessor` which require implementation of `processMessage(AMQPMessage $message): bool` method.
@@ -320,19 +326,19 @@ rabbitmq:publish | Publish one message using a consumer | `php artisan rabbitmq:
320326
rabbitmq:setup | Creates all queues and exchanges | `php artisan rabbitmq:setup` or `php artisan rabbitmq:setup --force`. **NOTE** When using force, all queues and exchanges will be deleted first and then re-created.
321327

322328
### 3.4. Custom Message Processor
323-
At the current moment there is the posibility to either implement the `MessageProcessorInterface` class or extend the `AbstractMessageProcessor`.
329+
At the current moment there is the possibility to either implement the `MessageProcessorInterface` class or extend the `AbstractMessageProcessor`.
324330

325331
When using the `AbstractMessageProcessor`, you will have access to extra API than can be used in your `processMessage()`:
326332
```php
327333
protected function ack(AMQPMessage $message);
328334
protected function nack(AMQPMessage $message, bool $redeliver = true);
329335
```
330336

331-
# 4. Contribute
332-
You are free to contribute by submiting pull request or reporting any issue in Github.
337+
# 5. Contribute
338+
You are free to contribute by submitting pull request or reporting any issue in Github.
333339
At the current stage of the project, no contribution procedure is defined.
334340

335-
## 4.1 Local Development
341+
## 5.1 Local Development
336342
Run composer install (with ignore-platform-reqs to avoid missing extensions):
337343
```bash
338344
docker run --rm -v $(pwd):/app jitesoft/phpunit:8.1 composer install --ignore-platform-req=ext-sockets
@@ -342,3 +348,12 @@ Run unit tests via Docker:
342348
```bash
343349
docker run --rm -v $(pwd):/app jitesoft/phpunit:8.1 phpunit --configuration phpunit.xml
344350
```
351+
352+
## 5.2. Required Help
353+
There are multiple topics for which the library needs help
354+
- CI Pipeline: There is a need for a configuration of *scrutinizer* (or any other tool) that can cover running tests for all supported PHP Versions and Laravel Framework versions
355+
- Documentation: Any improvement to easy the use of the library it's welcome
356+
- Examples: A section of examples that proves the library's different real-world scenario examples
357+
358+
## 6. Special "Thank you"
359+
Special "Thank you" goes out to the library [contributors](https://github.com/needle-project/laravel-rabbitmq/graphs/contributors).

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,12 @@
1414
"php-amqplib/php-amqplib": ">=2.7|3.*"
1515
},
1616
"require-dev": {
17-
"phpunit/phpunit": "9.*",
18-
"squizlabs/php_codesniffer": "2.*",
17+
"phpunit/phpunit": "9.*|10.*",
18+
"squizlabs/php_codesniffer": "3.7.*",
1919
"phpmd/phpmd" : "@stable",
20-
"laravel/framework" : "5.*|6.*|7.*|8.*"
20+
"laravel/framework": "7.*|8.*|9.*|10.*",
21+
"phpstan/phpstan": "^1.10",
22+
"phpcompatibility/php-compatibility": "^9.3"
2123
},
2224
"autoload": {
2325
"psr-4": {"NeedleProject\\LaravelRabbitMq\\": "src/"}
@@ -37,6 +39,7 @@
3739
"config": {
3840
"allow-plugins": {
3941
"kylekatarnls/update-helper": true
40-
}
42+
},
43+
"process-timeout": 1200
4144
}
4245
}

phpmd.xml

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?xml version="1.0"?>
2+
<ruleset name="Ruleset"
3+
xmlns="http://pmd.sf.net/ruleset/1.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://pmd.sf.net/ruleset/1.0.0
6+
http://pmd.sf.net/ruleset_xml_schema.xsd"
7+
xsi:noNamespaceSchemaLocation="
8+
http://pmd.sf.net/ruleset_xml_schema.xsd">
9+
<rule ref="rulesets/codesize.xml/CyclomaticComplexity">
10+
</rule>
11+
<rule ref="rulesets/codesize.xml/NPathComplexity">
12+
</rule>
13+
<rule ref="rulesets/codesize.xml/ExcessiveMethodLength">
14+
</rule>
15+
<rule ref="rulesets/codesize.xml/ExcessiveClassLength">
16+
</rule>
17+
<rule ref="rulesets/codesize.xml/ExcessiveParameterList">
18+
</rule>
19+
<rule ref="rulesets/design.xml/ExitExpression">
20+
</rule>
21+
<rule ref="rulesets/design.xml/EvalExpression">
22+
</rule>
23+
<rule ref="rulesets/design.xml/GotoStatement">
24+
</rule>
25+
<rule ref="rulesets/design.xml/DepthOfInheritance">
26+
</rule>
27+
<rule ref="rulesets/design.xml/DevelopmentCodeFragment">
28+
<properties>
29+
<property name="ignore-namespaces" value="true"/>
30+
<property name="unwanted-functions" value="var_dump,print_r,debug_zval_dump,debug_print_backtrace,dd,dump" description="Comma separated list of suspect function images." />
31+
</properties>
32+
</rule>
33+
<rule ref="rulesets/naming.xml/LongVariable">
34+
<properties>
35+
<property name="maximum" description="The variable length reporting threshold" value="30"/>
36+
</properties>
37+
</rule>
38+
<rule ref="rulesets/naming.xml/ConstructorWithNameAsEnclosingClass">
39+
</rule>
40+
<rule ref="rulesets/naming.xml/ConstantNamingConventions">
41+
</rule>
42+
<rule ref="rulesets/naming.xml/BooleanGetMethodName">
43+
</rule>
44+
<rule ref="rulesets/unusedcode.xml">
45+
</rule>
46+
</ruleset>

phpunit.xml

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd" colors="true" bootstrap="vendor/autoload.php">
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.4/phpunit.xsd" colors="true" bootstrap="vendor/autoload.php" cacheDirectory=".phpunit.cache">
33
<coverage>
4-
<include>
5-
<directory suffix=".php">src/</directory>
6-
</include>
74
<report>
85
<html outputDirectory="coverage" lowUpperBound="35"/>
96
</report>
@@ -17,4 +14,9 @@
1714
</testsuite>
1815
</testsuites>
1916
<logging/>
17+
<source>
18+
<include>
19+
<directory suffix=".php">src/</directory>
20+
</include>
21+
</source>
2022
</phpunit>

src/Builder/ContainerBuilder.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,9 @@ public function createContainer(array $config)
5353

5454
foreach ($config['consumers'] as $consumerAliasName => $consumerDetails) {
5555
$prefetchCount = $consumerDetails['prefetch_count'];
56-
$globalPrefetch = array_key_exists('global_prefetch', $consumerDetails) ? $consumerDetails['global_prefetch'] : true;
56+
$globalPrefetch = array_key_exists('global_prefetch', $consumerDetails)
57+
? $consumerDetails['global_prefetch']
58+
: true;
5759
$messageProcessor = $consumerDetails['message_processor'];
5860

5961
if ($queues->has($consumerDetails['queue'])) {

src/Command/BasePublisherCommand.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,5 +66,6 @@ public function handle()
6666
{
6767
$this->getPublisher($this->input->getArgument('publisher'))
6868
->publish($this->input->getArgument('message'));
69+
return 0;
6970
}
70-
}
71+
}

src/ConfigHelper.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,8 +79,7 @@ private function addAttributesOnEntities(array $entityConfig): array
7979
*/
8080
private function addPrefetchOnConsumers(array $consumers): array
8181
{
82-
foreach ($consumers as $consumerAliasName => $consumerDefinition)
83-
{
82+
foreach ($consumers as $consumerAliasName => $consumerDefinition) {
8483
if (!isset($consumerDefinition['prefetch_count'])) {
8584
$consumerDefinition['prefetch_count'] = 1;
8685
}

src/Entity/ExchangeEntity.php

Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
22
namespace NeedleProject\LaravelRabbitMq\Entity;
33

44
use NeedleProject\LaravelRabbitMq\AMQPConnection;
5+
use NeedleProject\LaravelRabbitMq\Interpreter\EntityArgumentsInterpreter;
56
use NeedleProject\LaravelRabbitMq\PublisherInterface;
67
use PhpAmqpLib\Channel\AMQPChannel;
78
use PhpAmqpLib\Exception\AMQPChannelClosedException;
89
use PhpAmqpLib\Exception\AMQPProtocolChannelException;
910
use PhpAmqpLib\Message\AMQPMessage;
11+
use PhpAmqpLib\Wire\AMQPTable;
1012

1113
/**
1214
* Class ExchangeEntity
@@ -17,7 +19,7 @@
1719
class ExchangeEntity implements PublisherInterface, AMQPEntityInterface
1820
{
1921
/**
20-
* @const int Retry count when a Channel Closed exeption is thrown
22+
* @const int Retry count when a Channel Closed exception is thrown
2123
*/
2224
const MAX_RETRIES = 3;
2325

@@ -36,6 +38,8 @@ class ExchangeEntity implements PublisherInterface, AMQPEntityInterface
3638
'internal' => false,
3739
// Whether to receive a Declare confirmation
3840
'nowait' => false,
41+
// Additional arguments for queue creation
42+
'arguments' => [],
3943
// Whether to auto create the entity before publishing/consuming it
4044
'auto_create' => false,
4145
// whether to "hide" the exception on re-declare.
@@ -44,6 +48,8 @@ class ExchangeEntity implements PublisherInterface, AMQPEntityInterface
4448
// whether to throw on exception when trying to
4549
// bind to an in-existent queue/exchange
4650
'throw_exception_on_bind_fail' => true,
51+
// no ideea what it represents - @todo - find a documentation that states it's role
52+
'ticket' => null
4753
];
4854

4955
/**
@@ -62,7 +68,7 @@ class ExchangeEntity implements PublisherInterface, AMQPEntityInterface
6268
protected $attributes;
6369

6470
/**
65-
* @var int
71+
* @var int
6672
*/
6773
protected $retryCount = 0;
6874

@@ -133,7 +139,11 @@ public function create()
133139
$this->attributes['durable'],
134140
$this->attributes['auto_delete'],
135141
$this->attributes['internal'],
136-
$this->attributes['nowait']
142+
$this->attributes['nowait'],
143+
EntityArgumentsInterpreter::interpretArguments(
144+
$this->attributes['arguments']
145+
),
146+
$this->attributes['ticket']
137147
);
138148
} catch (AMQPProtocolChannelException $e) {
139149
// 406 is a soft error triggered for precondition failure (when redeclaring with different parameters)
@@ -162,7 +172,7 @@ public function bind()
162172
$bindItem['routing_key']
163173
);
164174
} catch (AMQPProtocolChannelException $e) {
165-
// 404 is the code for trying to bind to an non-existing entity
175+
// 404 is the code for trying to bind to a non-existing entity
166176
if (true === $this->attributes['throw_exception_on_bind_fail'] || $e->amqp_reply_code !== 404) {
167177
throw $e;
168178
}
@@ -192,18 +202,25 @@ public function reconnect()
192202
*
193203
* @param string $message
194204
* @param string $routingKey
205+
* @param array $properties
195206
* @return mixed|void
196207
* @throws AMQPProtocolChannelException
197208
*/
198-
public function publish(string $message, string $routingKey = '')
209+
public function publish(string $message, string $routingKey = '', array $properties = [])
199210
{
200211
try {
201212
if ($this->attributes['auto_create'] === true) {
202213
$this->create();
203214
$this->bind();
204215
}
205216
$this->getChannel()->basic_publish(
206-
new AMQPMessage($message),
217+
new AMQPMessage(
218+
$message,
219+
EntityArgumentsInterpreter::interpretProperties(
220+
$this->attributes,
221+
$properties
222+
)
223+
),
207224
$this->attributes['name'],
208225
$routingKey,
209226
true

0 commit comments

Comments
 (0)