简体   繁体   中英

why does my main method keeps running?

I´m doing a spring-integration + rabbitMQ application. From a main class I call a gateway that sends to a rabbitmq my message and it works perfectly but for some weird reason my main method keeps on running, at first I tought that I may have left a poller in my spring-context but that´s not the case. Here is my code:

public final class Main {

    private static final Logger LOGGER = Logger.getLogger(Main.class);

    @Autowired
    static
    ChatGateway chatGateway;

    private Main() { }

    /**
     * Load the Spring Integration Application Context
     *
     * @param args - command line arguments
     */
    public static void main(String args[]) {
        Mensaje mensaje = new Mensaje();
        mensaje.setClienteID("clienteXXX");

        ClassPathXmlApplicationContext ctx = new 
        ClassPathXmlApplicationContext("classpath:META-INF/spring/integration/spring-integration-context.xml");
        chatGateway = (ChatGateway) ctx.getBean("chatGateway");

        chatGateway.enviarAlarma(mensaje);

    }
}

and here is my spring context:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
    xmlns:int-amqp="http://www.springframework.org/schema/integration/amqp"
    xmlns:rabbit="http://www.springframework.org/schema/rabbit"
    xmlns:int-stream="http://www.springframework.org/schema/integration/stream"
    xsi:schemaLocation="http://www.springframework.org/schema/integration/amqp http://www.springframework.org/schema/integration/amqp/spring-integration-amqp.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
        http://www.springframework.org/schema/integration/stream http://www.springframework.org/schema/integration/stream/spring-integration-stream.xsd
        http://www.springframework.org/schema/rabbit http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">

    <!-- From STDIN To RabbitMQ 

    <int-stream:stdin-channel-adapter id="consoleIn"
        channel="toRabbit">
        <int:poller fixed-delay="1000" max-messages-per-poll="1" />
    </int-stream:stdin-channel-adapter>
    -->

    <int:channel id="toRabbit" />

    <int:gateway id="chatGateway"
        service-interface="com.praxis.chat.gateway.ChatGateway"
        default-request-channel="toRabbit" />

    <int-amqp:outbound-channel-adapter
        channel="toRabbit" amqp-template="amqpTemplate" exchange-name="si.test.exchange"
        routing-key="si.test.binding" />


    <!-- Infrastructure -->

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

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

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

    <rabbit:queue name="si.test.queue" />

    <rabbit:direct-exchange name="si.test.exchange">
        <rabbit:bindings>
            <rabbit:binding queue="si.test.queue" key="si.test.binding" />
        </rabbit:bindings>
    </rabbit:direct-exchange>

</beans>

Why does my main method keeps on running even after it sent the message?? Thanks in advance.

It will keep going, because it hasn't been told to end.

You could use:

System.exit(0);

or

return;

at the end of main(String[] args)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM