Hi All,
I'm fairly certain that I'm doing something simple - wrongly! I am also violating one of my cardinal rules about coding late into a Friday night.
In any event, I have this demo app that establishes a producer thread and a consumer thread.
The main thread init code creates a topic exchange and a queue like this:
The producer's run method looks like this:Code:ConnectionFactory connectionFactory = getConnectionFactory(); rabbitTemplate = new RabbitTemplate(connectionFactory); // create Spring's implementation of the AmqpTemplate interface rabbitAdmin = new RabbitAdmin(rabbitTemplate.getConnectionFactory()); // get a RabbitAdmin providing required connectionFactory ctor arg Exchange topicExchange = new TopicExchange("pbTopicExchange", false, false); // non-durable, and no auto-delete rabbitAdmin.declareExchange(topicExchange); Queue queue = new Queue("pbJobMgmtRqst", false, false, false); // non-durable, non-exclusive, no auto-delete rabbitAdmin.declareQueue(queue); // NB: the RabbitAdmin object links the exchange and the queue
After running this (let's forget about consumer thread for the moment), I see no evidence of any messages queued against queue "pbJobMgmtRqst." That is, the RabbitMQ admin plugin shows 0 Ready, 0 Unacknowledged, 0 Total.Code:public void run() { System.out.println("ENTERED PRODUCER THREAD"); ConnectionFactory connectionFactory = getConnectionFactory(); rabbitTemplate = new RabbitTemplate(connectionFactory); rabbitAdmin = new RabbitAdmin(rabbitTemplate.getConnectionFactory()); // get a RabbitAdmin providing required connectionFactory ctor arg Queue queue = new Queue("pbJobMgmtRqst", false, false, false); // non-durable, non-exclusive, no auto-delete rabbitAdmin.declareQueue(queue); // NB: the RabbitAdmin object links the exchange and the queue String strMsg = "This is a test..."; byte[] msgBody = null; try { msgBody = strMsg.getBytes("UTF-8"); } catch(Exception e) { System.out.println("CAUGHT EXCEPTION"); } MessageProperties msgProperties = new MessageProperties(); Message msg = new Message(msgBody, msgProperties); System.out.println("SENDING MSG to exchange " + exchangeName); for ( int n=0; n < 100; n++) { rabbitTemplate.send(exchangeName, "mgmt.clientID.1234", msg); } }
The consumer has not run.
The admin console also shows the following under Queues -> Bindings:
Incoming to pbJobMgmtRqst
From: (AMQP default)
Routing key: pbJobMgmtRqst
I found this odd because I thought that with statement
I had specified an Exchange name of "pbTopicExchange." This is set in the producer thread's constructor.Code:rabbitTemplate.send(exchangeName, "mgmt.clientID.1234", msg);
So before I get to the consumer issues (another post to this thread), some questions:
a. shouldn't I be seeing in the admin console some evidence of the 100 messages I sent ?
b. why does the admin console show "AMQP default" as the exchange?
On a side note: I am finding discrepancies between the online documentation at
http://static.springsource.org/sprin...1.0.x/apidocs/
and the Spring AMQP - Reference Documentation 1.0.0.RELEASE PDF. For example, the PDF shows
But the online docs give no instance of BindBuilder.bind returning a Binding. Instead, .bind returns something called a BindingBuilder.DestinationConfigurer. In fact, my Eclipse IDE changed my use of Binding to GenericArgumentsConfigurer.Code:Binding b = BindingBuilder.bind(someQueue).to(someTopicExchange).with("foo.*");
The consumer thread is the next issue but, again, I will save that for later.
I would be grateful for any help on this.
Thanks.
-Paul


Reply With Quote
