Created
October 24, 2010 08:16
-
-
Save 1999/643291 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 | |
$cnn = new AMQPConnect(); | |
# подсоединяемся | |
$exch = new AMQPExchange( $cnn ); | |
$exch->declare( 'testing', 'direct', AMQP_DURABLE ); | |
if ( true === isset( $_GET['publish'] ) ) { | |
for ( $i=1; $i<=5; $i++ ) { | |
$message = 'this is message #' . $i . ' with random content: ' . mt_rand( 1, 10 ); | |
$exch->publish( $message, 'robot' ); | |
} | |
exit( 'messages published' ); | |
} | |
$queue = new AMQPQueue( $cnn ); | |
if ( user1 ) { | |
$messagesNum = $queue->declare( 'dima.queue', AMQP_DURABLE ); | |
$queue->bind( 'testing', 'robot' ); | |
$i = $messagesNum - 1; | |
while ( $i >= 0 ) { | |
$res = $queue->get(); | |
echo $res['msg'] . '<br>'; | |
$i--; | |
} | |
exit; | |
} | |
if ( user2 ) { | |
$messagesNum = $queue->declare( 'denya.queue', AMQP_DURABLE ); | |
$queue->bind( 'testing', 'robot' ); | |
$i = $messagesNum - 1; | |
while ( $i >= 0 ) { | |
$res = $queue->get(); | |
echo $res['msg'] . '<br>'; | |
$i--; | |
} | |
exit; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment