[rabbitmq-discuss] Clarification needed on how to publish to topic exchange

George Haidar ghaidar0 at gmail.com
Fri Oct 9 13:10:00 BST 2009


Hi,
I have rabbitmq-server installed  - checked out from mercurial and
built along with all plugins at the time of writing. I created two
mock java application to test it out - one to publish, one to
subscribe. My program is based on the example listed on the rabbitmq
site under the java api guide. I setup a topic exchange ("report") and
a queue ("live") and bound the two together with the binding key
"report.live". Then I tried to publish message using the routing key
"report.*". `rabbitmqctl list_queue -p bfms` reports 0 messages in the
"live" queue. I was wondering if what I am trying to do is even
possible. If it is, what am I doing wrong?

Following is my code for the publisher:

package com.example;


import com.rabbitmq.client.*;
import com.rabbitmq.client.AMQP.Exchange;
import java.io.IOException;
import java.util.Calendar;
import java.util.logging.Level;
import java.util.logging.Logger;

public class RMQPublisher
{
    public static void main(String[] args)
    {
        ConnectionParameters connParams = new ConnectionParameters();
        connParams.setUsername("bfmsAdmin");
        connParams.setPassword("bfmsAdmin");
        connParams.setVirtualHost("bfms");
        connParams.setRequestedHeartbeat(0);
        try
        {
            System.out.println("Here");
            ConnectionFactory factory = new ConnectionFactory(connParams);
            Connection conn = factory.newConnection("xxxxxx");
            Channel channel = conn.createChannel();
            channel.exchangeDeclare("report", "topic", false, false,
false, null);
            channel.queueDeclare("live");
            channel.queueBind("live", "report", "report.live");
            System.out.println("Here");
            while (true)
            {
                Thread.sleep(1000);
                channel.basicPublish("report", "report.*", null,
("Hello World! "+
Calendar.getInstance().getTimeInMillis()).getBytes());
            }

        } catch (InterruptedException ex) {
            Logger.getLogger(RMQPublisher.class.getName()).log(Level.SEVERE,
null, ex);
        } catch (ShutdownSignalException sse)
        {
        } catch (IOException e)
        {
            System.out.println(e.getMessage());
            e.printStackTrace();
        }

    }

}

Regards




More information about the rabbitmq-discuss mailing list