[rabbitmq-discuss] Publish using PHP and consume using .NET
anate
ambatinr at hotmail.com
Thu Feb 20 20:13:53 GMT 2014
I am new RabbitMQ. I have simple publish to RabbitMQ using PHP and it works.
I can see there is a message in Queue. I am trying to consume the message
using C#. I am getting the following error message on this line of code.
What could be wrong? Please suggest.
channel.QueueDeclare("msgs", false, true, false, null);
The AMQP operation was interrupted: AMQP close-reason, initiated by Peer,
code=406, text="PRECONDITION_FAILED - parameters for queue 'msgs' in vhost
'/' not equivalent", classId=50, methodId=10, cause=
Here is my PHP code:(Publish)
-----------------------------
<?php
include(__DIR__ . '/config.php');
use PhpAmqpLib\Connection\AMQPConnection;
use PhpAmqpLib\Message\AMQPMessage;
$exchange = 'router';
$queue = 'msgs';
$conn = new AMQPConnection(HOST, PORT, USER, PASS, VHOST);
$ch = $conn->channel();
$ch->queue_declare($queue, false, true, false, false);
$ch->exchange_declare($exchange, 'direct', false, true, false);
$ch->queue_bind($queue, $exchange);
$msg_body = "Hello World";
$msg = new AMQPMessage($msg_body, array('content_type' => 'text/plain',
'delivery_mode' => 2));
$ch->basic_publish($msg, $exchange);
$ch->close();
$conn->close();
?>
.NET code
---------------------------------------------
var connectionFactory = new ConnectionFactory
{
HostName = "server-name",
Port = 5672,
UserName = "guest",
Password = "guest",
VirtualHost = "/"
};
using (IConnection connection =
connectionFactory.CreateConnection())
{
using (var channel = connection.CreateModel())
{
channel.QueueDeclare("msgs", false, true, false, null);
var consumer = new QueueingBasicConsumer(channel);
channel.BasicConsume("msgs", true, consumer);
while (true)
{
var ea =
(BasicDeliverEventArgs)consumer.Queue.Dequeue();
var body = ea.Body;
var message = Encoding.UTF8.GetString(body);
textBox1.Text = message;
}
}
}
--
View this message in context: http://rabbitmq.1065348.n5.nabble.com/Publish-using-PHP-and-consume-using-NET-tp33540.html
Sent from the RabbitMQ mailing list archive at Nabble.com.
More information about the rabbitmq-discuss
mailing list