Spring集成和JMS:从外部客户端接收消息

Spring集成和JMS:从外部客户端接收消息,spring,spring-integration,spring-jms,Spring,Spring Integration,Spring Jms,在我们的系统中,外部客户机将消息放在JMS队列上。 我们的Spring集成应用程序需要从这些队列中提取消息并进行处理。 我对此的初步尝试是使用以下配置: <int:channel id="source_channel" /> <int-jms:inbound-channel-adapter id="source" channel="source_channel" destination-name="jms-queue-name" connection

在我们的系统中,外部客户机将消息放在JMS队列上。 我们的Spring集成应用程序需要从这些队列中提取消息并进行处理。 我对此的初步尝试是使用以下配置:

<int:channel id="source_channel" />

<int-jms:inbound-channel-adapter 
   id="source"
   channel="source_channel"
   destination-name="jms-queue-name"
   connection-factory="...">
   <int:poller fixed-rate="1000" />
</int-jms:inbound-channel-adapter>

<int:service-activator input-channel="source_channel" ref="sourceMessageReciever"/>

我希望当客户端将消息放入“jms队列名称”队列时,service activator bean能够处理该消息,但这并没有发生。这是正确的方法,还是我需要使用messageGateway来实现这一点? 谢谢

Rose

和之间的区别在于适配器是单向工作的,而不是双向工作的


我真的不知道什么地方可能出错,但您是否测试了您的JMS连接工厂配置是否按预期工作?

您的service activator类中该方法的签名是什么?检查它们是否有一个(并且只有一个)公共方法,或者将method属性添加到服务激活器定义中


通常,您应该更喜欢消息驱动的通道适配器,而不是jms:inbout通道适配器。最后一个适配器使用轮询器检查新消息,而消息驱动的通道适配器使用Spring消息侦听器。

我通过以下配置实现了类似的要求:

<context:component-scan base-package="somePackage"/>

<int:channel id="jmsInChannel" />

<bean id="jmsInboundContainer"
      class="org.springframework.jms.listener.DefaultMessageListenerContainer"
      destroy-method="destroy">
    <property name="connectionFactory" ref="..." />
    <property name="destination" ref="jmsQueue" />
    <property name="sessionTransacted" value="true" />
</bean>

<int-jms:message-driven-channel-adapter channel="jmsInChannel"
    container="jmsInboundContainer" acknowledge="transacted" />

<int:service-activator input-channel="jmsInChannel" ref="myService" />

我的服务实现如下:

@Component
public class MyService {

    @ServiceActivator
    public void processMessage(
        @Headers Map<String, Object> headers,
        @Payload Message<String> paylaod) {

        ...
        ...
    }
}
@组件
公共类MyService{
@服务激活器
公共消息(
@标题映射标题,
@有效负载消息(paylaod){
...
...
}
}

我遇到了同样的问题,然后我尝试显式声明入站队列,并在入站通道适配器中使用它

成功了

<int:channel id="source_channel" />

<int-jms:inbound-channel-adapter 
   id="source"
   channel="source_channel"
   destination="inboundQueue"
   connection-factory="...">
   <int:poller fixed-rate="1000" />
</int-jms:inbound-channel-adapter>

<int:service-activator input-channel="source_channel" ref="sourceMessageReciever"/>

<bean id="inboundQueue" class="org.apache.activemq.command.ActiveMQQueue">
   <constructor-arg value="jms-queue-name"></constructor-arg>
</bean>


打开调试日志记录;一切都应该变得显而易见;如果您对日志中看到的内容有疑问,请修改您的问题。您知道在消息未到达时如何调用服务吗?这是我的要求,在消息未提交时作出反应。