Dave and Gary,
Thanks again. The news about durable bindings is very good. And Gary's suggestion re defining a TopicExchange rather than a mere Exchange did the trick.
So I am very close to getting this demo to work.
However, when I run the consumer (now a distinct Java application rather than a thread created by the AmqpDemo class), I am getting this error (actually, I am getting thousands of them):
Failed to invoke target method 'handleMessage' with argument type = [class org.springframework.amqp.core.Message], value = [{(Body:'This is a test, ...'; ID:null; Content:text/plain; Headers:{}; Exchange
bTopicExchange; RoutingKey:mgmt.clientID.1234; Reply:null; DeliveryMode:PERSISTENT; DeliveryTag:701)}
I think that ultimately (or originally) this error has something to do with the type of message I am sending. Rather, what each end thinks about the type of message. Here is the producing code:
Code:
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();
msgProperties.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);
Message msg = new Message(msgBody, msgProperties);
rabbitTemplate.send(exchangeName, "mgmt.clientID.1234", msg);
And here is how I set up for receiving messages in the consumer Java application:
Code:
Queue queue = new Queue(queueName, false, false, false);
TopicExchange topicExchange = new TopicExchange("pbTopicExchange", false, false); // non-durable, and no auto-delete
Binding b = BindingBuilder.bind(queue).to(topicExchange).with(bindingKey);
rabbitAdmin.declareBinding(b);
numberConcurrentConsumers = 1;
ConsumerSimpleMessageListenerContainer container = new ConsumerSimpleMessageListenerContainer();
container.setConnectionFactory(getConnectionFactory()); // connect to broker node
container.setQueueNames(queueName); // set name of Q whence receive messages
container.setConcurrentConsumers(numberConcurrentConsumers);
//container.setMessageListener(new MessageListenerAdapter(new ConsumerHandler(), new SimpleMessageConverter()));
container.setMessageListener(new MessageListenerAdapter(new ConsumerHandler(), null));
container.startConsumers();
Please note the commented out line that calls setMessageListener. I was experimenting with a SimpleMessageConverter and, in the next line, tried setting that converter to null. In each case I continue to get the error, but the phenomena varies some; specifically, the text of the error message is a bit different (if I recall correctly).
The ConsumerSimpleMessageListenerContainer is simply this:
Code:
public class ConsumerSimpleMessageListenerContainer extends SimpleMessageListenerContainer
{
public void startConsumers() throws Exception
{
super.doStart();
}
}
And the handler itself is simply this:
Code:
public class ConsumerHandler
{
public void handleMessage(String text) throws Exception
{
System.out.println("Received--------------------------: " + text);
}
}
Again, I suspect this is a simple mistake.
Can someone point out where my misunderstanding is?
Thanks.
-Paul