tags:

views:

497

answers:

1

I've installed the M4 release of the Apache Qpid Java broker on a Windows box, and started it using the out-of-the-box configuration (via the qpid-server.bat script).

I'm now trying to publish a message to a queue using the RabbitMQ C# client library (version 1.5.3, compiled for .NET 3.0); my code is:

public void PublishMessage(string message)
{
    ConnectionFactory factory = new ConnectionFactory();
    factory.Parameters.VirtualHost = "...";
    IProtocol protocol = Protocols.FromEnvironment();
    using (IConnection conn = factory.CreateConnection(protocol, "localhost", 5672))
    {
        using (IModel ch = conn.CreateModel())
        {
            string exchange = "...";
            string routingKey = "...";
            ch.BasicPublish(exchange, routingKey, null, Encoding.UTF8.GetBytes(message));
        }
    }
}

Basically, I'm unsure what values to use for factory.Parameters.VirtualHost and the strings exchange and routingKey. I've tried various combinations, but nothing seems to work - the closest I've got is seeing the following in the Qpid server log:

2009-03-19 17:11:04,248 WARN  [pool-1-thread-1] queue.IncomingMessage (IncomingMessage.java:198) - MESSAGE DISCARDED: No routes for message - Message[(HC:896033 ID:1 Ref:1)]: 1; ref count: 1

which looks as though the Qpid server is receiving the message, but doesn't know what to do with it.

Any advice on what configuration values I need in my client code (bearing in mind I'm using the default Qpid config in virtualhosts.xml) would be much appreciated. More general information on virtual hosts, exchanges, queues and routing keys, and how Qpid links them all together, would also be very useful.

Thank you in advance,

Alan

+5  A: 

Just for reference, I managed to get this working in the end. The code below sends a message to the queue test-queue in the test.direct exchange on the localhost virtual host (all part of the default Qpid broker configuration):

public void PublishMessage(string message)
{
    ConnectionFactory factory = new ConnectionFactory();
    factory.Parameters.VirtualHost = "/localhost";
    IProtocol protocol = Protocols.AMQP_0_8_QPID;
    using (IConnection conn = factory.CreateConnection(protocol, "localhost", 5672))
    {
        using (IModel ch = conn.CreateModel())
        {
            ch.ExchangeDeclare("test.direct", "direct");
            ch.QueueDeclare("test-queue");
            ch.QueueBind("test-queue", "test.direct", "TEST", false, null);
            ch.BasicPublish("test.direct", "TEST", null, Encoding.UTF8.GetBytes(message));
        }
    }
}
Alan Gairey