Skip to content

Instantly share code, notes, and snippets.

@1999
Created October 24, 2010 08:16
Show Gist options
  • Save 1999/643291 to your computer and use it in GitHub Desktop.
Save 1999/643291 to your computer and use it in GitHub Desktop.
<?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