java - 如何在 Spring Integration 中将服务分配给消息驱动适配器?

标签 java asynchronous spring-integration

在 receiveChannel 中收到消息后,我想调用一个服务来完成一些额外的工作。 消息流将是:

JMS Message -> receiveChannel -- message-driven-adapter --> jmsInChannel -> queueChannel (here the service should be invoked)

我想通过 1) 在队列 channel 2) 上调用的服务或消息适配器来实现此目的。

在后一种情况下,我不知道如何在 Spring Integration 中将服务分配给消息驱动适配器?而且服务也没有被调用。

此配置包含两种方法,但它们都不起作用:

<int-jms:channel id="receiveChannel" 
    queue-name="FORWARD"
    connection-factory="connectionFactory" 
    auto-startup="true">
</int-jms:channel>

<si:channel id="jmsInChannel"/>
<int-jms:message-driven-channel-adapter id="messageDrivenAdapter"
    channel="receiveChannel" destination-name="jmsInChannel"/>
<si:bridge input-channel="jmsInChannel" output-channel="queueChannel"/> 

<si:channel id="queueChannel">
    <si:queue/>
</si:channel>


 <si:service-activator id ="activator" ref="messageService" 
    method="processMessage" 
    input-channel="queueChannel">
</si:service-activator>

这是我的发送者,它将消息发送到 FORWARD 队列:

 <si:channel id="sendChannel"/>
<int-jms:outbound-channel-adapter 
connection-factory="connectionFactory" 
destination-name="FORWARD" 
channel="sendChannel"/>

<si:gateway id="forwardGateway" 
    service-interface="com.ucware.ucpo.forward.jms.MessageGateway" 
    default-request-channel="sendChannel"/>

消息来自 ActiveMQ 后端的 FORWARD 队列。

更新:我添加了一个监听器,现在已收到消息。这是打开 TRACE 的日志文件:

18.07.2013 15:52:16.036 [DirectChannel] [AbstractMessageChannel.java] [DEBUG] [main]
postSend (sent=true) on channel 'inputChannel', message: [Payload={FORWARD_ALL=3000, LINE=601}    
[Headers={timestamp=1374155536031, id=c2895e24-2260-4af8-9b23-a226ae95c31f,   
source=PRESENCE_ENGINE,userid=alice@tkb.local, type=FORWARD}]

18.07.2013 15:52:16.036 [ActiveMQMessageConsumer] [ActiveMQMessageConsumer.java] [TRACE] [org.springframework.jms.listener.DefaultMessageListenerContainer#1-1] ID:Lmiroslaw-PC-59127-1374155535776-1:1:1:1 **received message: MessageDispatch** {commandId = 0, responseRequired = false, consumerId = ID:Lmiroslaw-PC-59127-1374155535776-1:1:1:1, destination = queue://FORWARD, message = ActiveMQObjectMessage {commandId = 11, responseRequired = true, messageId = ID:Lmiroslaw-PC-59127-1374155535776-1:1:3:1:3, originalDestination = null, originalTransactionId = null, producerId = ID:Lmiroslaw-PC-59127-1374155535776-1:1:3:1, destination = queue://FORWARD, transactionId = null, expiration = 0, timestamp = 1374155536032, arrival = 0, brokerInTime = 1374155536013, brokerOutTime = 1374155536013, correlationId = null, replyTo = null, persistent = true, type = null, priority = 4, groupID = null, groupSequence = 0, targetConsumerId = null, compressed = false, userID = null, content = org.apache.activemq.util.ByteSequence@1bc4ec8, marshalledProperties = org.apache.activemq.util.ByteSequence@1d840d9, dataStructure = null, redeliveryCounter = 0, size = 0, properties = {timestamp=1374155536031, userid=alice@tkb.local, source=PRESENCE_ENGINE, type=FORWARD}, readOnlyProperties = true, readOnlyBody = true, droppable = false}, redeliveryCounter = 0}

18.07.2013 15:52:16.037 [DefaultMessageListenerContainer] [AbstractPollingMessageListenerContainer.java] [DEBUG] [org.springframework.jms.listener.DefaultMessageListenerContainer#1-1] **Received message of** type [class org.apache.activemq.command.ActiveMQObjectMessage] from consumer [Cached JMS MessageConsumer: ActiveMQMessageConsumer { value=ID:Lmiroslaw-PC-59127-1374155535776-1:1:1:1, started=true }] of session [Cached JMS Session: ActiveMQSession {id=ID:Lmiroslaw-PC-59127-1374155535776-1:1:1,started=true}]

最佳答案

<int-jms:channel/>不用于启动流程 - 它用于在流程中提供消息持久性。

您不需要前两个元素;只需使用 destination-name="FORWARD" 配置消息驱动适配器即可并且它将接收来自该队列的消息。

此外,删除 queueChannel ;不需要;该服务将在监听器线程上调用。

message-driven-adapter->jmsInChannel->service-activator

关于java - 如何在 Spring Integration 中将服务分配给消息驱动适配器?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17700625/

相关文章:

java - 在 mac 终端上运行 jar 文件 - FlowDroid

java - 什么是ActionMapping、RenderMapping?

java - 将 Java Swing 动画作为视频进行流式传输

javascript - 替代异步/等待

java - Spring集成在运行时添加路由

spring-integration - Spring 集成 - 屏障

java - 如何在 GWT 中使用非静态方法@Using window.addEventListener ('message' ~

c# - 使用任务进行异步编程

ios - 如何在ios中异步下载图片?

python - 使用 Python 编写 Spring 集成脚本