Background service to receive messages from AMQP messagebroker RabbitMQ

Hey all.

Is it possible to create a background service within Cuba that listens to/receives messages from a message broker like RabbitMQ ? I have been able to install RabbitMQ and send messages out with it, but I would like some sort of running background service which listens to incoming messages, and sends them to the right service. I lack a bit of experience in java, so if someone can help me in the right direction, I would be grateful.

Thanks in advance!

Hi Jeroen,

i created an example which sends and receives messages from / to RabbitMQ. You can find the example here:

Basically it uses the Spring AMQP / Rabbit integration. If you have any question, don’t hesitate to ask.

Bye
Mario

1 Like

Hey Mario,

Thanks allot! I’ve ran into the spring integration guide, but it was hard to follow as a non-experienced Java developer. (So initially I installed RabbitMQ in Cuba directly). Your explanation was perfect, so I remain without questions :slight_smile:

I’ve read your blog a couple times as well, really good stuff (as far as I can follow) :wink: Specially the Lazy loading vs. eager fetching post with the Hobbits.

Anyway, thanks again!

Thanks, great you enjoyed it!

Bye

Hey Mario,

I’m starting with the implementation, and I’m running into a conversion issue. When I send a message to the queue in (via via rabbitMQ admin ui, and via an external console program), I get the following error:


org.springframework.amqp.rabbit.listener.exception.ListenerExecutionFailedException: Failed to invoke target method 'receive' with argument type = [class [B], value = [{[B@3c07ac73}]
........
Caused by: java.lang.NoSuchMethodException:  com.company.example.core.StatusUpdateReceiver.receive([B)

If I understand correctly, its seems that the default body it expects is a byte array. If I try to send the same messages to your project, I get the same errors. Perhaps within Spring, it defaults to a bytearray messages, but when I use another way of sending messages, it defaults to something else ?

It should be solvable by setting up a MessageConverter on the rabbitTemplate. But I’m a bit stuck how and if I should to implement it on the receiving end (in your case, in the BigOrderPresentCreator), of that it’s something I should add to the spring.xml configuration.

Any thoughts on this ?

Cheers!

Jeroen

Thanks for your provided answer,

I wonder, is it possible to create queues dynamically without specifying them in spring.xml?

If yes, how to do that?

Thanks in advance