Created
May 22, 2010 15:04
-
-
Save yuxel/410132 to your computer and use it in GitHub Desktop.
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
<?php | |
/** | |
* Kullanici kayit olduktan sonra kuyruga kullanici id'sini | |
* mesaj gonderen uygulama | |
* | |
* http://code.google.com/p/php-amqplib/ adresinden PHP kutuphanesini indirmelisiniz | |
*/ | |
//indirdiginiz kutuphane icindeki dosyanin yolunu gosterin | |
require_once('../amqp.inc'); | |
class sendRegisterMessageToQueue { | |
// yapilandirma | |
function __construct() { | |
// rabbitmq ayarlari | |
$this->rabbitMQConf = array("host"=>"localhost", | |
"port"=>"5672", | |
"user"=>"guest", | |
"pass"=>"guest", | |
"virtualHost"=>"/"); | |
// kuyruk ayarlari | |
$this->queueConf = array("exchange"=>"kayit"); | |
} | |
// kullanici id'sini mesaj olarak gonder | |
function send($userId) { | |
try{ | |
// amqp'ye baglan | |
$conn = new AMQPConnection($this->rabbitMQConf['host'], | |
$this->rabbitMQConf['port'], | |
$this->rabbitMQConf['user'], | |
$this->rabbitMQConf['pass']); | |
$channel = $conn->channel(); | |
$channel->access_request($this->rabbitMQConf['virtualHost'], false, false, true, true); | |
// mesajı gönder | |
$msg = new AMQPMessage($userId, array('content_type' => 'text/plain')); | |
$channel->basic_publish($msg, $this->queueConf['exchange']); | |
$channel->close(); | |
$conn->close(); | |
return true; | |
} | |
catch(Exception $e) { | |
echo "Bir hata oluştu ".$e->getMessage(); | |
} | |
} | |
} | |
$messageSender = new sendRegisterMessageToQueue(); | |
$userId = 777; | |
if ( $messageSender->send($userId ) ) { | |
echo "Kullanicinin yakinindaki insanlara e-posta gonderme mesaji iletildi"; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment