Skip to content

Instantly share code, notes, and snippets.

@kevinmlong
Created June 1, 2017 15:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kevinmlong/e9374d10d64dfe4c4cfe87afea4d5a40 to your computer and use it in GitHub Desktop.
Save kevinmlong/e9374d10d64dfe4c4cfe87afea4d5a40 to your computer and use it in GitHub Desktop.
Example Implementation for PHP Event Bus Using RabbitMQ
<?php
/**
* Example of PHP Script #1
*/
// Do some work...
// Need to send a message
// Create an instance of Postmaster
$postmaster = Postmaster::create();
// We need something to tell Postmaster to send - let's make a Letter
$letter = new Letter();
$letter->setMessage('This is an important message!');
// We need to tell the Postmaster to send the Letter for us
$postmaster->send($letter);
// Do some more work...
/**
* Example of PHP Script #2
* This is a very simple script that creates a LetterCarrier and then waits for messages.
* Messages received are processed by the carrier's receivedMessage method
*/
$letterCarrier = new LetterCarrier();
$letterCarrier->waitForMail();
/* In the console for PHP Script #2 we should see the output of receivedMessage:
* The message in the letter is: This is an important message!
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment