Skip to content

Commit

Permalink
test programs working
Browse files Browse the repository at this point in the history
  • Loading branch information
standaloneSA committed Apr 3, 2012
1 parent 913b217 commit c8499bd
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 16 deletions.
39 changes: 39 additions & 0 deletions receive-parallel.php
@@ -0,0 +1,39 @@
<?php
// config
$exchangeName = 'IRClog';
$queueName = "";

// connect
$connection = new AMQPConnection();
$connection->connect() or die ("Error connecting\n");


// setup our queue
$chan = new AMQPChannel($connection);
$chan->qos(0,5);
$q = new AMQPQueue($chan);
//$q->setName($queueName);
//$q->setFlags(AMQP_DURABLE);

$q->declare();

$q->bind($exchangeName, $queueName);


function consumeQueue($envelope, $queue) {
print "Processing message: " . $envelope->getBody() . "... ";
//sleep(rand(2,7));
sleep(1);
$queue->ack($envelope->getDeliveryTag());
print "completed.\n";
} // end function consumeQueue()



print "Waiting. Press ctrl-c to cancel\n";
$q->consume("consumeQueue");

$q->unbind($exchangeName, $queueName);
$connection->disconnect();

?>
23 changes: 13 additions & 10 deletions receive.php
@@ -1,27 +1,30 @@
<?php
// config
$exchangeName = 'new_topic1';
$routingKey = 'routing.key';
$queueName = 'myqueue';
$exchangeName = 'amq.fanout';
$queueName = "queue1";

// connect
$connection = new AMQPConnection();
$connection->connect() or die ("Error connecting\n");

$chan = new AMQPChannel($connection);

// setup our queue
$chan = new AMQPChannel($connection);
$q = new AMQPQueue($chan);
$q->setName = $queueName;
$q->setName($queueName);
$q->declare();

// Bind it on the exchange to routing.key
$q->bind($exchangeName, $routingKey);
$q->bind($exchangeName, $queueName);

// show the message
print_r($q->get());
$envelope = $q->get(AMQP_AUTOACK);
if ( ! $envelope ) {
print "It appears that the queue is empty\n";
} else {
print "We may have found something: \n";
print $envelope->getBody() . "\n";
}
$q->unbind($exchangeName, $queueName);

// disconnect
$connection->disconnect();

?>
19 changes: 13 additions & 6 deletions send.php
@@ -1,23 +1,30 @@
<?php

// config
$routingKey = 'routing.key';
$routingKey = 'IRCoutput';
$message = $argv[1];

// connect
$connection = new AMQPConnection();
$connection->connect();

$chan = new AMQPChannel($connection);
$ex = new AMQPExchange($chan);
$ex->setName('new_topic1');
if ( ! $ex->getType() ) {
$ex->setType('direct');
$ex->declare();
if ( $chan->isConnected() ) {
$ex = new AMQPExchange($chan);
} else {
print "Error connecting to channel\n";
exit;
}

$ex->setName("IRClog");
$ex->setType("fanout");
$ex->declare();


$chan->startTransaction();
//$ex->publish($message, $routingKey, AMQP_NOPARAM, array("delivery_mode", "2"));
$ex->publish($message, $routingKey);
$chan->commitTransaction();
print "Sent: " . $argv[1] . "\n";

?>

0 comments on commit c8499bd

Please sign in to comment.