2014-06-17 3 views
1

스프링 예제에 나와있는 것과 비슷한 브라우저를 설정하여 스톰프와 함께 웹 소켓을 사용하여 대화 형 웹 애플리케이션을 만드는 데 익숙한 사용자 중 일부가 익숙하다고 생각합니다. 그것은 여기에 있습니다 : 메시징을 통해 직접 클라이언트로 돌아가서 페이지에 "Hello"+ 이름을 출력하는 입력 대신, 낙타를 사용하여 대기열과 응용 프로그램을 라우팅하는 일련의 과정을 거쳐야합니다. . 내 대기열 시스템을 브라우저에 연결하는 방법을 잘 모르겠습니다.Spring, Camel, ActiveMQ, WebSockets

"testQSource"라는 대기열에서 현재 시작하는 내 낙타 컨텍스트입니다. Stomp를 사용하여 testQSource로 전송 된 클라이언트가 브라우저에 입력 메시지를 보내고 싶습니다. 그런 다음 계속 진행하십시오. 여기

<camelContext xmlns="http://camel.apache.org/schema/spring"> 
<route> 
    <from uri="jms:queue:testQSource"/> 
    <to uri="myBean"/> 
    <log message="Routing message from testQSource to testQDestination queue with data ${body}"/> 
    <to uri="jms:queue:testQDestination"/> 
    <to uri="finalBean"/> 
    <log message="message: ${body}"/> 
</route> 
</camelContext> 

<camel:camelContext id="camel-client"> 
    <camel:template id="camelTemplate" /> 
</camel:camelContext> 

<bean id="jms" class="org.apache.activemq.camel.component.ActiveMQComponent"> 
    <property name="brokerURL" value="tcp://localhost:61616" /> 
</bean> 

내 주요 클래스 :

public class TestCamelSpring { 

public static void main(String[] args) { 
    ApplicationContext context = new ClassPathXmlApplicationContext("camelspring.xml"); 
    ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class); 

    System.out.println("Message Sending started"); 
    camelTemplate.sendBody("jms:queue:testQSource", "Sample Message"); 
    System.out.println("Message sent"); 

} 

}

난 그냥 내 주요 기능에 SpringApplication.run 슬립과 camelContext를 편집 할 수 또는 거기에 내가해야 할 뭔가 더있다 ? 클라이언트 입력을 testQSource에 보내는 방법을 모르겠습니다.

나는 그것이 입이 다름을 안다. 그러나 나는 이것을 잠시 동안 고투하고 있고, 벽을 약간 쳤다. 모든 도움이 크게 감사하겠습니다!

답변

1

메시지 대기열에 메시지를 보내려는 Java 코드를 작성하지 않으려면 타이머를 사용하여 메시지 보내기를 트리거하여 클라이언트 낙타 컨텍스트를 설정 한 다음 Spring을 시작하면됩니다. 문맥.

<camel:camelContext id="camel-client"> 
    <camel:from uri="timer://foo?fixedRate=true&period=60000" /> 
    <camel:setBody> 
     <simple>Simple Message!</simple> 
    </camel:setBody> 
    <camel:to uri="jms:queue:testQSource" /> 
</camel:camelContext> 
+0

그러면 타이머가 6000 단위로 메시지를 받습니까? – Theo

+0

이 경로는 testQSource에게 60 초마다 메시지를 보냅니다. –

관련 문제