Announcement Announcement Module
Collapse
No announcement yet.
Use AMQP without Spring Framework core libraries. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Use AMQP without Spring Framework core libraries.

    Hi,

    I am a newbee here.
    I started playing around with samples.

    We are not using Spring Framework in my project. We have a need to work w
    I would like to know if there is an easier way to use Spring AMQP without taking rest of the libraries.

    Thanks and appreciate for any help in advance.


    Jiggy.

  • #2
    You lose a lot of things when not using spring completely if it will even work at all without an ApplicationContext.

    For instance, Queues, Exchanges, and Bindings will not be redeclared automatically on reconnect unless they are beans.

    I believe that Akka has a java API which supposedly has spring and guice integration if desired. We are using this library for one of our components.

    Comment


    • #3
      Spring AMQP can be used as "just an API" rather than relying on the ApplicationContext. All you lose is the functionality that *can* be done automatically when there is a context in place to manage references to all the beans and their lifecycle events.

      The AmqpAdmin interface (and RabbitAdmin implementation of that) offers all of the methods to declare Queues, Exchanges, and Bindings. You can add a ConnectionListener to the ConnectionFactory directly, and then assuming you have references to your own Queues and Exchanges (e.g. in a Map), you can declare them through the API upon each connection being established. If you look within the RabbitAdmin, you'll see that's what it's doing within its own initialization method (afterPropertiesSet).

      That said, @jmalkin, can you explain a bit more about why you want to avoid the core libraries? Is it just that you aren't planning to use Spring for dependency management, or something else?

      Comment


      • #4
        Thanks for the information.

        We are using Google GUICE as our DI Framework. So I would like to use only few libraries that I need. So my choices will come down to either write code to rabbitmq API or use Spring AMQP.

        Pulling more spring libraries then I need will push me towards writing code to rabbitmq API .

        I tried creating a sample project only using AMQP, Rabbit, and AMQP client libraries. I found they have dependency on spring core and maven would pull spring core and other spring libraries.

        I tried adding exclusions in pom. So I got the right libraries and was hoping to manually configure manually but now I get compilation errors suggesting I am indirectly using spring core libraries through spring AMQP/Babbit API.

        Multiple markers at this line
        - The type org.springframework.context.ApplicationContextAwar e cannot be resolved. It is indirectly
        referenced from required .class files
        - The type org.springframework.beans.factory.InitializingBean cannot be resolved. It is indirectly
        referenced from required .class files
        - The type org.springframework.beans.factory.DisposableBean cannot be resolved. It is indirectly
        referenced from required .class files

        Code:
        import org.springframework.amqp.core.AmqpAdmin;
        import org.springframework.amqp.core.AmqpTemplate;
        import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
        import org.springframework.amqp.rabbit.connection.ConnectionFactory;
        import org.springframework.amqp.rabbit.core.RabbitAdmin;
        import org.springframework.amqp.rabbit.core.RabbitTemplate;
        
        public class Consumer {
        	
        	public static void main(String[] args) {
        	    ConnectionFactory connectionFactory = new CachingConnectionFactory();
        
        	    AmqpAdmin admin = new RabbitAdmin(connectionFactory);
        	    admin.declareQueue("myqueue");
        
        	    AmqpTemplate template = new RabbitTemplate(connectionFactory);
        	    template.convertAndSend("myqueue", "foo");
        
        	    String foo = template.receiveAndConvert("myqueue");
                    System.out.println("Received: " + amqpTemplate.receiveAndConvert());
        	}
        }

        Comment


        • #5
          The Spring AMQP libraries do have transitive dependencies on Spring Framework libraries. The 3 interfaces that you listed above are all related to lifecycle-management. Several classes implement those interfaces for convenience when using Spring as the DI container.

          Why are you concerned about the transitive dependency if you aren't directly depending on the codebase yourself?

          Comment


          • #6
            It is way too many jars to pull in to implement simple message producer/consumer.
            Is there a way to only use 3 jars I needed for this.
            Was there a reason to make to make AMQP API depend on spring core and other libraries?
            Wasn't one of the Spring framework API concept was to make it modular so as a developer I can decide what I want?

            I haven't been working on Spring for a bit, so apologies for ignorant questions.

            Comment


            • #7
              Well, its kind of a political argument if you wish. . .

              Think of it this way.
              Spring is mostly perceived to be an application framework to be used by the end users building business applications. However Spring also provides great tools and API for framework development. In other words Spring-AMQP could have been built without any dependency on Spring, but this would mean we would have to repeat/duplicate (e.g., Lifecycle management, utility libraries etc.)
              Its the same argument people often use when choosing "to-framework-or-not-to-framework". Should I use framework or should I go against the raw API (as you suggested earlier). Of course the choice is yours, but realize one thing that although right now you are thinking in terms of a simple producer/consumer model and using frameworks seems like an overkill, you most certainly will realize later as you requirements move forward that you need other functionalities and hooks (the typical boilerplate code) which you will end up writing yourself. The sad part is that in the end you'll end up responsible for writing and maintaining all this code when you could have been working on something more interesting if you would only delegate the boilerplate to the framework.

              Hope that helps

              Comment


              • #8
                Hi Oleg,

                Thanks for the reply. I have noting against Spring or any such open source frameworks. I have used Spring in the past and have seen all the benefits.

                From my prospective argument is not political. I just want to use sub set of functionality but seems like you guys have made a choice either not to allow or make it difficult. It is like I want a bottle of soda but you want to give me entire fridge with soda.

                I strongly believe in agile methodologies and as such don't like to over engineer a solution until I see the real need. For now I would provide my app level abstraction and provide a simple implementation against the raw api. So in future I could swap out implementation easily.

                Comment

                Working...
                X