2015-05-03 42 views
1

我對JMS的知識非常薄弱,請耐心等待。發送郵件給QueueChannel

我想發送一個簡單的消息到隊列消息通道。

@Autowired 
private MessageChannel myChannel = null; 

@Test 
public void testRecieveMethod() { 
    Message m = ((QueueChannel)myChannel).receive(); 
    System.out.println("HELLO"); 
} 

程序掛起像它應該,但當我嘗試從另一個程序發送郵件,它似乎並沒有被越來越收到。

private MessageChannel channel = null; 

@Test 
public void testMessage() { 
    channel = super.ctx.getBean("myChannel", MessageChannel.class); 
    jackMessage message = new ameerMessage("Hello my name is jack"); 
    Message<ameerMessage> msg = MessageBuilder.withPayload(message).build(); 
    channel.send(msg, 10000); 
} 

這裏是我的applicationContext

<int:channel id="myChannel"> 
    <int:queue capacity="10"/> 
</int:channel> 

<jms:inbound-channel-adapter id="JmsAdapter" 
    connection-factory="connectionFactory" 
    destination="myQueue" 
    channel="myChannel"> 
    <int:poller fixed-rate = "1000"/> 
</jms:inbound-channel-adapter> 

<bean id="myQueue" 
    class="org.apache.activemq.command.ActiveMQQueue"> 
    <constructor-arg value="MYQUEUE"/> 
</bean> 

<bean name="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory"> 
    <property name="brokerURL"> 
     <value>tcp://localhost:61616</value> 
    </property> 
</bean> 

<bean id="myProcessor" 
    class="com.jack.springintegration.Processor"/> 
</beans> 

不知道,我爲什麼沒有被收到該消息。有人可以幫忙嗎?

回答

0

你說「另一個程序」。如果它真的是另一個程序,那麼他們是不同的myChannel s。

我想你想要做的是發送一條消息給JMS,所以第一個程序的myChannel將從JMS獲得消息。

您需要在第二個程序中使用出站通道適配器將消息發送到JMS隊列。

+0

我確實看過一本集成書,它在某處提到過。感謝澄清這一點。 – SoftwareDude