Hello,
is there any way I can pause/resume a consumer?
Also can i get the number of current elements existing in a queue?
Thanks in advance.
Hello,
is there any way I can pause/resume a consumer?
Also can i get the number of current elements existing in a queue?
Thanks in advance.
This forum is for the Spring AMQP project, so I assume you are using that.
To pause/resume, call stop()/start() on the SimpleMessageListenerContainer.
You can get queue depths via the UI if the Rabbit management plugin is installed. I don't know if there is a way to do it programmatically - ask the rabbit guys on their list: https://lists.rabbitmq.com/cgi-bin/m...bbitmq-discuss
Gary P. Russell
Spring Integration Team
SpringSource, a division of VMware
Thanks Gary,
I have already tryed that, the issue I think is that I have tried to do stop()/start() upon request via a request on a Controller, the code is the following:
@Controller
@RequestMapping("/consumer")
public class Consumer extends SimpleMessageListenerContainer {
public void handle(Map requestMap) {
log.info("Received message " );
log.info("Map: "+requestMap.toString());
}
@RequestMapping("/stop")
public void stop(){
super.stop();
}
@RequestMapping("/start")
public void start(){
superstart();
}
}
The configuration is:
<bean id="consumer" class="package.Consumer" >
<property name="connectionFactory" ref="connectionFactory" />
<property name="queueNames" value="queue" />
</bean>
<rabbit:connection-factory id="connectionFactory" />
<rabbit:template connection-factory="connectionFactory" />
<rabbit:admin connection-factory="connectionFactory"/>
<rabbit:queue durable="true" name="queue" />
<rabbit:listener-container connection-factory="connectionFactory" >
<rabbit:listener method="handle" ref="consumer" queues="queue" />
</rabbit:listener-container>
What should be the way to invoke methods to stop/start the consumer? Can't it be a request to a controller?
Thanks in advance.
Seems a little odd to me (making the container a controller rather than just injecting the container into the controller to keep the concerns separate). But, I don't see why it shouldn't work. What happens (in the log) when you invoke stop/start? Turn on DEBUG logging.
Gary P. Russell
Spring Integration Team
SpringSource, a division of VMware
I have tried that way too...
@Controller
@RequestMapping("/consumer")
public class ConsumerController {
@Autowired Consumer consumer;
/**
* Logger.
*/
private static Logger log = Logger.getLogger(ConsumerController.class);
@RequestMapping("/stop")
public void stop(){
try{
consumer.stop();
}catch(RuntimeException e){
log.info("Exception: "+e);
}
log.info("parado!");
}
@RequestMapping("/start")
public void start(){
try{
consumer.start();
}catch(Exception e){
log.info("Exception: "+e);
}
}
}
public class Consumer extends SimpleMessageListenerContainer {
/**
* Logger.
*/
private static Logger log = Logger
.getLogger(Consumer.class);
public void handle(Map requestMap) {
log.info("Received message " );
log.info("Map: "+requestMap.toString());
}
}
The error we get is:
(AbstractMessageListenerContainer.java:invokeError Handler:428) - Execution of Rabbit message listener failed, and no ErrorHandler has been set: class org.springframework.amqp.rabbit.listener.ListenerE xecutionFailedException: Failed to invoke target method 'handle' with argument type = [class org.apache.catalina.util.ParameterMap], value = [{{opmnc=[Ljava.lang.String;@b039b55}}]
non stop...
So the error is nothing to do with the inability to start/stop, it is something more basic.
It's not clear to me what you are trying to do. Why are you extending SimpleMessageListenerContainer? Why not just use the vanilla SMLC and give it a MessageListener (or MessageListenerAdapter)?
Gary P. Russell
Spring Integration Team
SpringSource, a division of VMware