forked from bschmitt/laravel-amqp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
124 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
{ | ||
"name": "bschmitt/laravel-amqp", | ||
"name": "mammutgroup/laravel-amqp", | ||
"description": "AMQP wrapper for Laravel and Lumen to publish and consume messages", | ||
"keywords": [ | ||
"laravel", | ||
|
@@ -16,12 +16,16 @@ | |
"license": "MIT", | ||
"support": { | ||
"issues": "https://github.com/bschmitt/laravel-amqp/issues", | ||
"source": "https://github.com/bschmitt/laravel-amqp" | ||
"source": "https://github.com/mammutgroup/laravel-amqp" | ||
}, | ||
"authors": [ | ||
{ | ||
"name": "Björn Schmitt", | ||
"email": "[email protected]" | ||
}, | ||
{ | ||
"name": "MohammadReza Honarkhah", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,6 @@ | ||
<?php namespace Bschmitt\Amqp; | ||
|
||
use App; | ||
use Closure; | ||
use Bschmitt\Amqp\Request; | ||
use Bschmitt\Amqp\Message; | ||
|
||
/** | ||
* @author Björn Schmitt <[email protected]> | ||
|
@@ -13,39 +10,42 @@ class Amqp | |
|
||
/** | ||
* @param string $routing | ||
* @param mixed $message | ||
* @param array $properties | ||
* @param mixed $message | ||
* @param array $properties | ||
*/ | ||
public function publish($routing, $message, array $properties = []) | ||
{ | ||
$properties['routing'] = $routing; | ||
|
||
/* @var Publisher $publisher */ | ||
$publisher = App::make('Bschmitt\Amqp\Publisher'); | ||
$publisher = \App::make('Bschmitt\Amqp\Publisher'); | ||
$publisher | ||
->mergeProperties($properties) | ||
->setup(); | ||
|
||
$messageProperties = ['content_type' => 'text/plain', 'delivery_mode' => 2]; | ||
$messageProperties = array_merge($messageProperties, $publisher->getProperty('message_properties')); | ||
|
||
if (is_string($message)) { | ||
$message = new Message($message, ['content_type' => 'text/plain', 'delivery_mode' => 2]); | ||
$message = new Message($message, $messageProperties); | ||
} | ||
|
||
$publisher->publish($routing, $message); | ||
Request::shutdown($publisher->getChannel(), $publisher->getConnection()); | ||
} | ||
|
||
/** | ||
* @param string $queue | ||
* @param string $queue | ||
* @param Closure $callback | ||
* @param array $properties | ||
* @param array $properties | ||
* @throws Exception\Configuration | ||
*/ | ||
public function consume($queue, Closure $callback, $properties = []) | ||
{ | ||
$properties['queue'] = $queue; | ||
|
||
/* @var Consumer $consumer */ | ||
$consumer = App::make('Bschmitt\Amqp\Consumer'); | ||
$consumer = \App::make('Bschmitt\Amqp\Consumer'); | ||
$consumer | ||
->mergeProperties($properties) | ||
->setup(); | ||
|
@@ -54,9 +54,32 @@ public function consume($queue, Closure $callback, $properties = []) | |
Request::shutdown($consumer->getChannel(), $consumer->getConnection()); | ||
} | ||
|
||
public function declareExchange($exchange, $exchangeType) | ||
{ | ||
|
||
$properties['exchange'] = $exchange; | ||
$properties['exchange_type'] = $exchangeType; | ||
|
||
$request = \App::make('Bschmitt\Amqp\Request'); | ||
$request->mergeProperties($properties); | ||
$request->exchangeDeclare($exchange, $exchangeType); | ||
return $exchange; | ||
} | ||
|
||
public function declareQueue($queue, $exchange, $routingKey) | ||
{ | ||
$properties['queue'] = $queue; | ||
$properties['routing_key'] = $routingKey; | ||
|
||
$request = \App::make('Bschmitt\Amqp\Request'); | ||
$request->mergeProperties($properties); | ||
|
||
$request->queueDeclare($queue, $exchange, $routingKey); | ||
} | ||
|
||
/** | ||
* @param string $body | ||
* @param array $properties | ||
* @param array $properties | ||
* @return \Bschmitt\Amqp\Message | ||
*/ | ||
public function message($body, $properties = []) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
<?php namespace Bschmitt\Amqp; | ||
|
||
use Illuminate\Config\Repository; | ||
use PhpAmqpLib\Connection\AMQPStreamConnection; | ||
use Illuminate\Support\Arr; | ||
|
||
/** | ||
* @author Björn Schmitt <[email protected]> | ||
|
@@ -32,7 +32,7 @@ public function __construct(Repository $config) | |
protected function extractProperties(Repository $config) | ||
{ | ||
if ($config->has(self::REPOSITORY_KEY)) { | ||
$data = $config->get(self::REPOSITORY_KEY); | ||
$data = $config->get(self::REPOSITORY_KEY); | ||
$this->properties = $data['properties'][$data['use']]; | ||
} | ||
} | ||
|
@@ -59,9 +59,9 @@ public function getProperties() | |
* @param string $key | ||
* @return mixed | ||
*/ | ||
public function getProperty($key) | ||
public function getProperty($key,$default = null) | ||
{ | ||
return array_key_exists($key, $this->properties) ? $this->properties[$key] : NULL; | ||
return Arr::get($this->properties, $key, $default); | ||
} | ||
|
||
/** | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters