【问题标题】:Setting mapped port of TestContainer in DynamicPropertySource在 DynamicPropertySource 中设置 TestContainer 的映射端口
【发布时间】:2022-01-25 00:15:57
【问题描述】:

假设:TestContainer 作为集成框架,Spring Boot 应用程序,ibm mq 作为代理我尝试测试它,无法使用默认设置连接,catch:

Caused by: com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE').
    at com.ibm.msg.client.wmq.common.internal.Reason.createException(Reason.java:203)
    ... 118 common frames omitted
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2538;AMQ9204: Connection to host 'localhost(1414)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2538;AMQ9204: Connection to host 'localhost/127.0.0.1:1414' rejected. [1=java.net.ConnectException[Connection refused (Connection refused)],3=localhost/127.0.0.1:1414,4=TCP,5=Socket.connect]],3=localhost(1414),4=,5=RemoteTCPConnection.bindAndConnectSocket]

容器声明:

@Container
static GenericContainer<?> mqContainer = new GenericContainer<>(DockerImageName.parse("ibmcom/mq"))
        .withEnv("LICENSE", "accept")
        .withEnv("MQ_QMGR_NAME", "QM1")
        .withEnv("MQ_USER_NAME","admin")
        .withCommand("--volume q1data:/mnt/mqm")
        .withExposedPorts(1414);```

yml 文件中队列的所有设置看起来都不相关,因为没有任何端口特定的东西:

ibm:
      mq:
        channel: DEV.APP.SVRCONN
        queue-manager: QM1
        user: admin
        password: passw0rd
        use-i-b-m-cipher-mappings: false
        user-authentication-m-q-c-s-p: false
        #ssl-cipher-spec: ECDHE_RSA_AES_128_CBC_SHA256
        ssl.enabled: false

我询问了 TC 框架支持者,他们建议在动态属性中为 spring 设置主机和端口,这似乎是合法的。我找不到要使用的正确设置的唯一问题。有什么建议吗?

【问题讨论】:

    标签: ibm-mq testcontainers


    【解决方案1】:

    从这里的教程:https://developer.ibm.com/tutorials/mq-jms-application-development-with-spring-boot/,这些可能是以下属性:

    ibm.mq.connName=localhost(1414)
    

    所以你的@DynamicPropertySource 可能是这样的:

    @DynamicPropertySource
    static void registerMqProperties(DynamicPropertyRegistry registry) {
      registry.add("ibm.mq.connName", 
                   () -> String.format("%s(%d)", 
                                       mqContainer.getHost(), 
                                       mqContainer.getFirstMappedPort()));
    }
    

    【讨论】:

      猜你喜欢
      • 2020-08-05
      • 1970-01-01
      • 2015-08-09
      • 1970-01-01
      • 2013-04-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多