Page Menu
Home
DevCentral
Search
Configure Global Search
Log In
Files
F4793180
SendMessageToBroker.php
No One
Temporary
Actions
Download File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Award Token
Flag For Later
Size
2 KB
Referenced Files
None
Subscribers
None
SendMessageToBroker.php
View Options
<?php
namespace
Nasqueron\Notifications\Jobs
;
use
Illuminate\Contracts\Bus\SelfHandling
;
use
Nasqueron\Notifications\Actions\AMQPAction
;
use
Nasqueron\Notifications\Events\ReportEvent
;
use
Nasqueron\Notifications\Jobs\Job
;
use
Broker
;
use
Event
;
class
SendMessageToBroker
extends
Job
implements
SelfHandling
{
///
/// Private members
///
/**
* The routing key, for topic exchange
*
* @var string
*/
private
$routingKey
=
''
;
/**
* The message to send
*
* @var string
*/
private
$message
=
''
;
/**
* The target exchange
*
* @var string
*/
private
$target
=
''
;
/**
* If not null, an exception thrown during the task
*
* @var \Exception
*/
private
$exception
;
///
/// Constructor
///
/**
* Create a new job instance.
*
* @param string $routingKey the routing key, for topic exchange
* @param string $message the message to send
*
* @return void
*/
public
function
__construct
(
$target
,
$routingKey
,
$message
)
{
$this
->
target
=
$target
;
$this
->
routingKey
=
$routingKey
;
$this
->
message
=
$message
;
}
///
/// Task
///
/**
* Executes the job.
*
* @return void
*/
public
function
handle
()
{
$this
->
sendMessage
();
$this
->
report
();
}
/**
* Sends the message to the broker
*/
protected
function
sendMessage
()
{
try
{
Broker
::
setExchangeTarget
(
$this
->
target
)
->
routeTo
(
$this
->
routingKey
)
->
sendMessage
(
$this
->
message
);
}
catch
(
\Exception
$ex
)
{
$this
->
exception
=
$ex
;
}
}
/**
* Prepares a report and fires a report event
*/
protected
function
report
()
{
$actionToReport
=
new
AMQPAction
(
"publish"
,
$this
->
target
,
$this
->
routingKey
);
if
(
$this
->
exception
!==
null
)
{
$actionToReport
->
attachException
(
$this
->
exception
);
}
Event
::
fire
(
new
ReportEvent
(
$actionToReport
));
}
}
File Metadata
Details
Attached
Mime Type
text/x-php
Expires
Fri, Feb 28, 21:40 (1 d, 8 h)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
2436621
Default Alt Text
SendMessageToBroker.php (2 KB)
Attached To
Mode
rNOTIF Notifications center
Attached
Detach File
Event Timeline
Log In to Comment