无法连接到citrus-simulator-jms中的JpenMQ队列

时间:2018-04-09 12:22:01

标签: simulator citrus-framework

为不同类型的队列扩展柑橘的文档也不错!  这是我尝试启动Simulator.class的代码片段:

@SpringBootApplication
public class Simulator extends SimulatorJmsAdapter {

    public static void main(String[] args) {
        SpringApplication.run(Simulator.class, args);
    }

    @Override
    public ConnectionFactory connectionFactory() {

        QueueConnectionFactory factory = new QueueConnectionFactory();
        try {
            factory.setProperty(ConnectionConfiguration.imqAddressList, "mq://192.168.116.21:7676");
        } catch (JMSException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        return new QueueConnectionFactory();
    }

    @Override
    public boolean synchronous(SimulatorJmsConfigurationProperties simulatorJmsConfiguration) {
        return true;
    }

}

这里是context.xml:

<?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:citrus="http://www.citrusframework.org/schema/config"
       xmlns:citrus-jms="http://www.citrusframework.org/schema/jms/config"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.citrusframework.org/schema/jms/config http://www.citrusframework.org/schema/jms/config/citrus-jms-config.xsd
       http://www.citrusframework.org/schema/config http://www.citrusframework.org/schema/config/citrus-config.xsd">

  <citrus:schema-repository id="schemaRepository">
    <citrus:locations>
      <citrus:location path="classpath:xsd/HelloService.xsd"/>
    </citrus:locations>
  </citrus:schema-repository>

  <!-- Test JMS client -->
  <citrus-jms:sync-endpoint id="simulatorEndpoint"
                            destination-name="Citrus.Simulator.Inbound"/>

  <bean id="connectionFactory" class="com.sun.messaging.QueueConnectionFactory.QueueConnectionFactory">
    <property name="ConnectionConfiguration" ref="ConnectionConfiguration" />
  </bean>
    <bean id="ConnectionConfiguration" class="com.sun.messaging.ConnectionConfiguration">
    <property name="imqAddressList" ref="mq://192.168.116.21:7676" />
  </bean>

</beans>

当我运行clean install时,spring-boot:run。我收到此错误:C4003: Error occurred on connection creation [localhost:7676].

有人可以帮助我,为什么会这样?我如何正确创建文件上下文我需要一些例子?

1 个答案:

答案 0 :(得分:0)

我在这里回答:在EndpointConfig课程中我添加了几个Beans:

@Bean
public QueueConnectionFactory connectionFactory() throws JMSException {

QueueConnectionFactory connectionFactory = new QueueConnectionFactory();
connectionFactory.setProperty(ConnectionConfiguration.imqAddressList, "mq://#####.stage.tema:7676");
return connectionFactory;

}

    @Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(QueueConnectionFactory connectionFactory,
    PlatformTransactionManager transactionManager) {

DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setTransactionManager(transactionManager);
factory.setSessionTransacted(true);
factory.setSessionAcknowledgeMode(Session.SESSION_TRANSACTED);
// factory.setErrorHandler(errorHandler);
return factory;
}
  @Bean
public JmsTemplate jmsTemplate(QueueConnectionFactory qcf) throws JMSException {
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(qcf);
return template;
}

在我的测试中,我发送了用pom注入的个人物品。这里是代码:

@CitrusTest
@Test
public void send() {

        action(new AbstractTestAction() {
    @Override
    public void doExecute(TestContext context) {
    MORequest req = new MORequest(param1, param2, param3);
    //Method of object
    req.setSourcePort(4);

    jmsTemplate.send("queue_name", (Session sn) -> sn.createObjectMessage(req));

    }

});
}