Citrus Simulator如何在不同队列中发送和接收Java对象

时间:2018-07-10 11:47:32

标签: spring-jms citrus-framework

我正在尝试设置模拟器。我想在一个队列“ citrus_1”中接收对象“ MORequest”。并将MOResponse发送到“ citrus_2”队列。 在配置类中,我编写了以下内容:

@配置 公共类SimulatorJmsConfig扩展了SimulatorJmsAdapter {

@Value("${tqa.jms.morquest.endpoint}")
private String morequestDestinationName;

@Value("${tqa.jms.broker.uri}")
private String glassfishJmsBrokerUri;

@Bean(name = "tqa.jms.broker.uri")
public QueueConnectionFactory connectionFactory() {
    QueueConnectionFactory connectionFactory = new QueueConnectionFactory();
    try {
        connectionFactory.setProperty(ConnectionConfiguration.imqAddressList,
                glassfishJmsBrokerUri);
    } catch (JMSException e) {
        e.printStackTrace();
    }
    return connectionFactory;
}
@Bean
public JmsEndpoint jmsOutboundEndpoint() {
    return CitrusEndpoints.jms()
            .synchronous()
            .connectionFactory(connectionFactory())
            .destination("citrus_2")
            .build();
}}

在“ application.properties”中,我注册了模拟器监听的队列:

citrus.simulator.jms.inboundDestination = citrus_1
citrus.simulator.jms.enabled=true

我的默认方案类别:

enter code here@Scenario("JMS_SEND")public class DefaultScenario extends AbstractSimulatorScenario {@Autowired JmsEndpointjmsOutboundEndpoint;@Override public void run(ScenarioDesigner scenario){scenario.receive();scenario.send(jmsOutboundEndpoint).payload("TestMessage");}}

在日志中,我看到轮到我了:

2018-07-10 12:08:38.455 DEBUG 728 --- [cTaskExecutor-1] javax.jms.session                        : Session created: ConnectionID=8889371755234545920, SessionID=88893717552346042882018-07-10 12:08:38.456 DEBUG 728 --- [cTaskExecutor-1] o.springframework.jms.core.JmsTemplate   : Executing callback on JMS Session: ConnectionID=8889371755234545920, SessionID=88893717552346042882018-07-10 12:08:38.464 DEBUG 728 --- [cTaskExecutor-1] javax.jms.session:Message consumer created: ConnectionID=8889371755234545920, SessionID=8889371755234604288, ConsumerID=8889371755234606592, DestName=citrus_1

所以...当我在日志中将我的对象发送到队列“ citrus_1”中时,我看到了一些例外:

2018-07-10 14:13:05.060 DEBUG 15928 --- [enario:JMS_SEND] o.hibernate.internal.util.EntityPrinter  : com.consol.citrus.simulator.model.ScenarioExecution{executionId=1, endDate=Tue Jul 10 14:13:05 MSK 2018, scenarioParameters=<uninitialized>, errorMessage=com.consol.citrus.exceptions.CitrusRuntimeException: Could not find proper message validator for message type 'XML', please define a capable message validator for this message type
at com.consol.citrus.validation.MessageValidatorRegistry.findMessageValidators(MessageValidatorRegistry.java:83)

2018-07-10 14:13:05.072 ERROR 15928 --- [enario:JMS_SEND] c.consol.citrus.report.LoggingReporter   : TEST FAILED ScenarioDesigner <com.consol.citrus.simulator.scenario> Nested exception is:com.consol.citrus.exceptions.CitrusRuntimeException: Could not find proper message validator for message type 'XML', please define a capable message validator for this message typeat com.consol.citrus.validation.MessageValidatorRegistry.findMessageValidators(MessageValidatorRegistry.java:83)~[citrus-core-2.7.3.jar:na

和主要实例:

2018-07-10 14:13:10.889 ERROR 15928 --- [cTaskExecutor-1] c.c.c.s.e.SimulatorEndpointPoller:Failed to process message: Failed to get correlationkeyfor'citrus_message_correlator_simulatorJmsInboundEndpoint:consumer'2018-07-10 14:13:10.889 DEBUG 15928 ---[cTaskExecutor-1]c.c.c.s.e.SimulatorEndpointPoller:Failed to get correlationkey for 'citrus_message_correlator_simulatorJmsInboundEndpoint:consumer'com.consol.cit

为什么会这样?如何发送对象?

1 个答案:

答案 0 :(得分:0)

这是因为您收到目标消息,而Citrus不知道如何为该消息有效负载自动选择验证机制。您没有提供任何预期的有效负载信息,并且Citrus无法自动猜测要使用的消息有效负载验证类型。

默认消息类型是XML。这就是Citrus尝试使用XML消息有效负载验证的原因,而对象有效负载却失败了。

我建议您在第一个scenario.receive()操作中使用validation matcher。这样,您将显式添加对接收到的对象有效负载的验证。或者,您可以将消息类型显式设置为plaintext,并使用预期的消息有效负载,例如@ignore@