JBoss 퓨즈-AMQ with Camel

이 장에서는 ActiveMQ가 Camel과 함께 작동하는 방법에 대한 기본 사항을 배웁니다.

ActiveMQ 구성 요소로 구성

코드에서 ActiveMQ 큐 또는 토픽을 사용하기 전에 ActiveMQComponent를 구성해야합니다. ActiveMQComponent의 최소 구성은 다음 프로그램과 같이 수행 할 수 있습니다.

<bean id = "activemq" class = "org.apache.activemq.camel.component.ActiveMQComponent">
   <property name = "brokerURL" value = "tcp://localhost:61616"/>
   <property name = "userName" value = "admin"/>
   <property name = "password" value = "admin"/>
</bean>
  • brokerURL − AMQ 브로커의 호스트 및 포트를 지정합니다.

  • username − AMQ 브로커 연결에 사용할 사용자 이름을 지정합니다.

  • password − AMQ 브로커에 연결하기위한 암호를 지정합니다.

대기열에 연결

이제 ActiveMQComponent를 구성 했으므로 CamelContext에서 엔드 포인트로 사용할 수 있습니다.

AMQ 끝점을 다음 형식으로 사용합니다.

Activemq:[queue|topic]:[queueName|topicName]

AMQ에 메시지 쓰기

<?xml version = "1.0" encoding="UTF-8"?>
<!-- Configures the Camel Context-->
<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://camel.apache.org/schema/spring
   http://camel.apache.org/schema/spring/camel-spring.xsd">

이 번들을 Fuse 컨테이너에 배포 한 후 AMQ에 게시 된 메시지를 볼 수 있어야합니다. D:/src/data.

Input

D : /src/data/input.txt

Test me

Output

AMQ에서 읽기

<?xml version = "1.0" encoding = "UTF-8"?>
<!-- Configures the Camel Context-->

<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "
   http://www.springframework.org/schema/beans
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://camel.apache.org/schema/spring
   http://camel.apache.org/schema/spring/camel-spring.xsd">
	
   <camelContext xmlns = "http://camel.apache.org/schema/spring">
      <!-- here is a sample which processes the input files
         (leaving them in place - see the 'noop' flag)
          then performs content based routing on the message using XPath -->
			 
      <route>
         <from uri = "activemq:queue:TestQ"/>
         <to uri = "file:///d:/src"/>
      </route>
   </camelContext>
	
   <bean id = "activemq" class = "org.apache.activemq.camel.component.ActiveMQComponent">
      <property name = "brokerURL" value = "tcp://localhost:61616"/>
      <property name = "userName" value = "admin"/>
      <property name = "password" value = "admin"/>
   </bean>
	
</beans>

Input

이 번들을 배포 한 후 D : / src에서 파일이 생성되고 메시지가 사용되는 것을 볼 수 있습니다. 또한 해당 대기열에 대한 소비자가 표시되어야합니다.

Output

D : / src

Test me

주제에 쓰기

<?xml version = "1.0" encoding = "UTF-8"?>
<!-- Configures the Camel Context-->
<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://camel.apache.org/schema/spring 
   http://camel.apache.org/schema/spring/camel-spring.xsd">
	
   <camelContext xmlns = "http://camel.apache.org/schema/spring">
      <!-- here is a sample which processes the input files
         (leaving them in place - see the 'noop' flag)
          then performs content based routing on the message using XPath -->
			 
      <route>
         <from uri = "file:///d:/src"/>
         <to uri = "activemq:topic:TestTopic” />
      </route>
   </camelContext>
	
   <bean id = "activemq" class = "org.apache.activemq.camel.component.ActiveMQComponent">
      <property name = "brokerURL" value = "tcp://localhost:61616"/>
      <property name = "userName" value = "admin"/>
      <property name = "password" value = "admin"/>
   </bean>
	
</beans>

주제에서 읽기

<?xml version = "1.0" encoding = "UTF-8"?>
<!-- Configures the Camel Context-->
<beans xmlns = "http://www.springframework.org/schema/beans"
   xmlns:xsi = "http://www.w3.org/2001/XMLSchema-instance"
   xsi:schemaLocation = "
   http://www.springframework.org/schema/beans 
   http://www.springframework.org/schema/beans/spring-beans.xsd
   http://camel.apache.org/schema/spring 
   http://camel.apache.org/schema/spring/camel-spring.xsd">
	
   <camelContext xmlns = "http://camel.apache.org/schema/spring">
      <!-- here is a sample which processes the input files
         (leaving them in place - see the 'noop' flag)
         then performs content based routing on the message using XPath -->
			
      <route>
         <from uri = "activemq:topic:TestTopic"/>
         <to uri = "file:///d:/src2"/>
      </route>
   </camelContext>
	
   <bean id = "activemq" class = "org.apache.activemq.camel.component.ActiveMQComponent">
      <property name = "brokerURL" value="tcp://localhost:61616"/>
      <property name = "userName" value = "admin"/>
      <property name = "password" value = "admin"/>
   </bean>
	
</beans>

Input

D : /src/file1.xml

<order>
   <data>
      <value>value1</value>
   </data>
</order>

<order>
   <data>
      <value>value2</value>
   </data>
</order>

<order>
   <data>
      <value>value3</value>
   </data>
</order>

Output

D : / src /

<order>
   <data>
      <value>value1</value>
   </data>
</order>

<order>
   <data>
      <value>value2</value>
   </data>
</order>

<order>
   <data>
      <value>value3</value>
   </data>
</order>