dnup1092
dnup1092

Reputation: 375

RabbitMQ producer doesn't terminates

I have a producer which sends data to RabbitMQ(version 3.6.1). Previously I was using rabbitmq-client jar and the application was working fine.

Now I switched to spring-amqp 1.2.0 which is also successfully able to sends the data to RabbitMQ broker but the program never terminates. I have used following configuration @ Producer side.

<rabbit:connection-factory id="connectionFactory" host="localhost" port="5672" channel-cache-size="25" />

<rabbit:template id="amqpTemplate" connection-factory="connectionFactory"/>

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

<rabbit:queue name="text_offline_queue"/> 

I'm loading above configuration by using below code:

  public static int send(String message) {
      ClassPathXmlApplicationContext ctx = null;  
        try {
        ctx = new ClassPathXmlApplicationContext(
                "rabbitContext.xml");


      }catch (Exception ex){
          ex.printStackTrace();
          System.out.println(
                        "Error while open/read the rabbitmq context file");
      }

        AmqpTemplate template = ctx.getBean(AmqpTemplate.class);

        template.send(QUEUE_NAME, new Message(message.getBytes(), new MessageProperties()));

      return 1;
  }
}

And program never terminates(See attached image). See the red square in the console view of Eclipse-RabbitMQ version 3.6.1. Spring-AMQP-Version 1.2.0

Thanks in advance

Upvotes: 0

Views: 164

Answers (1)

Gary Russell
Gary Russell

Reputation: 174554

First, 1.2 is very old; the current version is 1.6.3.

The connection factory keeps a connection open for efficiency.

When you want to terminate your application, call ctx.close() and the application context will be shut down.

Upvotes: 1

Related Questions