g***@me.com
2015-06-11 23:01:52 UTC
This is the problem.
***@sis-mqueue11:/var/apache2/2.2/htdocs/amqp# php
amqp_publisher_with_confirms.php
PHP Catchable fatal error: Argument 1 passed to
PhpAmqpLib\Channel\AMQPChannel::set_ack_handler() must be an instance of
PhpAmqpLib\Channel\Callable, instance of Closure given, called in
/var/apache2/2.2/htdocs/amqp/amqp_publisher_with_confirms.php on line 17
and defined in
/var/apache2/2.2/htdocs/amqp/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php
on line 1045
PHP Stack trace:
PHP 1. {main}()
/var/apache2/2.2/htdocs/amqp/amqp_publisher_with_confirms.php:0
PHP 2. PhpAmqpLib\Channel\AMQPChannel->set_ack_handler()
/var/apache2/2.2/htdocs/amqp/amqp_publisher_with_confirms.php:17
***@sis-mqueue11:/var/apache2/2.2/htdocs/amqp# cat
amqp_publisher_with_confirms.php
<?php
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
include(__DIR__ . '/config.php');
$exchange = 'someExchange';
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();
$ch->set_ack_handler(
function (AMQPMessage $message) {
echo "Message acked with content " . $message->body . PHP_EOL;
}
);
$ch->set_nack_handler(
function (AMQPMessage $message) {
echo "Message nacked with content " . $message->body . PHP_EOL;
}
);
/*
* bring the channel into publish confirm mode.
* if you would call $ch->tx_select() befor or after you brought the
channel into this mode
* the next call to $ch->wait() would result in an exception as the publish
confirm mode and transactions
* are mutually exclusive
*/
$ch->confirm_select();
/*
name: $exchange
type: fanout
passive: false // don't check is an exchange with the same name exists
durable: false // the exchange won't survive server restarts
auto_delete: true //the exchange will be deleted once the channel is
closed.
*/
$ch->exchange_declare($exchange, 'fanout', false, false, true);
$i = 1;
$msg = new AMQPMessage($i, array('content_type' => 'text/plain'));
$ch->basic_publish($msg, $exchange);
/*
* watching the amqp debug output you can see that the server will ack the
message with delivery tag 1 and the
* multiple flag probably set to false
*/
$ch->wait_for_pending_acks();
while ($i <= 11) {
$msg = new AMQPMessage($i++, array('content_type' => 'text/plain'));
$ch->basic_publish($msg, $exchange);
}
/*
* you do not have to wait for pending acks after each message sent. in
fact it will be much more efficient
* to wait for as many messages to be acked as possible.
*/
$ch->wait_for_pending_acks();
$ch->close();
$conn->close();
***@sis-mqueue11:/var/apache2/2.2/htdocs/amqp#
***@sis-mqueue11:/var/apache2/2.2/htdocs/amqp# php
amqp_publisher_with_confirms.php
PHP Catchable fatal error: Argument 1 passed to
PhpAmqpLib\Channel\AMQPChannel::set_ack_handler() must be an instance of
PhpAmqpLib\Channel\Callable, instance of Closure given, called in
/var/apache2/2.2/htdocs/amqp/amqp_publisher_with_confirms.php on line 17
and defined in
/var/apache2/2.2/htdocs/amqp/vendor/videlalvaro/php-amqplib/PhpAmqpLib/Channel/AMQPChannel.php
on line 1045
PHP Stack trace:
PHP 1. {main}()
/var/apache2/2.2/htdocs/amqp/amqp_publisher_with_confirms.php:0
PHP 2. PhpAmqpLib\Channel\AMQPChannel->set_ack_handler()
/var/apache2/2.2/htdocs/amqp/amqp_publisher_with_confirms.php:17
***@sis-mqueue11:/var/apache2/2.2/htdocs/amqp# cat
amqp_publisher_with_confirms.php
<?php
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
include(__DIR__ . '/config.php');
$exchange = 'someExchange';
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();
$ch->set_ack_handler(
function (AMQPMessage $message) {
echo "Message acked with content " . $message->body . PHP_EOL;
}
);
$ch->set_nack_handler(
function (AMQPMessage $message) {
echo "Message nacked with content " . $message->body . PHP_EOL;
}
);
/*
* bring the channel into publish confirm mode.
* if you would call $ch->tx_select() befor or after you brought the
channel into this mode
* the next call to $ch->wait() would result in an exception as the publish
confirm mode and transactions
* are mutually exclusive
*/
$ch->confirm_select();
/*
name: $exchange
type: fanout
passive: false // don't check is an exchange with the same name exists
durable: false // the exchange won't survive server restarts
auto_delete: true //the exchange will be deleted once the channel is
closed.
*/
$ch->exchange_declare($exchange, 'fanout', false, false, true);
$i = 1;
$msg = new AMQPMessage($i, array('content_type' => 'text/plain'));
$ch->basic_publish($msg, $exchange);
/*
* watching the amqp debug output you can see that the server will ack the
message with delivery tag 1 and the
* multiple flag probably set to false
*/
$ch->wait_for_pending_acks();
while ($i <= 11) {
$msg = new AMQPMessage($i++, array('content_type' => 'text/plain'));
$ch->basic_publish($msg, $exchange);
}
/*
* you do not have to wait for pending acks after each message sent. in
fact it will be much more efficient
* to wait for as many messages to be acked as possible.
*/
$ch->wait_for_pending_acks();
$ch->close();
$conn->close();
***@sis-mqueue11:/var/apache2/2.2/htdocs/amqp#
--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-users+***@googlegroups.com.
To post to this group, send an email to rabbitmq-***@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.