Looking for an example of a multi-threadded consumer for Spring Boot

6,917 views
Skip to first unread message

Jim Archer

unread,
Nov 23, 2015, 6:39:44 PM11/23/15
to rabbitmq-users
Hi All...

I have a simple Sprint Boot app that consumes messages and writes them to Oracle. All it does is instantiate a Connectionfactory() , set its parameters, then it gets a connection, creates a channel and a queue. Then it instantiates DefaultConsumer with the channel.

It works fine, but its slow. I have three producers sending messages very rapidly, and they are piling up at the broker.  So it seems I need a consumer that can use multiple threads.

I think what I need to use is SimpleMessageListenerContainer but I have been Googling, but I'm having trouble finding an example. If I try to just write it, it's an unknown type. Its import org.springframework.amqp.rabbit.listener is also not found, even though I have the amqp-client in my POM. That makes me think I'm trying to use something from another package that's not compatible. 

So if someone could point me in the right direction I would appreciate it...

Michael Klishin

unread,
Nov 23, 2015, 6:51:17 PM11/23/15
to rabbitm...@googlegroups.com, Jim Archer
On 24 November 2015 at 02:39:48, Jim Archer (bostc...@gmail.com) wrote:
> So if someone could point me in the right direction I would appreciate
> it

I'm not sure if you use spring-amqp but if you do, take a look at http://stackoverflow.com/questions/23341811/how-is-concurrency-in-spring-amqp-listener-container-implemented.

If you use straight RabbitMQ Java client, you can either add more consumers to the same queue
or make your consumer's handleDelivery method offload it to a thread pool or similar.

RabbitMQ Java client isn't aware of Spring-specific things, of course. 
--
MK

Staff Software Engineer, Pivotal/RabbitMQ


Jim Archer

unread,
Nov 23, 2015, 7:30:06 PM11/23/15
to rabbitmq-users, bostc...@gmail.com
Thanks MK, I actually did see that question on StackOverflow, and it helped me get a little closer to understanding whats Java specific and whats Spring specific.  I don't have any XML config in my project, so that didn't help too much.

I have been reading here:


From what I understand, I can just use a few annotations and a single method, and the messages will magically get delivered to that method. And then I can set the number of concurrent clients. Seems pretty cool, and I'll bet it is once I figure out how to make it work :-)

Michael Klishin

unread,
Nov 23, 2015, 7:32:31 PM11/23/15
to rabbitm...@googlegroups.com, Jim Archer
On 24 November 2015 at 03:30:09, Jim Archer (bostc...@gmail.com) wrote:
> From what I understand, I can just use a few annotations and a
> single method, and the messages will magically get delivered
> to that method. And then I can set the number of concurrent clients.
> Seems pretty cool, and I'll bet it is once I figure out how to make
> it work :-)

Jim

Let me clarify: you do use spring-amqp, don't you?

I'm not a spring-amqp expert but someone from that team is on this list.
They strongly prefer having questions asked on Stack Overflow, tagged with `spring-amqp`,
though, so that's what I'd recommend if you indeed use spring-amqp. 

Jim Archer

unread,
Nov 23, 2015, 11:59:29 PM11/23/15
to rabbitmq-users, bostc...@gmail.com
I was not using it, but I'm thinking I should switch. I'll post on stackoverflow, thanks.

Gary Russell

unread,
Nov 24, 2015, 2:19:49 PM11/24/15
to rabbitm...@googlegroups.com, James Archer
The sample apps in the spring amqp reference [1] have examples of configuring a listener container in Java.

As has been said, Stack Overflow is the best place to reach us.


--
You received this message because you are subscribed to the Google Groups "rabbitmq-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rabbitmq-user...@googlegroups.com.
To post to this group, send email to rabbitm...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages