2013-07-01 2 views
0

저는 스프링 통합 + rabbitMQ 응용을하고 있습니다. 메인 클래스에서 나는 내 메시지를 rabbitmq에게 보내는 게이트웨이를 호출합니다.하지만 그것은 완벽하게 작동합니다. 그러나 주된 방법은 계속 실행되고 있습니다. 처음에는 스프링 컨텍스트에서 폴러를 남겨 놓을 수는 있었지만, 그렇지 않습니다. 여기 내 코드입니다 : 여기내 기본 방법이 계속 실행되는 이유는 무엇입니까?

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); 

    } 
} 

내 스프링 컨텍스트는 다음과 같습니다

<?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> 

왜 내 주요 방법은이 메시지를 보낸 후에도 실행에 계속하지? 미리 감사드립니다.

답변

1

끝내야한다는 말 때문에 계속 될 것입니다.

당신은 사용할 수 있습니다

System.exit(0);

또는 작업을 할 것 main(String[] args)

+0

의 끝에

return;

. 나는 무한 루프가 없다면 주된 방법이 끝나지 않을 것이라고했다. – linker85

+1

사실, 문제는 RabbitMQ 클라이언트가 비 데몬 스레드를 실행한다는 것입니다. 응용 프로그램을 종료 할 준비가되면 연결 팩토리에서'destroy()'를 호출하는'ctx.destroy()'를 사용할 수 있습니다. 연결 스레드를 연결하고 중지하십시오. –

관련 문제