[rabbitmq-discuss] Publish using PHP and consume using .NET
Alvaro Videla
videlalvaro at gmail.com
Thu Feb 20 21:33:30 GMT 2014
Hi,
In PHP you are declaring a durable queue, that's what the third
parameter to queue_declare being "true" means.
In .Net you declare a non durable queue, that is, your second
parameter is false. The .Net API is here:
http://www.rabbitmq.com/releases/rabbitmq-dotnet-client/v3.2.3/rabbitmq-dotnet-client-3.2.3-client-htmldoc/html/type-RabbitMQ.Client.IModel.html
Whenever you re-declare an existent resource, you need to use the same
arguments as the ones used the first time the resource was declared.
Regards,
Alvaro
On Thu, Feb 20, 2014 at 9:13 PM, anate <ambatinr at hotmail.com> wrote:
> 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.
> _______________________________________________
> rabbitmq-discuss mailing list
> rabbitmq-discuss at lists.rabbitmq.com
> https://lists.rabbitmq.com/cgi-bin/mailman/listinfo/rabbitmq-discuss
More information about the rabbitmq-discuss
mailing list