Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring integration pubsub vs Spring amqp RabbitMQ pubsub

I am working on a MicroBlog spring mvc hibernate application. I need to implement a publish subscribe functionality like twitter.

I am using RabbitMQ for messaging with Spring AMQP abstraction.

Everywhere I see on web the pubsub examples are given involving

Spring Integration

Spring AMQP & RabbitMQ

I researched a little more on Spring-Integration & found that a publish subscribe can be implemented with it even without using RabbitMQ.

Now my question is

Why do I need to use Spring Integration with [Spring AMQP & RabbitMQ] to implement a pubsub functionality. Why can't I just use Spring AMQP with Rabbit to do that?

Does Spring integration provide any additional features?

My Spring AMQP & RabbitMQ configuration

<rabbit:connection-factory id="connectionFactory" virtual-host="/" host="localhost" 
username="guest" password="guest"/>

<rabbit:admin connection-factory="connectionFactory" />

<rabbit:queue name="UserPostpublishQueue" />

<fanout-exchange name="broadcastUserPosts" xmlns="http://www.springframework.org/schema/rabbit">
    <bindings>
        <binding queue="UserPostpublishQueue"/>
    </bindings>
</fanout-exchange>

<rabbit:template id="amqpTemplate" connection-factory="connectionFactory" exchange="broadcastUserPosts" 
queue="UserPostpublishQueue"/>

</beans>

Test code in my controller

@Autowire
private AmqpTemplate amqpTemplate;

try{
        amqpTemplate.convertAndSend(post);
        Post receivedPost = (Post)amqpTemplate.receiveAndConvert();
        System.out.println("received Post "+receivedPost);
        }catch(AmqpException e){
            //deal with exception
        }
like image 937
underdog Avatar asked Sep 26 '15 10:09

underdog


People also ask

What is spring AMQP?

The Spring AMQP project applies core Spring concepts to the development of AMQP-based messaging solutions. It provides a "template" as a high-level abstraction for sending and receiving messages. It also provides support for Message-driven POJOs with a "listener container".

How does RabbitMQ connect to spring boot?

Run the Application There is a Runner bean, which is then automatically run. It retrieves the RabbitTemplate from the application context and sends a Hello from RabbitMQ! message on the spring-boot queue. Finally, it closes the Spring application context, and the application ends.

How do you use Spring Integration?

Spring Integration provides JDBC channel adapters that connect a channel to a database. In the case of the inbound adapter, a database is the source on which an SQL query can be run and the complete result set is available as a message with a Java List payload.

What is RabbitTemplate?

RabbitTemplate() Convenient constructor for use with setter injection. RabbitTemplate​(ConnectionFactory connectionFactory) Create a rabbit template with default strategies and settings.


1 Answers

Spring Integration implements the patterns from http://www.enterpriseintegrationpatterns.com/books1.html while using AMQP/RabbitMQ as one of its many transports.

I understand that spring-amqp is more the AMQP client functionality. If you don't want to use spring. Then we have a plain java client: https://www.rabbitmq.com/java-client.html

like image 79
old_sound Avatar answered Sep 28 '22 19:09

old_sound