int:outbound-websocket-adapter发送MESSAGE帧。我期待一个SEND框架

时间:2017-10-24 12:37:55

标签: spring-integration

Bakground: 我想通过jms消息触发批处理作业,并通过websocket将反馈发送给客户端。

问题: 服务器从客户端收到MESSAGE帧,但我期待一个SEND帧。因此,该主题的订阅者(/ topic / export-status)  没有收到jobExection状态。

问题: 我该如何解决这个问题?我错过了什么

我有以下spring集成流程: jms msg - >消息驱动的dapter - > jsm到作业请求转换器 - >作业启动网关 - >出站websocket

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration" xmlns:jms="http://www.springframework.org/schema/jms" xmlns:int-jms="http://www.springframework.org/schema/integration/jms"
  xmlns:batch="http://www.springframework.org/schema/batch" xmlns:batch-int="http://www.springframework.org/schema/batch-integration" xmlns:int-websocket="http://www.springframework.org/schema/integration/websocket" xmlns:websocket="http://www.springframework.org/schema/websocket"
  xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/websocket http://www.springframework.org/schema/websocket/spring-websocket.xsd
        http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms.xsd
        http://www.springframework.org/schema/integration/websocket http://www.springframework.org/schema/integration/websocket/spring-integration-websocket.xsd
        http://www.springframework.org/schema/integration/jms http://www.springframework.org/schema/integration/jms/spring-integration-jms.xsd
        http://www.springframework.org/schema/batch-integration  http://www.springframework.org/schema/batch-integration/spring-batch-integration.xsd
        http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd">

  <int:channel id="jmsInChannel"></int:channel>
  <int:channel id="jmsOutChannel"></int:channel>
  <int:channel id="fileExportJobRequests"></int:channel>
  <int:channel id="fileExportJobChannel"></int:channel>
  <int:channel id="errorChannel"></int:channel>

  <int:publish-subscribe-channel id="wsStatusChannel" />

  <int-jms:message-driven-channel-adapter id="jmsIn" destination-name="inQueue" channel="jmsInChannel" error-channel="errorChannel" />


  <int:router input-channel="jmsInChannel" expression="payload.job">
    <int:mapping value="export" channel="fileExportJobChannel" />
  </int:router>

  <int:chain input-channel="fileExportJobChannel" output-channel="fileExportJobRequests">
    <int:header-enricher>
      <int:reply-channel ref="nullChannel" />
    </int:header-enricher>
    <int:transformer id="prepareExportJobLaunchRequest">
      <bean class="com.bodastage.jobs.fileexport.JmsMessageToExportJobRequest">
        <property name="job" ref="fileExportJob" />
      </bean>
    </int:transformer>
  </int:chain>

  <batch-int:job-launching-gateway request-channel="fileExportJobRequests" reply-channel="jmsOutChannel" />

  <int:object-to-string-transformer input-channel="jmsOutChannel" output-channel="wsStatusChannel" />

  <bean id="webSocketClient" class="org.springframework.web.socket.client.standard.StandardWebSocketClient" />

  <bean id="stompSubProtocolHandler" class="org.springframework.web.socket.messaging.StompSubProtocolHandler" />

  <int-websocket:client-container id="clientWebSocketContainer" client="websocketStompClient" uri="http://localhost:8080/websocket" auto-startup="true" />


  <int:chain input-channel="wsStatusChannel">
    <int:header-enricher default-overwrite="true">
      <int:header name="#{T(org.springframework.messaging.simp.SimpMessageHeaderAccessor).DESTINATION_HEADER}" value="/topic/export-status" />

    </int:header-enricher>

    <int-websocket:outbound-channel-adapter container="clientWebSocketContainer" id="outboundWeSocketAdapter" default-protocol-handler="stompSubProtocolHandler">
    </int-websocket:outbound-channel-adapter>
  </int:chain>

  <int:logging-channel-adapter id="logger" channel="wsStatusChannel" level="INFO" log-full-message="true" />
</beans>

客户日志:

 Consumer [ActiveMQMessageConsumer { value=ID:LAPTOP-I5BST4S0-52358-1508768644545-1:1:1:1, started=true }] of session [ActiveMQSession {id=ID:LAPTOP-I5BST4S0-52358-1508768644545-1:1:1,started=true} java.lang.Object@65b94f8e] did not receive a message
2017-10-23 17:35:03.176 DEBUG 14984 --- [sIn.container-1] o.s.j.l.DefaultMessageListenerContainer  : Received message of type [class org.apache.activemq.command.ActiveMQMapMessage] from consumer [ActiveMQMessageConsumer { value=ID:LAPTOP-I5BST4S0-52358-1508768644545-1:1:1:1, started=true }] of session [ActiveMQSession {id=ID:LAPTOP-I5BST4S0-52358-1508768644545-1:1:1,started=true} java.lang.Object@65b94f8e]
2017-10-23 17:35:03.177 DEBUG 14984 --- [sIn.container-1] .i.j.ChannelPublishingJmsMessageListener : converted JMS Message [ActiveMQMapMessage {commandId = 5, responseRequired = true, messageId = ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, originalDestination = null, originalTransactionId = null, producerId = ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1, destination = queue://inQueue, transactionId = null, expiration = 0, timestamp = 1508769303167, arrival = 0, brokerInTime = 1508769303167, brokerOutTime = 1508769303171, 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@1e1f33c9, marshalledProperties = null, dataStructure = null, redeliveryCounter = 0, size = 0, properties = null, readOnlyProperties = true, readOnlyBody = true, droppable = false, jmsXGroupFirstForConsumer = false} ActiveMQMapMessage{ theTable = {name=Missing externals, format=csv, pk=1, job=export, file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals} }] to integration Message payload [{file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals, name=Missing externals, format=csv, pk=1, job=export}]
2017-10-23 17:35:03.178 DEBUG 14984 --- [sIn.container-1] o.s.integration.channel.DirectChannel    : preSend on channel 'jmsInChannel', message: GenericMessage [payload={file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals, name=Missing externals, format=csv, pk=1, job=export}, headers={jms_redelivered=false, jms_destination=queue://inQueue, id=eb77658f-c22d-335f-14a2-23facb7aab13, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303177}]
2017-10-23 17:35:03.178 DEBUG 14984 --- [sIn.container-1] o.s.i.router.ExpressionEvaluatingRouter  : org.springframework.integration.config.RouterFactoryBean#0 received message: GenericMessage [payload={file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals, name=Missing externals, format=csv, pk=1, job=export}, headers={jms_redelivered=false, jms_destination=queue://inQueue, id=eb77658f-c22d-335f-14a2-23facb7aab13, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303177}]
2017-10-23 17:35:03.178 DEBUG 14984 --- [sIn.container-1] o.s.integration.channel.DirectChannel    : preSend on channel 'fileExportJobChannel', message: GenericMessage [payload={file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals, name=Missing externals, format=csv, pk=1, job=export}, headers={jms_redelivered=false, jms_destination=queue://inQueue, id=eb77658f-c22d-335f-14a2-23facb7aab13, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303177}]
2017-10-23 17:35:03.178 DEBUG 14984 --- [sIn.container-1] o.s.i.handler.MessageHandlerChain        : org.springframework.integration.handler.MessageHandlerChain#0 received message: GenericMessage [payload={file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals, name=Missing externals, format=csv, pk=1, job=export}, headers={jms_redelivered=false, jms_destination=queue://inQueue, id=eb77658f-c22d-335f-14a2-23facb7aab13, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303177}]
2017-10-23 17:35:03.179 DEBUG 14984 --- [sIn.container-1] o.s.i.t.MessageTransformingHandler       : org.springframework.integration.handler.MessageHandlerChain#0$child#0.handler received message: GenericMessage [payload={file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals, name=Missing externals, format=csv, pk=1, job=export}, headers={jms_redelivered=false, jms_destination=queue://inQueue, id=eb77658f-c22d-335f-14a2-23facb7aab13, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303177}]
2017-10-23 17:35:03.179 DEBUG 14984 --- [sIn.container-1] o.s.i.t.MessageTransformingHandler       : org.springframework.integration.handler.MessageHandlerChain#0$child.prepareExportJobLaunchRequest.handler received message: GenericMessage [payload={file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals, name=Missing externals, format=csv, pk=1, job=export}, headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=9e4ae8c9-2148-6aea-cb94-d38c573a8622, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303179}]
2017-10-23 17:35:03.184 DEBUG 14984 --- [sIn.container-1] o.s.integration.channel.DirectChannel    : preSend on channel 'fileExportJobRequests', message: GenericMessage [payload=JobLaunchRequest: fileExportJob, parameters={query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}, headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=4f07fb9a-ae56-942f-d9c8-f9a68a6fb57f, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303184}]
2017-10-23 17:35:03.217  INFO 14984 --- [sIn.container-1] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=fileExportJob]] launched with the following parameters: [{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}]
2017-10-23 17:35:03.260  INFO 14984 --- [sIn.container-1] o.s.batch.core.job.SimpleStepHandler     : Executing step: [step]
2017-10-23 17:35:03.365  INFO 14984 --- [sIn.container-1] o.s.b.c.l.support.SimpleJobLauncher      : Job: [SimpleJob: [name=fileExportJob]] completed with the following parameters: [{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}] and the following status: [COMPLETED]
2017-10-23 17:35:03.366 DEBUG 14984 --- [sIn.container-1] o.s.integration.channel.DirectChannel    : preSend on channel 'jmsOutChannel', message: GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=d60873a9-ca67-a0c9-4b72-0296c538a5f8, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303366}]
2017-10-23 17:35:03.367 DEBUG 14984 --- [sIn.container-1] o.s.i.t.MessageTransformingHandler       : org.springframework.integration.transformer.MessageTransformingHandler#0 received message: GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=d60873a9-ca67-a0c9-4b72-0296c538a5f8, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303366}]
2017-10-23 17:35:03.368 DEBUG 14984 --- [sIn.container-1] o.s.i.channel.PublishSubscribeChannel    : preSend on channel 'wsStatusChannel', message: GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=ebbc1358-f43f-329d-da30-14618eb47552, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303367}]
2017-10-23 17:35:03.368 DEBUG 14984 --- [sIn.container-1] o.s.i.handler.MessageHandlerChain        : org.springframework.integration.handler.MessageHandlerChain#1 received message: GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=ebbc1358-f43f-329d-da30-14618eb47552, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303367}]
2017-10-23 17:35:03.368 DEBUG 14984 --- [sIn.container-1] o.s.i.t.MessageTransformingHandler       : org.springframework.integration.handler.MessageHandlerChain#1$child#0.handler received message: GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=ebbc1358-f43f-329d-da30-14618eb47552, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303367}]
2017-10-23 17:35:03.368 DEBUG 14984 --- [sIn.container-1] .s.i.w.o.WebSocketOutboundMessageHandler : org.springframework.integration.handler.MessageHandlerChain#1$child.outboundWeSocketAdapter.handler received message: GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=c54b632b-a412-fb05-293a-5509811817ba, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, simpDestination=/topic/export-status, timestamp=1508769303368}]
2017-10-23 17:35:03.369  WARN 14984 --- [sIn.container-1] o.s.w.s.m.StompSubProtocolHandler        : No STOMP "subscription" header in GenericMessage [payload=byte[410], headers={replyChannel=nullChannel, simpMessageType=MESSAGE, jms_redelivered=false, jms_destination=queue://inQueue, priority=4, jms_timestamp=1508769303167, contentType=text/plain;charset=UTF-8, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, simpDestination=/topic/export-status}]
2017-10-23 17:35:03.369 TRACE 14984 --- [sIn.container-1] o.s.w.s.s.c.WebSocketClientSockJsSession : Sending message TextMessage payload=[["MESSAGE\..], byteCount=543, last=true] in WebSocketClientSockJsSession[id='59aa39c1ac8340abbf0e1289f9ec2919, url=http://localhost:8080/websocket]
2017-10-23 17:35:03.369 TRACE 14984 --- [sIn.container-1] o.s.w.s.adapter.NativeWebSocketSession   : Sending TextMessage payload=[["MESSAGE\..], byteCount=543, last=true], JettyWebSocketSession[id=a3fcd9f, uri=ws://localhost:8080/websocket/107/59aa39c1ac8340abbf0e1289f9ec2919/websocket]
2017-10-23 17:35:03.370 DEBUG 14984 --- [sIn.container-1] o.s.integration.handler.LoggingHandler   : org.springframework.integration.handler.LoggingHandler#0 received message: GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=ebbc1358-f43f-329d-da30-14618eb47552, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303367}]
2017-10-23 17:35:03.371  INFO 14984 --- [sIn.container-1] o.s.integration.handler.LoggingHandler   : GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=ebbc1358-f43f-329d-da30-14618eb47552, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303367}]
2017-10-23 17:35:03.371 DEBUG 14984 --- [sIn.container-1] o.s.i.channel.PublishSubscribeChannel    : postSend (sent=true) on channel 'wsStatusChannel', message: GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=ebbc1358-f43f-329d-da30-14618eb47552, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303367}]
2017-10-23 17:35:03.371 DEBUG 14984 --- [sIn.container-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'jmsOutChannel', message: GenericMessage [payload=JobExecution: id=393, version=2, startTime=Mon Oct 23 17:35:03 EAT 2017, endTime=Mon Oct 23 17:35:03 EAT 2017, lastUpdated=Mon Oct 23 17:35:03 EAT 2017, status=COMPLETED, exitStatus=exitCode=COMPLETED;exitDescription=, job=[JobInstance: id=370, version=0, Job=[fileExportJob]], jobParameters=[{query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}], headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=d60873a9-ca67-a0c9-4b72-0296c538a5f8, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303366}]
2017-10-23 17:35:03.372 DEBUG 14984 --- [sIn.container-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'fileExportJobRequests', message: GenericMessage [payload=JobLaunchRequest: fileExportJob, parameters={query=SELECT * FROM networkaudit.rule_missing_externals, format=csv, fileName=missing_externals_20171023053503.csv}, headers={replyChannel=nullChannel, jms_redelivered=false, jms_destination=queue://inQueue, id=4f07fb9a-ae56-942f-d9c8-f9a68a6fb57f, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303184}]
2017-10-23 17:35:03.372 DEBUG 14984 --- [sIn.container-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'fileExportJobChannel', message: GenericMessage [payload={file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals, name=Missing externals, format=csv, pk=1, job=export}, headers={jms_redelivered=false, jms_destination=queue://inQueue, id=eb77658f-c22d-335f-14a2-23facb7aab13, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303177}]
2017-10-23 17:35:03.372 DEBUG 14984 --- [sIn.container-1] o.s.integration.channel.DirectChannel    : postSend (sent=true) on channel 'jmsInChannel', message: GenericMessage [payload={file_name=missing_externals_20171023053503.csv, query=SELECT * FROM networkaudit.rule_missing_externals, name=Missing externals, format=csv, pk=1, job=export}, headers={jms_redelivered=false, jms_destination=queue://inQueue, id=eb77658f-c22d-335f-14a2-23facb7aab13, priority=4, jms_timestamp=1508769303167, jms_messageId=ID:LAPTOP-I5BST4S0-61078-1508580196140-1:55:1:1:1, timestamp=1508769303177}]
2017-10-23 17:35:04.379 TRACE 14984 --- [sIn.container-1] o.s.j.l.DefaultMessageListenerContainer  : Consumer [ActiveMQMessageConsumer { value=ID:LAPTOP-I5BST4S0-52358-1508768644545-1:1:1:1, started=true }] of session [ActiveMQSession {id=ID:LAPTOP-I5BST4S0-52358-1508768644545-1:1:1,started=true} java.lang.Object@65b94f8e] did not receive a message
2017-10-23 17:35:05.379 TRACE 14984 --- [sIn.container-1] o.s.j.l.DefaultMessageListenerContainer  : Consumer [ActiveMQMessageConsumer { value=ID:LAPTOP-I5BST4S0-52358-1508768644545-1:1:1:1, started=true }] of session [ActiveMQSession {id=ID:LAPTOP-I5BST4S0-52358-1508768644545-1:1:1,started=true} java.lang.Object@65b94f8e] did not receive a message
2017-10-23 17:35:06.380 TRACE 14984 --- [sIn.container-1] 
o.s.j.l.DefaultMessageListenerContainer  : Consumer [ActiveMQMessageConsumer 

服务器日志:

2017-10-24 15:36:33.380 TRACE 22164 --- [nio-8080-exec-7] s.w.s.h.LoggingWebSocketHandlerDecorator : Handling TextMessage payload=[MESSAGE
de..], byteCount=528, last=true] in WebSocketServerSockJsSession[id=9468834bc830423ba2fe048b041e3186]
2017-10-24 15:36:33.381 TRACE 22164 --- [nio-8080-exec-7] o.s.w.s.m.StompSubProtocolHandler        : From client: MESSAGE {destination=[/topic/export-status], content-type=[text/plain;charset=UTF-8], message-id=[null-3], content-length=[410]} session=9468834bc830423ba2fe048b041e3186 text/plain;charset=UTF-8 payload=JobExecution: id=397, version=2, startTime=Tue Oct 24 15:36:33 EAT 2017, endTime...(truncated)
2017-10-24 15:36:37.177 DEBUG 22164 --- [nio-8080-exec-8] o.s.b.w.f.OrderedRequestContextFilter    : Cleared thread-bound request context: org.apache.catalina.connector.RequestFacade@afc9416
2017-10-24 15:36:46.755 TRACE 22164 --- [MessageBroker-7] s.w.s.s.t.s.WebSocketServerSockJsSession : Preparing to write SockJsFrame content='h'
2017-10-24 15:36:46.755 TRACE 22164 --- [MessageBroker-7] s.w.s.s.t.s.WebSocketServerSockJsSession : Writing SockJsFrame content='h'
2017-10-24 15:36:46.755 TRACE 22164 --- [MessageBroker-7] o.s.w.s.adapter.NativeWebSocketSession   : Sending TextMessage payload=[h], byteCount=1, last=true], StandardWebSocketSession[id=0, uri=/websocket/125/9468834bc830423ba2fe048b041e3186/websocket]
2017-10-24 15:36:46.755 TRACE 22164 --- [MessageBroker-7] s.w.s.s.t.s.WebSocketServerSockJsSession : Cancelling heartbeat in session 9468834bc830423ba2fe048b041e3186
2017-10-24 15:36:46.755 TRACE 22164 --- [MessageBroker-7] s.w.s.s.t.s.WebSocketServerSockJsSession : Scheduled heartbeat in session 9468834bc830423ba2fe048b041e3186

更新 添加拦截器:

public class WebSocketConfiguration  implements WebSocketMessageBrokerConfigurer 
...
    @Override
    public void configureClientInboundChannel(ChannelRegistration registration) {
        registration.taskExecutor().corePoolSize(Runtime.getRuntime().availableProcessors()*4);

        registration.setInterceptors(new ChannelInterceptorAdapter() {
            @Override
            public Message<?> preSend(Message<?> message, MessageChannel channel) {
                if (StompCommand.MESSAGE.equals(message.getHeaders().get("stompCommand"))) {
                    return MessageBuilder.fromMessage(message)
                            .setHeader("stompCommand", StompCommand.SEND)
                            .build();
                }
                else {
                    return message;
                }
            }
         });

    }
...

添加频道拦截器后的服务器日志:

org.springframework.messaging.MessageDeliveryException: Failed to handle GenericMessage [payload=byte[410], headers={simpMessageType=MESSAGE, stompCommand=SEND, id=a9089aac-6c81-1672-cb84-b9a37fdafae9, timestamp=1509003161562}] to org.springframework.messaging.support.ExecutorSubscribableChannel$SendTask@702abfd5 in StompBrokerRelay[0.0.0.0:61613]; nested exception is java.lang.IllegalStateException: No header accessor (not using the SimpMessagingTemplate?): GenericMessage [payload=byte[410], headers={simpMessageType=MESSAGE, stompCommand=SEND, id=a9089aac-6c81-1672-cb84-b9a37fdafae9, timestamp=1509003161562}], failedMessage=GenericMessage [payload=byte[410], headers={simpMessageType=MESSAGE, stompCommand=SEND, id=a9089aac-6c81-1672-cb84-b9a37fdafae9, timestamp=1509003161562}]
    at org.springframework.messaging.support.ExecutorSubscribableChannel$SendTask.run(ExecutorSubscribableChannel.java:144)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)
Caused by: java.lang.IllegalStateException: No header accessor (not using the SimpMessagingTemplate?): GenericMessage [payload=byte[410], headers={simpMessageType=MESSAGE, stompCommand=SEND, id=a9089aac-6c81-1672-cb84-b9a37fdafae9, timestamp=1509003161562}]
    at org.springframework.messaging.simp.stomp.StompBrokerRelayMessageHandler.handleMessageInternal(StompBrokerRelayMessageHandler.java:458)
    at org.springframework.messaging.simp.broker.AbstractBrokerMessageHandler.handleMessage(AbstractBrokerMessageHandler.java:238)
    at org.springframework.messaging.support.ExecutorSubscribableChannel$SendTask.run(ExecutorSubscribableChannel.java:135)
... 3 more
2017-10-26 10:32:41.654 DEBUG 27356 --- [io-8080-exec-10] s.w.s.h.LoggingWebSocketHandlerDecorator : WebSocketServerSockJsSession[id=e12efba449c2414eba4c3396888d163a] closed with CloseStatus[code=4500, reason=null]

1 个答案:

答案 0 :(得分:1)

我假设您在服务器端使用StompBrokerRelayMessageHandler,这是STOMP协议的一部分,可以从那里正确发送SEND帧,从客户端正确中继。

不幸的是StompSubProtocolHandler仅针对服务器端而设计,它具有以下逻辑:

else if (stompAccessor.getCommand() == null || StompCommand.SEND.equals(stompAccessor.getCommand())) {
    stompAccessor.updateStompCommandAsServerMessage();
}

我现在正在考虑我们可以做什么作为一个开箱即用的解决方案,但同时我建议你ChannelInterceptor为:

 @Override
 public void configureClientInboundChannel(ChannelRegistration registration) {
        registration.interceptors(new ChannelInterceptorAdapter() {

            @Override
            public Message<?> preSend(Message<?> message, MessageChannel channel) {
                if (StompCommand.MESSAGE.equals(message.getHeaders().get("stompCommand"))) {
                    StompHeaderAccessor headers = StompHeaderAccessor.wrap(message);
                    headers.setLeaveMutable(true);
                    headers.removeHeader("stompCommand");
                    headers.updateStompCommandAsClientMessage();
                    return MessageBuilder.createMessage(message.getPayload(), headers.getMessageHeaders());
                }
                else {
                    return message;
                }
            }

        });
    }

这是对AbstractWebSocketMessageBrokerConfigurer方法的重写。