Note that there are some explanatory texts on larger screens.

plurals
  1. POUse of Spring Framework for RabbitMQ is reducing the performance
    text
    copied!<p>I have created a producer, which was using <code>com.rabbitmq.client.connectionFactory</code> and was sending 1,000,000 messages (40 Bytes) in 100 seconds. </p> <p>But now I want an spring abstraction. I was unable to use <code>com.rabbitmq.client.connectionFactory</code> rather I had to use <code>org.springframework.amqp.rabbit.connection.SingleConnectionFactory</code>. Using this connection factory only 100,000 messages (40 Bytes) are send to the broker in 100 seconds.</p> <p>Does anybody have experience why the performance is reduced so much (around 90%).</p> <p>The code using "import com.rabbitmq.client.ConnectionFactory;" is -></p> <pre><code>package Multiple_queues_multiple_consumers; import java.io.IOException; import com.rabbitmq.client.AMQP; import com.rabbitmq.client.Channel; import com.rabbitmq.client.Connection; import com.rabbitmq.client.ConnectionFactory; public class Producer { private static Connection myConnection; private static Channel myChannel; public static String myQueueName; public static void main(String[] args) throws IOException { long startTime=0; int count=0; ConnectionFactory myFactory=new ConnectionFactory(); myFactory.setHost("localhost"); try { myConnection = myFactory.newConnection(); myChannel = myConnection.createChannel(); String myExchange = "wxyzabc"; String myBody = "This is a message : message numberxxxxxx"; String myRoutingKey = "RoutingKey"; myQueueName = "new_Queue"; myChannel.exchangeDeclare(myExchange, "direct", true, false, null); myChannel.queueDeclare(myQueueName, true, false, false, null); myChannel.queueBind(myQueueName, myExchange, myRoutingKey); startTime=System.currentTimeMillis(); AMQP.BasicProperties properties = new AMQP.BasicProperties(); properties.setDeliveryMode(2); startTime=System.currentTimeMillis(); while(count++&lt;=10000){ myChannel.basicPublish(myExchange, myRoutingKey, true, true, properties, myBody.getBytes() ); } System.out.println(System.currentTimeMillis()-startTime); } catch (Exception e){ System.exit(0); } } } </code></pre> <p>The code using SpringFramework is :-></p> <p>Producer1.java</p> <pre><code>import org.springframework.amqp.core.AmqpAdmin; import org.springframework.amqp.core.Binding; import org.springframework.amqp.core.DirectExchange; import org.springframework.amqp.core.Message; import org.springframework.amqp.core.Queue; import org.springframework.amqp.rabbit.core.RabbitAdmin; import org.springframework.amqp.rabbit.core.RabbitTemplate; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; public class Producer1 { public static void main(String[] args) { ConfigurableApplicationContext context = new ClassPathXmlApplicationContext("Producer1.xml"); AmqpAdmin amqpAdmin = context.getBean(RabbitAdmin.class); Queue queue = new Queue("sampleQueue"); DirectExchange exchange = new DirectExchange("myExchange"); Binding binding = new Binding(queue, exchange, ""); amqpAdmin.declareQueue(queue); amqpAdmin.declareExchange(exchange); amqpAdmin.declareBinding(binding); RabbitTemplate rabbitTemplate = context.getBean(RabbitTemplate.class); String routingKey = ""; String myBody = "This is a message : message numberxxxxxx"; Message Msg = new Message(myBody.getBytes(), null); int count=0; long CurrTime = System.currentTimeMillis(); while(count++&lt;=10000){ rabbitTemplate.send(routingKey, Msg); //System.out.println("Message Sent"); } System.out.println(System.currentTimeMillis()-CurrTime); } } </code></pre> <p>Producer1.xml</p> <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt; &lt;beans xmlns="http://www.springframework.org/schema/beans" xmlns:p="http://www.springframework.org/schema/p" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"&gt; &lt;!-- Define a connectionFactory --&gt; &lt;bean id="rabbitConnectionFactory" class="com.rabbitmq.client.ConnectionFactory"&gt; &lt;property name="host" value="localhost" /&gt; &lt;/bean&gt; &lt;bean id="connectionFactory" class="org.springframework.amqp.rabbit.connection.SingleConnectionFactory"&gt; &lt;constructor-arg ref="rabbitConnectionFactory"/&gt; &lt;/bean&gt; &lt;!-- Tell the Admin bean about that connectionFactory and initialize it, create a queue and an exchange on Rabbit Broker using the RabbitTemplate provided by Spring framework-Rabbit APIs --&gt; &lt;bean id="Admin" class="org.springframework.amqp.rabbit.core.RabbitAdmin"&gt; &lt;constructor-arg ref="connectionFactory" /&gt; &lt;/bean&gt; &lt;bean id="rabbitTemplate" class="org.springframework.amqp.rabbit.core.RabbitTemplate" p:connectionFactory-ref="connectionFactory" p:routingKey="myRoutingKey" p:exchange="myExchange" /&gt; &lt;/beans&gt; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload