Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions .docker/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
FROM php:8.2-cli

# Install system dependencies
RUN apt-get update && apt-get install -y \
git \
zip \
unzip \
&& rm -rf /var/lib/apt/lists/*

# Install PHP extensions
RUN docker-php-ext-install sockets pcntl

# Install Composer
COPY --from=composer:latest /usr/bin/composer /usr/bin/composer

WORKDIR /app
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ composer.lock
phpunit.xml
.phpunit.result.cache
.php_cs.cache
.phpunit.cache
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ Only the latest version will get new features. Bug fixes will be provided using

| Package Version | Laravel Version | Bug Fixes Until | |
|-----------------|-----------------|------------------|---------------------------------------------------------------------------------------------|
| 13 | 9 | August 8th, 2023 | [Documentation](https://github.com/vyuldashev/laravel-queue-rabbitmq/blob/master/README.md) |
| 14 | 10, 11, 12 | August 8th, 2023 | [Documentation](https://github.com/vyuldashev/laravel-queue-rabbitmq/blob/master/README.md) |

## Installation

You can install this package via composer using this command:

```
composer require vladimir-yuldashev/laravel-queue-rabbitmq
composer require dejwcake/laravel-queue-rabbitmq
```

The package will automatically register itself.
Expand Down
8 changes: 7 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,17 @@
{
"name": "vladimir-yuldashev/laravel-queue-rabbitmq",
"name": "dejwcake/laravel-queue-rabbitmq",
"description": "RabbitMQ driver for Laravel Queue. Supports Laravel Horizon.",
"license": "MIT",
"authors": [
{
"name": "Vladimir Yuldashev",
"email": "misterio92@gmail.com"
},
{
"name": "David Běhal",
"email": "david.behal@dejw.sk",
"homepage": "https://www.dejw.sk",
"role": "Developer"
}
],
"require": {
Expand Down
21 changes: 15 additions & 6 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
version: '3.7'

services:

rabbitmq:
Expand All @@ -17,8 +15,6 @@ services:
- "./tests/files/rootCA.pem:/rootCA.pem:ro"
- "./tests/files/rootCA.key:/rootCA.key:ro"
ports:
- "15671:15671"
- "15672:15672"
- "5671:5671"
- "5672:5672"

Expand All @@ -39,5 +35,18 @@ services:
ports:
- 15671:15671
- 15672:15672
- 5671:5671
- 5672:5672

php:
build:
context: .
dockerfile: .docker/Dockerfile
environment:
HOST: rabbitmq
PORT: 5672
volumes:
- .:/app
working_dir: /app
tty: true
stdin_open: true
depends_on:
- rabbitmq
32 changes: 16 additions & 16 deletions src/Queue/RabbitMQQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,14 +62,14 @@ class RabbitMQQueue extends Queue implements QueueContract, RabbitMQQueueContrac
/**
* Holds the Configuration
*/
protected QueueConfig $config;
protected QueueConfig $rabbitMQConfig;

/**
* RabbitMQQueue constructor.
*/
public function __construct(QueueConfig $config)
{
$this->config = $config;
$this->rabbitMQConfig = $config;
$this->dispatchAfterCommit = $config->isDispatchAfterCommit();
}

Expand Down Expand Up @@ -293,7 +293,7 @@ public function setConnection(AbstractConnection $connection): RabbitMQQueue
*/
public function getJobClass(): string
{
$job = $this->getConfig()->getAbstractJob();
$job = $this->getRabbitMQConfig()->getAbstractJob();

throw_if(
! is_a($job, RabbitMQJob::class, true),
Expand All @@ -309,7 +309,7 @@ public function getJobClass(): string
*/
public function getQueue($queue = null): string
{
return $queue ?: $this->getConfig()->getQueue();
return $queue ?: $this->getRabbitMQConfig()->getQueue();
}

/**
Expand Down Expand Up @@ -523,7 +523,7 @@ protected function createMessage($payload, int $attempts = 0): array
$properties['correlation_id'] = $correlationId;
}

if ($this->getConfig()->isPrioritizeDelayed()) {
if ($this->getRabbitMQConfig()->isPrioritizeDelayed()) {
$properties['priority'] = $attempts;
}

Expand Down Expand Up @@ -605,16 +605,16 @@ protected function getQueueArguments(string $destination): array
// Messages with a priority which is higher than the queue's maximum, are treated as if they were
// published with the maximum priority.
// Quorum queues does not support priority.
if ($this->getConfig()->isPrioritizeDelayed() && ! $this->getConfig()->isQuorum()) {
$arguments['x-max-priority'] = $this->getConfig()->getQueueMaxPriority();
if ($this->getRabbitMQConfig()->isPrioritizeDelayed() && ! $this->getRabbitMQConfig()->isQuorum()) {
$arguments['x-max-priority'] = $this->getRabbitMQConfig()->getQueueMaxPriority();
}

if ($this->getConfig()->isRerouteFailed()) {
if ($this->getRabbitMQConfig()->isRerouteFailed()) {
$arguments['x-dead-letter-exchange'] = $this->getFailedExchange();
$arguments['x-dead-letter-routing-key'] = $this->getFailedRoutingKey($destination);
}

if ($this->getConfig()->isQuorum()) {
if ($this->getRabbitMQConfig()->isQuorum()) {
$arguments['x-queue-type'] = 'quorum';
}

Expand All @@ -639,7 +639,7 @@ protected function getDelayQueueArguments(string $destination, int $ttl): array
*/
protected function getExchange(?string $exchange = null): string
{
return $exchange ?? $this->getConfig()->getExchange();
return $exchange ?? $this->getRabbitMQConfig()->getExchange();
}

/**
Expand All @@ -648,15 +648,15 @@ protected function getExchange(?string $exchange = null): string
*/
protected function getRoutingKey(string $destination): string
{
return ltrim(sprintf($this->getConfig()->getExchangeRoutingKey(), $destination), '.');
return ltrim(sprintf($this->getRabbitMQConfig()->getExchangeRoutingKey(), $destination), '.');
}

/**
* Get the exchangeType, or AMQPExchangeType::DIRECT as default.
*/
protected function getExchangeType(?string $type = null): string
{
$constant = AMQPExchangeType::class.'::'.Str::upper($type ?: $this->getConfig()->getExchangeType());
$constant = AMQPExchangeType::class.'::'.Str::upper($type ?: $this->getRabbitMQConfig()->getExchangeType());

return defined($constant) ? constant($constant) : AMQPExchangeType::DIRECT;
}
Expand All @@ -666,7 +666,7 @@ protected function getExchangeType(?string $type = null): string
*/
protected function getFailedExchange(?string $exchange = null): string
{
return $exchange ?? $this->getConfig()->getFailedExchange();
return $exchange ?? $this->getRabbitMQConfig()->getFailedExchange();
}

/**
Expand All @@ -675,7 +675,7 @@ protected function getFailedExchange(?string $exchange = null): string
*/
protected function getFailedRoutingKey(string $destination): string
{
return ltrim(sprintf($this->getConfig()->getFailedRoutingKey(), $destination), '.');
return ltrim(sprintf($this->getRabbitMQConfig()->getFailedRoutingKey(), $destination), '.');
}

/**
Expand Down Expand Up @@ -735,9 +735,9 @@ protected function publishProperties($queue, array $options = []): array
return [$destination, $exchange, $exchangeType, $attempts];
}

protected function getConfig(): QueueConfig
protected function getRabbitMQConfig(): QueueConfig
{
return $this->config;
return $this->rabbitMQConfig;
}

/**
Expand Down
8 changes: 4 additions & 4 deletions tests/Feature/ConnectorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class ConnectorTest extends \VladimirYuldashev\LaravelQueueRabbitMQ\Tests\TestCase
{
public function test_lazy_connection(): void
public function testLazyConnection(): void
{
$this->app['config']->set('queue.connections.rabbitmq', [
'driver' => 'rabbitmq',
Expand Down Expand Up @@ -55,7 +55,7 @@ public function test_lazy_connection(): void
$this->assertTrue($connection->getConnection()->isConnected());
}

public function test_lazy_stream_connection(): void
public function testLazyStreamConnection(): void
{
$this->app['config']->set('queue.connections.rabbitmq', [
'driver' => 'rabbitmq',
Expand Down Expand Up @@ -98,7 +98,7 @@ public function test_lazy_stream_connection(): void
$this->assertTrue($connection->getConnection()->isConnected());
}

public function test_ssl_connection(): void
public function testSslConnection(): void
{
$this->markTestSkipped();

Expand Down Expand Up @@ -142,7 +142,7 @@ public function test_ssl_connection(): void
}

// Test to validate ssl connection params
public function test_no_verification_ssl_connection(): void
public function testNoVerificationSslConnection(): void
{
$this->app['config']->set('queue.connections.rabbitmq', [
'driver' => 'rabbitmq',
Expand Down
4 changes: 2 additions & 2 deletions tests/Feature/QueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ protected function setUp(): void
]);
}

public function test_connection(): void
public function testConnection(): void
{
$this->assertInstanceOf(AMQPStreamConnection::class, $this->connection()->getChannel()->getConnection());
}

public function test_without_reconnect(): void
public function testWithoutReconnect(): void
{
$queue = $this->connection('rabbitmq');

Expand Down
2 changes: 1 addition & 1 deletion tests/Feature/SslQueueTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected function getEnvironmentSetUp($app): void
]);
}

public function test_connection(): void
public function testConnection(): void
{
$this->assertInstanceOf(AMQPSSLConnection::class, $this->connection()->getChannel()->getConnection());
}
Expand Down
Loading
Loading